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=========================================================
20 package org.onap.aai.schemagen;
22 import org.junit.Before;
23 import org.junit.BeforeClass;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.onap.aai.edges.EdgeIngestor;
27 import org.onap.aai.nodes.NodeIngestor;
28 import org.onap.aai.schemagen.genxsd.*;
29 import org.onap.aai.setup.SchemaLocationsBean;
30 import org.onap.aai.setup.SchemaVersion;
31 import org.onap.aai.setup.SchemaVersions;
32 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
37 import org.springframework.test.context.ContextConfiguration;
38 import org.springframework.test.context.TestPropertySource;
39 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
41 import java.io.BufferedWriter;
42 import java.io.FileWriter;
44 import static org.hamcrest.CoreMatchers.is;
45 import static org.junit.Assert.assertNull;
46 import static org.junit.Assert.assertThat;
48 @RunWith(SpringJUnit4ClassRunner.class)
49 @ContextConfiguration(classes = {
50 SchemaLocationsBean.class,
51 TestUtilConfigTranslatorforBusiness.class,
54 SwaggerGenerationConfiguration.class,
57 @TestPropertySource(properties = {
58 "schema.uri.base.path = /aai",
59 "schema.xsd.maxoccurs = 5000"
61 public class GenerateXsdTest {
62 private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
63 private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
64 private static final String EDGEFILENAME = "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
65 public static AnnotationConfigApplicationContext ctx = null;
66 private static String testXML;
69 YAMLfromOXM yamlFromOxm;
72 HTMLfromOXM htmlFromOxm;
75 SchemaVersions schemaVersions;
78 public static void setUpBeforeClass() throws Exception {
79 XSDElementTest x = new XSDElementTest();
81 testXML = x.getTestXML();
82 logger.debug(testXML);
83 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
86 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
87 bw1.write(YAMLfromOXMTest.EdgeDefs());
93 public void setUp() throws Exception {
94 //PowerMockito.mockStatic(GenerateXsd.class);
95 XSDElementTest x = new XSDElementTest();
97 testXML = x.getTestXML();
98 // logger.info(testXML);
102 public void test_generateSwaggerFromOxmFile( ) {
104 SchemaVersion v = schemaVersions.getAppRootVersion();
105 String apiVersion = v.toString();
106 String fileContent = null;
109 yamlFromOxm.setXmlVersion(testXML, v);
110 fileContent = yamlFromOxm.process();
111 } catch(Exception e) {
114 assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
118 public void test_generateXSDFromOxmFile( ) {
120 SchemaVersion v = schemaVersions.getAppRootVersion();
121 String fileContent = null;
123 htmlFromOxm.setXmlVersion(testXML, v);
124 fileContent = htmlFromOxm.process();
125 } catch(Exception e) {
128 // logger.debug(fileContent);
129 assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
133 public void testGetAPIVersion() {
134 GenerateXsd.apiVersion = schemaVersions.getAppRootVersion().toString();
135 assertThat(GenerateXsd.getAPIVersion(),is("v11"));
139 public void testGetYamlDir() {
140 assertThat(GenerateXsd.getYamlDir(),is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
144 public void testGetResponsesUrl() {
145 assertNull(GenerateXsd.getResponsesUrl());