+ /**
+ * 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<NodeTemplate> nodeTemplateList = Collections.singletonList(buildNodeTemplate("testCR", "CR"));
+ // Create any Resource to which the CR can be added
+ final Resource dummyResource = new Resource(Type.ALLOTTED_RESOURCE, true);
+ new ArtifactGeneratorToscaParser(null).processResourceModels(dummyResource, nodeTemplateList);
+ }
+
+ /**
+ * Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
+ *
+ * @throws IOException
+ */
+ @Test(expected = IOException.class)
+ public void testToscaMappingWithoutType() throws IOException {
+ WidgetMapping invalidMapping = new WidgetMapping();
+ invalidMapping.setType(null);
+ WidgetConfigurationUtil.setWidgetMappings(Collections.singletonList(invalidMapping));
+ }
+
+ /**
+ * Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
+ *
+ * @throws IOException
+ */
+ @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() throws XmlArtifactGenerationException {
+ final String instanceGroupType = "org.openecomp.groups.ResourceInstanceGroup";
+ WidgetConfigurationUtil.setSupportedInstanceGroups(Collections.singletonList(instanceGroupType));
+
+ 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<Group> groups = new ArrayList<>();
+ groups.add(buildGroup("group", instanceGroupType));
+ Mockito.when(helper.getGroupsOfOriginOfNodeTemplate(serviceNodeTemplate)).thenReturn(groups);
+
+ ArtifactGeneratorToscaParser parser = new ArtifactGeneratorToscaParser(helper);
+ List<Resource> resources =
+ parser.processInstanceGroups(new Resource(Type.INSTANCE_GROUP, true), 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
+ */