+ /**
+ * 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.
+ *
+ * @throws XmlArtifactGenerationException
+ * if there is no configuration defined for a member Widget of an instance group
+ * @throws IOException
+ * if the widget mappings cannot be loaded
+ */
+ @Test
+ public void testInstanceGroups() throws XmlArtifactGenerationException, IOException {
+ new ArtifactTestUtils().loadWidgetMappings();
+
+ 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);
+ Resource groupResource = new Resource(WidgetType.valueOf("INSTANCE_GROUP"), true);
+ List<Resource> resources = parser.processInstanceGroups(groupResource, 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
+ */