f8ede63243404f09bb3569ae01a2da23d2e7d620
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / GenerateXsdTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *    http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.aai.util;
21
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.*;
24
25 import java.io.File;
26
27 import org.hamcrest.CoreMatchers;
28 import org.junit.Before;
29 import org.junit.Test;
30
31 import org.onap.aai.introspection.Version;
32 import org.onap.aai.util.genxsd.HTMLfromOXM;
33 import org.onap.aai.util.genxsd.HTMLfromOXMTest;
34 import org.onap.aai.util.genxsd.XSDElementTest;
35 import org.onap.aai.util.genxsd.YAMLfromOXM;
36 import org.onap.aai.util.genxsd.YAMLfromOXMTest;
37 import org.slf4j.Logger;
38 import org.slf4j.LoggerFactory;
39
40
41 public class GenerateXsdTest {
42         private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
43         private String testXML;
44                 
45         @Before
46         public void setUp() throws Exception {
47                 //PowerMockito.mockStatic(GenerateXsd.class);
48                 XSDElementTest x = new XSDElementTest();
49                 x.setUp();
50                 testXML = x.getTestXML();
51         }
52         
53         @Test
54         public void test_generateSwaggerFromOxmFile( ) {
55                 Version v = Version.v11;
56                 String apiVersion = v.toString();
57                 String fileContent = null;
58                 File edgeRuleFile = new File("../aai-core" + "/src/main/resources/dbedgerules/DbEdgeRules_" + apiVersion + ".json");
59                 try {
60                         YAMLfromOXM swagger = new YAMLfromOXM(testXML, v, edgeRuleFile);
61                         fileContent = swagger.process();
62                 } catch(Exception e) {
63                         e.printStackTrace();
64                 }
65                 logger.debug(fileContent);
66                 assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
67         }
68                 
69         @Test
70         public void test_generateXSDFromOxmFile( ) {
71                 
72                 Version v = Version.v11;
73                 String fileContent = null;
74                 try {
75                         HTMLfromOXM xsd = new HTMLfromOXM(testXML, v);
76                         fileContent = xsd.process();
77                 } catch(Exception e) {
78                         e.printStackTrace();
79                 }
80                 logger.debug(fileContent);
81                 assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
82         }
83         
84         @Test
85         public void testGetAPIVersion() {
86                 GenerateXsd.apiVersion=Version.v11.name();
87                 assertThat(GenerateXsd.getAPIVersion(),is("v11"));
88         }
89
90         @Test
91         public void testGetYamlDir() {
92                 assertThat(GenerateXsd.getYamlDir(),is("../aai-schema/src/main/resources/aai_swagger_yaml"));
93         }
94
95         @Test
96         public void testGetResponsesUrl() {
97                 assertNull(GenerateXsd.getResponsesUrl());
98         }
99 }