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.*;
37 import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness;
38 import org.onap.aai.setup.SchemaLocationsBean;
39 import org.onap.aai.setup.SchemaVersion;
40 import org.onap.aai.setup.SchemaVersions;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.context.annotation.AnnotationConfigApplicationContext;
45 import org.springframework.test.context.ContextConfiguration;
46 import org.springframework.test.context.TestPropertySource;
47 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
49 @RunWith(SpringJUnit4ClassRunner.class)
50 @ContextConfiguration(
51 classes = {SchemaLocationsBean.class, TestUtilConfigTranslatorforBusiness.class,
52 EdgeIngestor.class, NodeIngestor.class, SwaggerGenerationConfiguration.class,
53 SchemaVersions.class})
54 @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"})
55 public class GenerateXsdTest {
56 private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
57 private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
58 private static final String EDGEFILENAME =
59 "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
60 public static AnnotationConfigApplicationContext ctx = null;
61 private static String testXML;
64 YAMLfromOXM yamlFromOxm;
67 HTMLfromOXM htmlFromOxm;
70 SchemaVersions schemaVersions;
73 public static void setUpBeforeClass() throws Exception {
74 XSDElementTest x = new XSDElementTest();
76 testXML = x.getTestXML();
77 logger.debug(testXML);
78 BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
81 BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
82 bw1.write(YAMLfromOXMTest.EdgeDefs());
88 public void setUp() throws Exception {
89 // PowerMockito.mockStatic(GenerateXsd.class);
90 XSDElementTest x = new XSDElementTest();
92 testXML = x.getTestXML();
93 // logger.info(testXML);
97 public void test_generateSwaggerFromOxmFile() {
99 SchemaVersion v = schemaVersions.getAppRootVersion();
100 String apiVersion = v.toString();
101 String fileContent = null;
104 yamlFromOxm.setXmlVersion(testXML, v);
105 fileContent = yamlFromOxm.process();
106 } catch (Exception e) {
109 assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
113 public void test_generateXSDFromOxmFile() {
115 SchemaVersion v = schemaVersions.getAppRootVersion();
116 String fileContent = null;
118 htmlFromOxm.setXmlVersion(testXML, v);
119 fileContent = htmlFromOxm.process();
120 } catch (Exception e) {
123 // logger.debug(fileContent);
124 assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
128 public void testGetAPIVersion() {
129 GenerateXsd.apiVersion = schemaVersions.getAppRootVersion().toString();
130 assertThat(GenerateXsd.getAPIVersion(), is("v11"));
134 public void testGetYamlDir() {
135 assertThat(GenerateXsd.getYamlDir(),
136 is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
140 public void testGetResponsesUrl() {
141 assertNull(GenerateXsd.getResponsesUrl());