X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=65ec4c3c66e6d4022f1bea7df62a0a7f7ea1e4db;hb=5f1b6e4eb654639de6aaae9b7d862eb01b991f55;hp=50f0aa97e2fa0a80666a6be7091e1063c889dfaf;hpb=895cafe7aaf5f462e0bf3c3a2ab7fcb863bba78e;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 50f0aa9..65ec4c3 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -27,6 +27,7 @@ import static org.hamcrest.Matchers.is; import java.io.IOException; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; @@ -37,8 +38,11 @@ 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.Model; import org.onap.aai.babel.xml.generator.model.Resource; +import org.onap.aai.babel.xml.generator.model.Service; import org.onap.aai.babel.xml.generator.model.WidgetType; +import org.onap.aai.babel.xml.generator.types.ModelType; import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; @@ -53,18 +57,6 @@ 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. * @@ -84,8 +76,8 @@ public class TestArtifactGeneratorToscaParser { */ @Test(expected = IOException.class) public void testMissingMappingsContent() throws IOException { - String invalidJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG); - ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(invalidJson); + String emptyJson = new ArtifactTestUtils().getResourcePath(Resources.EMPTY_TOSCA_MAPPING_CONFIG); + ArtifactGeneratorToscaParser.initToscaMappingsConfiguration(emptyJson); } /** @@ -102,9 +94,12 @@ public class TestArtifactGeneratorToscaParser { /** * Process an Allotted Resource that does not have a Providing Service. + * + * @throws XmlArtifactGenerationException + * because the ALLOTTED_RESOURCE lacks a Providing Service */ - @Test(expected = IllegalArgumentException.class) - public void testMissingProvidingService() { + @Test(expected = XmlArtifactGenerationException.class) + public void testMissingProvidingService() throws XmlArtifactGenerationException { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); new ArtifactGeneratorToscaParser(null) .processResourceModels(new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true), nodeTemplateList); @@ -112,10 +107,17 @@ public class TestArtifactGeneratorToscaParser { /** * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model. + * + * @throws XmlArtifactGenerationException + * because the ALLOTTED_RESOURCE lacks a Providing Service + * @throws IOException + * if the test mappings cannot be loaded */ - @Test(expected = IllegalArgumentException.class) - public void testAddResourceNotProvidingService() { + @Test(expected = XmlArtifactGenerationException.class) + public void testAddResourceNotProvidingService() throws XmlArtifactGenerationException, IOException { + new ArtifactTestUtils().loadWidgetMappings(); List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); + // Create any Resource to which the CR can be added final Resource dummyResource = new Resource(WidgetType.valueOf("ALLOTTED_RESOURCE"), true); new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); @@ -160,6 +162,29 @@ public class TestArtifactGeneratorToscaParser { WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping)); } + /** + * Create a Resource with a Widget model type and add this to a Service. Note that there are no test CSAR files + * which require this functionality, but the code path exists to support it. + * + * @throws IOException + * if the widget mappings are not loaded + * @throws XmlArtifactGenerationException + * if there is no configuration defined for the test resource's widget type + */ + @Test + public void testAddWidgetToService() throws IOException, XmlArtifactGenerationException { + ArtifactTestUtils testUtils = new ArtifactTestUtils(); + testUtils.loadWidgetMappings(); + + Model serviceModel = new Service(); + Resource resourceModel = new Resource(WidgetType.valueOf("VF"), false); + resourceModel.setModelType(ModelType.WIDGET); + + ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class); + ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); + parser.addRelatedModel(serviceModel, resourceModel); + } + /** * Process a dummy Group object for a Service Resource. * @@ -175,21 +200,18 @@ public class TestArtifactGeneratorToscaParser { final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType)); - ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class); SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class); + List groups = Arrays.asList(buildGroup("group", instanceGroupType)); + Mockito.when(sm.getGroups()).thenReturn(new ArrayList(groups)); + NodeTemplate serviceNodeTemplate = buildNodeTemplate("service", "org.openecomp.resource.cr.a-collection-resource"); serviceNodeTemplate.setSubMappingToscaTemplate(sm); - Mockito.when(helper.getNodeTemplateByName(serviceNodeTemplate.getName())).thenReturn(serviceNodeTemplate); - ArrayList groups = new ArrayList<>(); - groups.add(buildGroup("group", instanceGroupType)); - Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups); - - ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true); - List resources = parser.processInstanceGroups(groupResource, serviceNodeTemplate); + List resources = new ArtifactGeneratorToscaParser(Mockito.mock(ISdcCsarHelper.class)) + .processInstanceGroups(groupResource, serviceNodeTemplate); assertThat(resources.size(), is(1)); Resource resource = resources.get(0);