2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.aai.schemagen;
23 import static org.hamcrest.CoreMatchers.is;
24 import static org.junit.Assert.assertNull;
25 import static org.junit.Assert.assertThat;
27 import java.io.BufferedWriter;
28 import java.io.FileWriter;
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;
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;
68 YAMLfromOXM yamlFromOxm;
71 HTMLfromOXM htmlFromOxm;
74 SchemaConfigVersions schemaConfigVersions;
77 public static void setUpBeforeClass() throws Exception {
78 XSDElementTest x = new XSDElementTest();
80 testXML = x.getTestXML();
81 logger.debug(testXML);
82 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
85 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
86 bw1.write(YAMLfromOXMTest.EdgeDefs());
92 public void setUp() throws Exception {
93 // PowerMockito.mockStatic(GenerateXsd.class);
94 XSDElementTest x = new XSDElementTest();
96 testXML = x.getTestXML();
97 // logger.info(testXML);
101 public void test_generateSwaggerFromOxmFile() {
103 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
104 String apiVersion = v.toString();
105 String fileContent = null;
108 yamlFromOxm.setXmlVersion(testXML, v);
109 fileContent = yamlFromOxm.process();
110 } catch (Exception e) {
113 assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
117 public void test_generateXSDFromOxmFile() {
119 SchemaVersion v = schemaConfigVersions.getAppRootVersion();
120 String fileContent = null;
122 htmlFromOxm.setXmlVersion(testXML, v);
123 fileContent = htmlFromOxm.process();
124 } catch (Exception e) {
127 // logger.debug(fileContent);
128 assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
132 public void testGetAPIVersion() {
133 GenerateXsd.apiVersion = schemaConfigVersions.getAppRootVersion().toString();
134 assertThat(GenerateXsd.getAPIVersion(), is("v11"));
138 public void testGetYamlDir() {
139 assertThat(GenerateXsd.getYamlDir(),
140 is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
144 public void testGetResponsesUrl() {
145 assertNull(GenerateXsd.getResponsesUrl());