import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
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;
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.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Generator with no Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Generator with invalid Widget Mappings content.
- *
+ *
* @throws IOException
* if the file content could not be read successfully
*/
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no type).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with invalid data (type value).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
/**
* Initialize the Artifact Generator Widget Mapping config with incomplete data (no widget name).
- *
+ *
* @throws IOException
* if a WidgetMapping is invalid
*/
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.
- *
+ *
* @throws XmlArtifactGenerationException
* if there is no configuration defined for a member Widget of an instance group
* @throws IOException
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<Group> groups = Arrays.asList(buildGroup("group", instanceGroupType));
+ Mockito.when(sm.getGroups()).thenReturn(new ArrayList<Group>(groups));
+
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);
+ List<Resource> resources = new ArtifactGeneratorToscaParser(Mockito.mock(ISdcCsarHelper.class))
+ .processInstanceGroups(groupResource, serviceNodeTemplate);
assertThat(resources.size(), is(1));
Resource resource = resources.get(0);