X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fxml%2Fgenerator%2FTestAaiArtifactGenerator.java;fp=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestToscaParser.java;h=d95291be143a04792d7213dc1fd35e97739da1cf;hb=refs%2Fchanges%2F47%2F83247%2F1;hp=f300f7b595dfb50d93e1b450d972ec5045eaff5a;hpb=d2215b5d8b6c8976a9540a9e4706c7bebca80aa2;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java similarity index 67% rename from src/test/java/org/onap/aai/babel/parser/TestToscaParser.java rename to src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java index f300f7b..d95291b 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestToscaParser.java +++ b/src/test/java/org/onap/aai/babel/xml/generator/TestAaiArtifactGenerator.java @@ -19,7 +19,7 @@ * ============LICENSE_END========================================================= */ -package org.onap.aai.babel.parser; +package org.onap.aai.babel.xml.generator; import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; @@ -31,21 +31,29 @@ import java.util.Map; import org.junit.Before; import org.junit.Test; import org.onap.aai.babel.csar.extractor.InvalidArchiveException; +import org.onap.aai.babel.parser.ArtifactGeneratorToscaParser; import org.onap.aai.babel.testdata.CsarTest; import org.onap.aai.babel.util.ArtifactTestUtils; import org.onap.aai.babel.util.Resources; import org.onap.aai.babel.xml.generator.api.AaiArtifactGenerator; import org.onap.aai.babel.xml.generator.data.AdditionalParams; import org.onap.aai.babel.xml.generator.data.GenerationData; +import org.onap.aai.babel.xml.generator.model.WidgetType; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException; +import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory; /** * Direct tests of the {@link AaiArtifactGenerator} to improve code coverage. */ -public class TestToscaParser { +public class TestAaiArtifactGenerator { + + private ArtifactTestUtils testUtils; @Before public void setup() { - new ArtifactTestUtils().setGeneratorSystemProperties(); + testUtils = new ArtifactTestUtils(); + testUtils.setGeneratorSystemProperties(); } @Test @@ -65,9 +73,33 @@ public class TestToscaParser { assertThat("Number of resources generated", data.getResultData().size(), is(equalTo(2))); } + /** + * Test that an Exception is thrown when a Widget Type (such as ALLOTTED_RESOURCE) required by Babel is not present + * in the WidgetType dynamic enumeration. + * + * @throws SdcToscaParserException + * @throws IOException + * @throws XmlArtifactGenerationException + */ + @Test(expected = IllegalArgumentException.class) + public void testParserWithIncompleteMappings() + throws SdcToscaParserException, IOException, XmlArtifactGenerationException { + testUtils.loadWidgetMappings(); + testUtils.loadWidgetToUuidMappings(); + + AaiArtifactGenerator artifactGenerator = new AaiArtifactGenerator(); + WidgetType.clearElements(); // Remove all WidgetTypes so that the generator fails + + ISdcCsarHelper csarHelper = SdcToscaParserFactory.getInstance() + .getSdcCsarHelper(TestAaiArtifactGenerator.class.getClassLoader() + .getResource(ArtifactTestUtils.CSAR_INPUTS_FOLDER + CsarTest.VNF_VENDOR_CSAR.getName()) + .getFile().toString()); + artifactGenerator.generateAllArtifacts("1.0", csarHelper); + } + /** * Invoke the generator with a sample CSAR file. - * + * * @return the generated AAI Artifacts * @throws InvalidArchiveException * if the test CSAR file is invalid