[AAI] Release docker artifact 1.12.4
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / 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
21 package org.onap.aai.schemagen;
22
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertThat;
26
27 import java.io.BufferedWriter;
28 import java.io.FileWriter;
29
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.onap.aai.edges.EdgeIngestor;
35 import org.onap.aai.nodes.NodeIngestor;
36 import org.onap.aai.schemagen.genxsd.HTMLfromOXM;
37 import org.onap.aai.schemagen.genxsd.HTMLfromOXMTest;
38 import org.onap.aai.schemagen.genxsd.XSDElementTest;
39 import org.onap.aai.schemagen.genxsd.YAMLfromOXM;
40 import org.onap.aai.schemagen.genxsd.YAMLfromOXMTest;
41 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
42 import org.onap.aai.setup.SchemaConfigVersions;
43 import org.onap.aai.setup.SchemaLocationsBean;
44 import org.onap.aai.setup.SchemaVersion;
45 import org.slf4j.Logger;
46 import org.slf4j.LoggerFactory;
47 import org.springframework.beans.factory.annotation.Autowired;
48 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
49 import org.springframework.test.context.ContextConfiguration;
50 import org.springframework.test.context.TestPropertySource;
51 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
52
53 @RunWith(SpringJUnit4ClassRunner.class)
54 @ContextConfiguration(
55     classes = {SchemaLocationsBean.class, TestUtilConfigTranslatorforBusiness.class,
56         EdgeIngestor.class, NodeIngestor.class, SwaggerGenerationConfiguration.class,
57         SchemaConfigVersions.class})
58 @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"})
59 public class GenerateXsdTest {
60     private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
61     private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
62     private static final String EDGEFILENAME =
63         "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
64     public static AnnotationConfigApplicationContext ctx = null;
65     private static String testXML;
66
67     @Autowired
68     YAMLfromOXM yamlFromOxm;
69
70     @Autowired
71     HTMLfromOXM htmlFromOxm;
72
73     @Autowired
74     SchemaConfigVersions schemaConfigVersions;
75
76     @BeforeClass
77     public static void setUpBeforeClass() throws Exception {
78         XSDElementTest x = new XSDElementTest();
79         x.setUp();
80         testXML = x.getTestXML();
81         logger.debug(testXML);
82         BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
83         bw.write(testXML);
84         bw.close();
85         BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
86         bw1.write(YAMLfromOXMTest.EdgeDefs());
87         bw1.close();
88
89     }
90
91     @Before
92     public void setUp() throws Exception {
93         // PowerMockito.mockStatic(GenerateXsd.class);
94         XSDElementTest x = new XSDElementTest();
95         x.setUp();
96         testXML = x.getTestXML();
97         // logger.info(testXML);
98     }
99
100     @Test
101     public void test_generateSwaggerFromOxmFile() {
102
103         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
104         String apiVersion = v.toString();
105         String fileContent = null;
106         try {
107
108             yamlFromOxm.setXmlVersion(testXML, v);
109             fileContent = yamlFromOxm.process();
110         } catch (Exception e) {
111             e.printStackTrace();
112         }
113         assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
114     }
115
116     @Test
117     public void test_generateXSDFromOxmFile() {
118
119         SchemaVersion v = schemaConfigVersions.getAppRootVersion();
120         String fileContent = null;
121         try {
122             htmlFromOxm.setXmlVersion(testXML, v);
123             fileContent = htmlFromOxm.process();
124         } catch (Exception e) {
125             e.printStackTrace();
126         }
127         // logger.debug(fileContent);
128         assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
129     }
130
131     @Test
132     public void testGetAPIVersion() {
133         GenerateXsd.apiVersion = schemaConfigVersions.getAppRootVersion().toString();
134         assertThat(GenerateXsd.getAPIVersion(), is("v11"));
135     }
136
137     @Test
138     public void testGetYamlDir() {
139         assertThat(GenerateXsd.getYamlDir(),
140             is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
141     }
142
143     @Test
144     public void testGetResponsesUrl() {
145         assertNull(GenerateXsd.getResponsesUrl());
146     }
147 }