X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=822cda5b06e68f54737d084866b81dd0157328df;hb=3452a390f7f04f4873a47718e2d8e558e92ce03a;hp=a74efaf96a79827b6f3ba606e8832ba2bea4a0c1;hpb=a2c5714eabfb87d4a59f106e418c967b599c4212;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 a74efaf..822cda5 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -21,11 +21,25 @@ package org.onap.aai.babel.parser; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.is; + +import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +import java.util.Properties; import org.junit.Test; +import org.mockito.Mockito; +import org.onap.aai.babel.xml.generator.data.WidgetConfigurationUtil; +import org.onap.aai.babel.xml.generator.model.InstanceGroup; +import org.onap.aai.babel.xml.generator.model.Model; +import org.onap.aai.babel.xml.generator.model.Resource; +import org.onap.sdc.tosca.parser.api.ISdcCsarHelper; +import org.onap.sdc.toscaparser.api.Group; import org.onap.sdc.toscaparser.api.NodeTemplate; +import org.onap.sdc.toscaparser.api.SubstitutionMappings; /** * Direct tests of the TOSCA parser-based Artifact Generator, to cover exceptional cases. @@ -33,7 +47,7 @@ import org.onap.sdc.toscaparser.api.NodeTemplate; public class TestArtifactGeneratorToscaParser { - ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(null); + private static final String TEST_UUID = "1234"; /** * Process a dummy Node Template object for a Service. A WARNING should be logged for the missing metadata. @@ -41,16 +55,89 @@ public class TestArtifactGeneratorToscaParser { @Test public void testMissingServiceData() { List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); + ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(null); parser.processServiceTosca(null, Collections.emptyMap(), nodeTemplateList); parser.processResourceToscas(nodeTemplateList, null); } + /** + * Process a dummy Group object for a Service Resource. + */ + @Test + public void testInstanceGroups() { + final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup"; + Properties props = new Properties(); + props.put("AAI.instance-group-types", instanceGroupType); + WidgetConfigurationUtil.setFilterConfig(props); + + ISdcCsarHelper helper = Mockito.mock(ISdcCsarHelper.class); + NodeTemplate serviceNodeTemplate = Mockito.mock(NodeTemplate.class); + SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class); + + Mockito.when(serviceNodeTemplate.getSubMappingToscaTemplate()).thenReturn(sm); + + NodeTemplate serviceNode = buildNodeTemplate("service", "org.openecomp.resource.cr.a-collection-resource"); + Mockito.when(helper.getNodeTemplateByName(serviceNode.getName())).thenReturn(serviceNodeTemplate); + + ArrayList groups = new ArrayList<>(); + groups.add(buildGroup("group", instanceGroupType)); + Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNode)).thenReturn(groups); + + ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper); + Model resourceModel = new InstanceGroup(); + List resources = parser.processInstanceGroups(resourceModel, serviceNode); + + assertThat(resources.size(), is(1)); + Resource resource = resources.get(0); + assertThat(resource.getModelNameVersionId(), is(equalTo(TEST_UUID))); + } + private NodeTemplate buildNodeTemplate(String name, String type) { LinkedHashMap nodeTemplateMap = new LinkedHashMap<>(); + nodeTemplateMap.put(name, buildMap("type", type)); + nodeTemplateMap.put(type, buildNodeTemplateCustomDefs()); + return new NodeTemplate(name, nodeTemplateMap, nodeTemplateMap, null, null); + } + + private LinkedHashMap buildNodeTemplateCustomDefs() { + LinkedHashMap customDefs = buildCustomDefs(); + customDefs.put("attributes", null); + customDefs.put("requirements", null); + customDefs.put("capabilities", null); + customDefs.put("artifacts", null); + return customDefs; + } + + private Group buildGroup(String name, String type) { LinkedHashMap template = new LinkedHashMap<>(); template.put("type", type); - nodeTemplateMap.put(name, template); - return new NodeTemplate(name, nodeTemplateMap, null, null, null); + template.put("metadata", new LinkedHashMap<>()); + template.put("properties", buildMap("UUID", TEST_UUID)); + LinkedHashMap customDefMap = buildMap(name, template); + customDefMap.put(type, buildGroupCustomDefs()); + return new Group(name, template, null, customDefMap); } + private LinkedHashMap buildGroupCustomDefs() { + LinkedHashMap customDefs = buildCustomDefs(); + customDefs.put("members", null); + return customDefs; + } + + private LinkedHashMap buildCustomDefs() { + LinkedHashMap customDefs = new LinkedHashMap<>(); + customDefs.put("derived_from", null); + customDefs.put("metadata", null); + customDefs.put("version", null); + customDefs.put("description", null); + customDefs.put("interfaces", null); + customDefs.put("properties", buildMap("UUID", buildMap("type", "java.lang.String"))); + return customDefs; + } + + private LinkedHashMap buildMap(String key, Object value) { + LinkedHashMap map = new LinkedHashMap<>(); + map.put(key, value); + return map; + } }