X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=acc4a352ec6a59d67e0d8fee38717551ca202ba7;hb=5a6fd49a6aca3a567464527335b107746e28f3bd;hp=a538373d2b03ac02e06de0bf82ebee802cde8e03;hpb=fc779f51a624bfddc68328bf3fd3c74594ef31f6;p=aai%2Fbabel.git diff --git a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java index a538373..acc4a35 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -25,12 +25,16 @@ import static org.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import org.junit.Test; import org.mockito.Mockito; +import org.onap.aai.babel.util.ArtifactTestUtils; +import org.onap.aai.babel.util.Resources; +import org.onap.aai.babel.xml.generator.XmlArtifactGenerationException; import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil; import org.onap.aai.babel.xml.generator.data.WidgetMapping; import org.onap.aai.babel.xml.generator.model.Resource; @@ -49,6 +53,53 @@ public class TestArtifactGeneratorToscaParser { private static final String TEST_UUID = "1234"; + /** + * Initialize the Generator with an invalid artifact generator properties file path. + * + * @throws IOException + * if an error occurs reading the configuration properties + */ + @Test(expected = IllegalArgumentException.class) + public void testMissingPropertiesFile() throws IOException { + System.setProperty(ArtifactGeneratorToscaParser.PROPERTY_ARTIFACT_GENERATOR_CONFIG_FILE, "non-existent.file"); + ArtifactGeneratorToscaParser.initWidgetConfiguration(); + } + + /** + * Initialize the Generator with an invalid mappings file path. + * + * @throws IOException + * if the file content could not be read successfully + */ + @Test(expected = IllegalArgumentException.class) + public void testMissingMappingsFile() throws IOException { + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration("non-existent.file"); + } + + /** + * Initialize the Generator with no Widget Mappings content. + * + * @throws IOException + * if the file content could not be read successfully + */ + @Test(expected = IOException.class) + public void testMissingMappingsContent() throws IOException { + String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG); + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson); + } + + /** + * Initialize the Generator with invalid Widget Mappings content. + * + * @throws IOException + * if the file content could not be read successfully + */ + @Test(expected = IOException.class) + public void testInvalidMappingsContent() throws IOException { + String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.INVALID_TOSCA_MAPPING_CONFIG); + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson); + } + /** * Process an Allotted Resource that does not have a Providing Service. */ @@ -71,30 +122,49 @@ public class TestArtifactGeneratorToscaParser { } /** - * Initialise the Artifact Generator Widget Mapping config with incomplete data. + * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type). + * + * @throws IOException */ - @Test(expected = IllegalArgumentException.class) - public void testToscaMappingWithoutType() { + @Test(expected = IOException.class) + public void testToscaMappingWithoutType() throws IOException { WidgetMapping invalidMapping = new WidgetMapping(); invalidMapping.setType(null); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } /** - * Initialise the Artifact Generator Widget Mapping config with incomplete data. + * Initialize the Artifact Generator Widget Mapping config with invalid data (type value). + * + * @throws IOException */ - @Test(expected = IllegalArgumentException.class) - public void testToscaMappingWithoutWidget() { + @Test(expected = IOException.class) + public void testToscaMappingWithInvalidType() throws IOException { + WidgetMapping invalidMapping = new WidgetMapping(); + invalidMapping.setType("invalid"); + WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); + } + + /** + * Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name). + * + * @throws IOException + */ + @Test(expected = IOException.class) + public void testToscaMappingWithoutWidget() throws IOException { WidgetMapping invalidMapping = new WidgetMapping(); invalidMapping.setWidget(null); WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } - + /** * Process a dummy Group object for a Service Resource. + * + * @throws XmlArtifactGenerationException + * if there is no configuration defined for a member Widget of an instance group */ @Test - public void testInstanceGroups() { + public void testInstanceGroups() throws XmlArtifactGenerationException { final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));