Add plugin to check coverage
[aai/aai-common.git] / aai-core / src / test / java / org / onap / aai / util / GenerateXsdTest.java
index 9a36680..f8ede63 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 {
-
-    @Test
-    public void testGenerationOfXsdAndYaml() throws Exception {
-
-        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 static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.*;
 
-        generateXsd.main(new String[]{});
+import java.io.File;
 
-        System.setProperty("gen_version", Version.getLatest().toString());
-        System.setProperty("gen_type", "YAML");
+import org.hamcrest.CoreMatchers;
+import org.junit.Before;
+import org.junit.Test;
 
-        String wikiLink = System.getProperty("aai.wiki.link");
+import org.onap.aai.introspection.Version;
+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;
 
-        if(wikiLink == null){
-            wikiLink = "https://wiki.onap.org/";
-        }
 
-        System.setProperty("yamlresponses_url", wikiLink);
-        System.setProperty("yamlresponses_label", "Response codes found in [response codes]");
+public class GenerateXsdTest {
+       private static final Logger logger = LoggerFactory.getLogger("GenerateXsd.class");
+       private String testXML;
+               
+       @Before
+       public void setUp() throws Exception {
+               //PowerMockito.mockStatic(GenerateXsd.class);
+               XSDElementTest x = new XSDElementTest();
+               x.setUp();
+               testXML = x.getTestXML();
+       }
+       
+       @Test
+       public void test_generateSwaggerFromOxmFile( ) {
+               Version v = Version.v11;
+               String apiVersion = v.toString();
+               String fileContent = null;
+               File edgeRuleFile = new File("../aai-core" + "/src/main/resources/dbedgerules/DbEdgeRules_" + apiVersion + ".json");
+               try {
+                       YAMLfromOXM swagger = new YAMLfromOXM(testXML, v, edgeRuleFile);
+                       fileContent = swagger.process();
+               } catch(Exception e) {
+                       e.printStackTrace();
+               }
+               logger.debug(fileContent);
+               assertThat(fileContent, is(new YAMLfromOXMTest().YAMLresult()));
+       }
+               
+       @Test
+       public void test_generateXSDFromOxmFile( ) {
+               
+               Version v = Version.v11;
+               String fileContent = null;
+               try {
+                       HTMLfromOXM xsd = new HTMLfromOXM(testXML, v);
+                       fileContent = xsd.process();
+               } catch(Exception e) {
+                       e.printStackTrace();
+               }
+               logger.debug(fileContent);
+               assertThat(fileContent, is(new HTMLfromOXMTest().HTMLresult()));
+       }
+       
+       @Test
+       public void testGetAPIVersion() {
+               GenerateXsd.apiVersion=Version.v11.name();
+               assertThat(GenerateXsd.getAPIVersion(),is("v11"));
+       }
 
-        generateXsd.main(new String[]{});
-    }
+       @Test
+       public void testGetYamlDir() {
+               assertThat(GenerateXsd.getYamlDir(),is("../aai-schema/src/main/resources/aai_swagger_yaml"));
+       }
 
+       @Test
+       public void testGetResponsesUrl() {
+               assertNull(GenerateXsd.getResponsesUrl());
+       }
 }