Integrate aai-schema-ingest library into aai-core
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / GenerateXsdTest.java
index 9a36680..1cd226f 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * org.onap.aai
  * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  * ============LICENSE_END=========================================================
- *
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  */
 package org.onap.aai.util;
 
-import org.junit.Test;
-import org.onap.aai.introspection.Version;
-
-public class GenerateXsdTest {
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
 
-    @Test
-    public void testGenerationOfXsdAndYaml() throws Exception {
+import java.io.BufferedWriter;
+import java.io.FileWriter;
 
-        GenerateXsd generateXsd = new GenerateXsd();
-        System.setProperty("gen_version", Version.getLatest().toString());
-        System.setProperty("gen_type", "XSD");
-        System.setProperty("yamlresponses_url", "");
-        System.setProperty("yamlresponses_label", "");
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.aai.config.SwaggerGenerationConfiguration;
+import org.onap.aai.edges.EdgeIngestor;
+import org.onap.aai.nodes.NodeIngestor;
+import org.onap.aai.setup.SchemaLocationsBean;
+import org.onap.aai.testutils.TestUtilConfigTranslatorforBusiness;
 
-        generateXsd.main(new String[]{});
+import org.onap.aai.AAISetup;
+import org.onap.aai.setup.SchemaVersion;
+import org.onap.aai.setup.SchemaVersions;
+import org.onap.aai.util.genxsd.HTMLfromOXM;
+import org.onap.aai.util.genxsd.HTMLfromOXMTest;
+import org.onap.aai.util.genxsd.XSDElementTest;
+import org.onap.aai.util.genxsd.YAMLfromOXM;
+import org.onap.aai.util.genxsd.YAMLfromOXMTest;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.AnnotationConfigApplicationContext;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.TestPropertySource;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
 
-        System.setProperty("gen_version", Version.getLatest().toString());
-        System.setProperty("gen_type", "YAML");
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(classes = {
+        SchemaLocationsBean.class,
+        TestUtilConfigTranslatorforBusiness.class,
+        EdgeIngestor.class,
+        NodeIngestor.class,
+               SwaggerGenerationConfiguration.class,
+               SchemaVersions.class
+})
+@TestPropertySource(properties = {
+               "schema.uri.base.path = /aai"
+})
+public class GenerateXsdTest {
+       private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
+       private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml";
+       private static final String EDGEFILENAME = "src/test/resources/dbedgerules/DbEdgeBusinessRules_test.json";
+       public static AnnotationConfigApplicationContext ctx = null;
+       private static String testXML;
 
-        String wikiLink = System.getProperty("aai.wiki.link");
+       @Autowired
+       YAMLfromOXM yamlFromOxm;
+       
+       @Autowired
+       HTMLfromOXM htmlFromOxm;
+       
+       @Autowired
+       SchemaVersions schemaVersions;
+       
+       @BeforeClass
+       public static void setUpBeforeClass() throws Exception {
+               XSDElementTest x = new XSDElementTest();
+               x.setUp();
+               testXML = x.getTestXML();
+               logger.debug(testXML);
+               BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME));
+               bw.write(testXML);
+               bw.close();
+               BufferedWriter bw1 = new BufferedWriter(new FileWriter(EDGEFILENAME));
+               bw1.write(YAMLfromOXMTest.EdgeDefs());
+               bw1.close();
 
-        if(wikiLink == null){
-            wikiLink = "https://wiki.onap.org/";
-        }
+       }       
 
-        System.setProperty("yamlresponses_url", wikiLink);
-        System.setProperty("yamlresponses_label", "Response codes found in [response codes]");
+       @Before
+       public void setUp() throws Exception {
+               //PowerMockito.mockStatic(GenerateXsd.class);
+               XSDElementTest x = new XSDElementTest();
+               x.setUp();
+               testXML = x.getTestXML();
+//             logger.info(testXML);
+       }
+       
+       @Test
+       public void test_generateSwaggerFromOxmFile( ) {
+               
+               SchemaVersion v = schemaVersions.getAppRootVersion();
+               String apiVersion = v.toString();
+               String fileContent = null;
+               try {
+                       
+                       yamlFromOxm.setXmlVersion(testXML, v);
+                       fileContent = yamlFromOxm.process();
+               } catch(Exception e) {
+                       e.printStackTrace();
+               }
+               assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
+       }
+               
+       @Test
+       public void test_generateXSDFromOxmFile( ) {
+               
+               SchemaVersion v = schemaVersions.getAppRootVersion();
+               String fileContent = null;
+               try {
+                       htmlFromOxm.setXmlVersion(testXML, v);
+                       fileContent = htmlFromOxm.process();
+               } catch(Exception e) {
+                       e.printStackTrace();
+               }
+//             logger.debug(fileContent);
+               assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
+       }
+       
+       @Test
+       public void testGetAPIVersion() {
+               GenerateXsd.apiVersion = schemaVersions.getAppRootVersion().toString();
+               assertThat(GenerateXsd.getAPIVersion(),is("v11"));
+       }
 
-        generateXsd.main(new String[]{});
-    }
+       @Test
+       public void testGetYamlDir() {
+               assertThat(GenerateXsd.getYamlDir(),is("aai-schema/src/main/resources/onap/aai_swagger_yaml"));
+       }
 
+       @Test
+       public void testGetResponsesUrl() {
+               assertNull(GenerateXsd.getResponsesUrl());
+       }
 }
+