/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ * 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. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= */ package org.onap.aai.schemagen.genxsd; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.aai.edges.EdgeIngestor; import org.onap.aai.nodes.NodeIngestor; import org.onap.aai.schemagen.SwaggerGenerationConfiguration; import org.onap.aai.schemagen.testutils.TestUtilConfigTranslatorforBusiness; import org.onap.aai.setup.SchemaConfigVersions; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; 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; import org.w3c.dom.Element; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration( classes = {SchemaConfigVersions.class, SchemaLocationsBean.class, TestUtilConfigTranslatorforBusiness.class, EdgeIngestor.class, NodeIngestor.class, SwaggerGenerationConfiguration.class }) @TestPropertySource(properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000"}) public class HTMLfromOXMTest { private static final Logger logger = LoggerFactory.getLogger("HTMLfromOXMTest.class"); private static final String OXMFILENAME = "src/test/resources/oxm/business_oxm_v11.xml"; public static AnnotationConfigApplicationContext ctx = null; private static String testXML; protected static final String SERVICE_NAME = "JUNIT"; @Autowired HTMLfromOXM htmlFromOxm; @Autowired SchemaConfigVersions schemaConfigVersions; @BeforeClass public static void setUpContext() throws Exception { } @BeforeClass public static void setupBundleconfig() throws Exception { System.setProperty("AJSC_HOME", "."); System.setProperty("BUNDLECONFIG_DIR", "src/test/resources/bundleconfig-local"); System.setProperty("aai.service.name", SERVICE_NAME); } @Before public void setUp() throws Exception { setUp(0); } public void setUp(int sbopt) throws Exception { XSDElementTest x = new XSDElementTest(); x.setUp(sbopt); testXML = x.testXML; logger.debug(testXML); BufferedWriter bw = new BufferedWriter(new FileWriter(OXMFILENAME)); bw.write(testXML); bw.close(); } @Test public void testGetDocumentHeader() { SchemaVersion v = schemaConfigVersions.getAppRootVersion(); String header = null; try { htmlFromOxm.setXmlVersion(testXML, v); htmlFromOxm.setSchemaConfigVersions(schemaConfigVersions); header = htmlFromOxm.getDocumentHeader(); } catch (Exception e) { e.printStackTrace(); } logger.debug("Header:"); logger.debug(header); assertThat(header, is(HTMLheader())); } @Test public void testProcess() { SchemaVersion v = schemaConfigVersions.getAppRootVersion(); String fileContent = null; try { htmlFromOxm.setXmlVersion(testXML, v); fileContent = htmlFromOxm.process(); } catch (Exception e) { e.printStackTrace(); } logger.debug("FileContent-I:"); logger.debug(fileContent); assertThat(fileContent, is(HTMLresult(0))); } @Test public void testProcessWithCombiningJavaTypes() { SchemaVersion v = schemaConfigVersions.getAppRootVersion(); String fileContent = null; try { setUp(1); htmlFromOxm.setXmlVersion(testXML, v); fileContent = htmlFromOxm.process(); } catch (Exception e) { e.printStackTrace(); } logger.debug("FileContent-I:"); logger.debug(fileContent); assertThat(fileContent, is(HTMLresult(1))); } @Test public void testHTMLfromOXMFileVersion() throws IOException { String outfileName = "testXML.xml"; File XMLfile = new File(outfileName); XMLfile.createNewFile(); BufferedWriter bw = null; Charset charset = Charset.forName("UTF-8"); Path path = Paths.get(outfileName); bw = Files.newBufferedWriter(path, charset); bw.write(testXML); bw.close(); SchemaVersion v = schemaConfigVersions.getAppRootVersion(); String fileContent = null; try { htmlFromOxm.setXmlVersion(testXML, v); fileContent = htmlFromOxm.process(); } catch (Exception e) { e.printStackTrace(); } XMLfile.delete(); logger.debug("FileContent-I:"); logger.debug(fileContent); assertThat(fileContent, is(HTMLresult(0))); } @Test public void testHTMLfromOXMStringVersion() { SchemaVersion v = schemaConfigVersions.getAppRootVersion(); String fileContent = null; try { htmlFromOxm.setXmlVersion(testXML, v); fileContent = htmlFromOxm.process(); } catch (Exception e) { e.printStackTrace(); } logger.debug("FileContent-II:"); logger.debug(fileContent); assertThat(fileContent, is(HTMLresult(0))); } @Test public void testProcessJavaTypeElement() { String target = "Element=java-type/Customer"; SchemaVersion v = schemaConfigVersions.getAppRootVersion(); Element customer = null; try { htmlFromOxm.setXmlVersion(testXML, v); htmlFromOxm.process(); customer = htmlFromOxm.getJavaTypeElementSwagger("Customer"); } catch (Exception e) { e.printStackTrace(); } logger.debug("Element:"); logger.debug("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name")); assertThat("Element=" + customer.getNodeName() + "/" + customer.getAttribute("name"), is(target)); } public String HTMLresult() { return HTMLresult(0); } public String HTMLresult(int sbopt) { StringBuilder sb = new StringBuilder(32368); sb.append(HTMLheader()); sb.append(HTMLdefs(sbopt)); return sb.toString(); } public String HTMLheader() { StringBuilder sb = new StringBuilder(1500); sb.append("" + OxmFileProcessor.LINE_SEPARATOR); sb.append( "" + OxmFileProcessor.DOUBLE_LINE_SEPARATOR); return sb.toString(); } public String HTMLdefs() { return HTMLdefs(0); } public String HTMLdefs(int sbopt) { StringBuilder sb = new StringBuilder(1500); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Object that group service instances.\",indexedProps=\"service-type\",dependentOn=\"customer\",container=\"service-subscriptions\",crossEntityReference=\"service-instance,service-type\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(isKey=true,description=\"Value defined by orchestration to identify this service.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"This property will be deleted from A&AI in the near future. Only stop gap solution.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Collection of objects that group service instances.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); if (sbopt == 0) { sb.append( " @org.onap.aai.annotations.Metadata(description=\"customer identifiers to provide linkage back to BSS information.\",nameProps=\"subscriber-name\",indexedProps=\"subscriber-name,global-customer-id,subscriber-type\",searchable=\"global-customer-id,subscriber-name\",uniqueProps=\"global-customer-id\",container=\"customers\",namespace=\"business\")" + OxmFileProcessor.LINE_SEPARATOR); } else { sb.append( " @org.onap.aai.annotations.Metadata(description=\"customer identifiers to provide linkage back to BSS information.\",nameProps=\"subscriber-name\",indexedProps=\"subscriber-type,subscriber-name,global-customer-id\",searchable=\"global-customer-id,subscriber-name\",uniqueProps=\"global-customer-id\",container=\"customers\",namespace=\"business\")" + OxmFileProcessor.LINE_SEPARATOR); } sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(isKey=true,description=\"Global customer id used across to uniquely identify customer.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Subscriber name, an alternate way to retrieve a customer.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); if (sbopt == 0) { sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Subscriber type, a way to provide VID with only the INFRA customers.\",defaultValue=\"CUST\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); } else { sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Subscriber type, a way to provide VID with only the INFRA customers.\",defaultValue=\"CUST\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); } sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Collection of customer identifiers to provide linkage back to BSS information.\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append( " @org.onap.aai.annotations.Metadata(description=\"Namespace for business related constructs\")" + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append(" " + OxmFileProcessor.LINE_SEPARATOR); sb.append("" + OxmFileProcessor.LINE_SEPARATOR); return sb.toString(); } }