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.util;
22 import static org.hamcrest.CoreMatchers.is;
23 import static org.junit.Assert.*;
25 import java.io.BufferedWriter;
26 import java.io.FileWriter;
28 import org.junit.Before;
29 import org.junit.BeforeClass;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.onap.aai.config.ConfigConfiguration;
33 import org.onap.aai.config.SwaggerGenerationConfiguration;
34 import org.onap.aai.edges.EdgeIngestor;
35 import org.onap.aai.nodes.NodeIngestor;
36 import org.onap.aai.setup.SchemaLocationsBean;
37 import org.onap.aai.testutils.TestUtilConfigTranslatorforBusiness;
39 import org.onap.aai.AAISetup;
40 import org.onap.aai.setup.SchemaVersion;
41 import org.onap.aai.setup.SchemaVersions;
42 import org.onap.aai.util.genxsd.HTMLfromOXM;
43 import org.onap.aai.util.genxsd.HTMLfromOXMTest;
44 import org.onap.aai.util.genxsd.XSDElementTest;
45 import org.onap.aai.util.genxsd.YAMLfromOXM;
46 import org.onap.aai.util.genxsd.YAMLfromOXMTest;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49 import org.springframework.beans.factory.annotation.Autowired;
50 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
51 import org.springframework.test.context.ContextConfiguration;
52 import org.springframework.test.context.TestPropertySource;
53 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
55 @RunWith(SpringJUnit4ClassRunner.class)
56 @ContextConfiguration(classes = {
57 ConfigConfiguration.class,
58 TestUtilConfigTranslatorforBusiness.class,
61 SwaggerGenerationConfiguration.class
63 @TestPropertySource(properties = {
64 "schema.uri.base.path = /aai"
66 public class GenerateXsdTest {
67 private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
68 private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
69 private static final String EDGEFILENAME = "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
70 public static AnnotationConfigApplicationContext ctx = null;
71 private static String testXML;
74 YAMLfromOXM yamlFromOxm;
77 HTMLfromOXM htmlFromOxm;
80 SchemaVersions schemaVersions;
83 public static void setUpBeforeClass() throws Exception {
84 XSDElementTest x = new XSDElementTest();
86 testXML = x.getTestXML();
87 logger.debug(testXML);
88 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
91 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
92 bw1.write(YAMLfromOXMTest.EdgeDefs());
98 public void setUp() throws Exception {
99 //PowerMockito.mockStatic(GenerateXsd.class);
100 XSDElementTest x = new XSDElementTest();
102 testXML = x.getTestXML();
103 // logger.info(testXML);
107 public void test_generateSwaggerFromOxmFile( ) {
109 SchemaVersion v = schemaVersions.getAppRootVersion();
110 String apiVersion = v.toString();
111 String fileContent = null;
114 yamlFromOxm.setXmlVersion(testXML, v);
115 fileContent = yamlFromOxm.process();
116 } catch(Exception e) {
119 assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
123 public void test_generateXSDFromOxmFile( ) {
125 SchemaVersion v = schemaVersions.getAppRootVersion();
126 String fileContent = null;
128 htmlFromOxm.setXmlVersion(testXML, v);
129 fileContent = htmlFromOxm.process();
130 } catch(Exception e) {
133 // logger.debug(fileContent);
134 assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
138 public void testGetAPIVersion() {
139 GenerateXsd.apiVersion = schemaVersions.getAppRootVersion().toString();
140 assertThat(GenerateXsd.getAPIVersion(),is("v11"));
144 public void testGetYamlDir() {
145 assertThat(GenerateXsd.getYamlDir(),is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
149 public void testGetResponsesUrl() {
150 assertNull(GenerateXsd.getResponsesUrl());