X-Git-Url: https://gerrit.onap.org/r/gitweb?p=aai%2Fbabel.git;a=blobdiff_plain;f=src%2Ftest%2Fjava%2Forg%2Fonap%2Faai%2Fbabel%2Fparser%2FTestArtifactGeneratorToscaParser.java;h=b7957f780d1f5508477a85a4cc6a849d91840b6e;hp=3cbaa13ca58fe4cd659125e0cbb38bf45be674e3;hb=05e7b934ad49c54c98ce840841528a13e882f8d3;hpb=047862bba53addd381fc7c715ac9e3dff76b740d 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 3cbaa13..b7957f7 100644 --- a/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java +++ b/src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java @@ -30,7 +30,6 @@ 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; @@ -49,114 +48,114 @@ import org.onap.sdc.toscaparser.api.SubstitutionMappings; public class TestArtifactGeneratorToscaParser { - private static final String TEST_UUID = "1234"; - - /** - * Process an Allotted Resource that does not have a Providing Service. - */ - @Test(expected = IllegalArgumentException.class) - public void testMissingProvidingService() { - List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); - new ArtifactGeneratorToscaParser(null).processResourceModels(new AllotedResource(), nodeTemplateList); - } - - /** - * - * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model. - */ - @Test(expected = IllegalArgumentException.class) - public void testAddResourceNotProvidingService() { - List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); - final Resource dummyResource = new AllotedResource(); // Any Resource to which the CR can be added - new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); - } - - /** - * 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); - SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class); - - 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); - List resources = parser.processInstanceGroups(new InstanceGroup(), serviceNodeTemplate); - - assertThat(resources.size(), is(1)); - Resource resource = resources.get(0); - assertThat(resource.getModelNameVersionId(), is(equalTo(TEST_UUID))); - } - - /** - * Create a NodeTemplate for unit testing purposes. In production code this object would only be created by the - * sdc-tosca parser. - * - * @param name - * name of the NodeTemplate - * @param type - * type of the NodeTemplate - * @return a new NodeTemplate object - */ - 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); - 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; - } + private static final String TEST_UUID = "1234"; + + /** + * Process an Allotted Resource that does not have a Providing Service. + */ + @Test(expected = IllegalArgumentException.class) + public void testMissingProvidingService() { + List nodeTemplateList = Collections.singletonList(buildNodeTemplate("name", "BlockStorage")); + new ArtifactGeneratorToscaParser(null).processResourceModels(new AllotedResource(), nodeTemplateList); + } + + /** + * + * Add a CR (a type of Resource which is not a Providing Service) to a Resource Model. + */ + @Test(expected = IllegalArgumentException.class) + public void testAddResourceNotProvidingService() { + List nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR")); + final Resource dummyResource = new AllotedResource(); // Any Resource to which the CR can be added + new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList); + } + + /** + * 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); + SubstitutionMappings sm = Mockito.mock(SubstitutionMappings.class); + + 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); + List resources = parser.processInstanceGroups(new InstanceGroup(), serviceNodeTemplate); + + assertThat(resources.size(), is(1)); + Resource resource = resources.get(0); + assertThat(resource.getModelNameVersionId(), is(equalTo(TEST_UUID))); + } + + /** + * Create a NodeTemplate for unit testing purposes. In production code this object would only be created by the + * sdc-tosca parser. + * + * @param name + * name of the NodeTemplate + * @param type + * type of the NodeTemplate + * @return a new NodeTemplate object + */ + 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); + 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; + } }