aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2018-11-27 16:54:33 +0000
committermark.j.leonard <mark.j.leonard@gmail.com>2018-11-27 16:54:33 +0000
commit05e7b934ad49c54c98ce840841528a13e882f8d3 (patch)
tree7e531b70c09201cf9a076d0c84dea3044812e9f1 /src/test
parent047862bba53addd381fc7c715ac9e3dff76b740d (diff)
Process Service-level Instance Groups
Create an InstanceGroup XML model for groups of the Service topology template in the case where there is no Resource model generated. Add a test CSAR file for a Service Proxy (an unsupported type). Assert that the Service is associated with the instance-group Models. Change-Id: If76bf7a1cfb960bc8692f1e136ee85176725915e Issue-ID: AAI-1963 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/babel/parser/TestArtifactGeneratorToscaParser.java221
-rw-r--r--src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java10
-rw-r--r--src/test/java/org/onap/aai/babel/testdata/CsarTest.java4
-rw-r--r--src/test/resources/compressedArtifacts/service-S1-csar.csarbin0 -> 67874 bytes
-rw-r--r--src/test/resources/generatedXml/AAI-Grouping Service for Test-service-1.0.xml69
-rw-r--r--src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..0-resource-1.xml32
-rw-r--r--src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..1-resource-1.xml32
7 files changed, 255 insertions, 113 deletions
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<NodeTemplate> 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<NodeTemplate> 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<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 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<String, Object> nodeTemplateMap = new LinkedHashMap<>();
- nodeTemplateMap.put(name, buildMap("type", type));
- nodeTemplateMap.put(type, buildNodeTemplateCustomDefs());
- return new NodeTemplate(name, nodeTemplateMap, nodeTemplateMap, null, null);
- }
-
- private LinkedHashMap<String, Object> buildNodeTemplateCustomDefs() {
- LinkedHashMap<String, Object> 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<String, Object> template = new LinkedHashMap<>();
- template.put("type", type);
- template.put("metadata", new LinkedHashMap<>());
- template.put("properties", buildMap("UUID", TEST_UUID));
- LinkedHashMap<String, Object> customDefMap = buildMap(name, template);
- customDefMap.put(type, buildGroupCustomDefs());
- return new Group(name, template, null, customDefMap);
- }
-
- private LinkedHashMap<String, Object> buildGroupCustomDefs() {
- LinkedHashMap<String, Object> customDefs = buildCustomDefs();
- customDefs.put("members", null);
- return customDefs;
- }
-
- private LinkedHashMap<String, Object> buildCustomDefs() {
- LinkedHashMap<String, Object> 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<String, Object> buildMap(String key, Object value) {
- LinkedHashMap<String, Object> 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<NodeTemplate> 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<NodeTemplate> 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<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 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<String, Object> nodeTemplateMap = new LinkedHashMap<>();
+ nodeTemplateMap.put(name, buildMap("type", type));
+ nodeTemplateMap.put(type, buildNodeTemplateCustomDefs());
+ return new NodeTemplate(name, nodeTemplateMap, nodeTemplateMap, null, null);
+ }
+
+ private LinkedHashMap<String, Object> buildNodeTemplateCustomDefs() {
+ LinkedHashMap<String, Object> 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<String, Object> template = new LinkedHashMap<>();
+ template.put("type", type);
+ template.put("metadata", new LinkedHashMap<>());
+ template.put("properties", buildMap("UUID", TEST_UUID));
+ LinkedHashMap<String, Object> customDefMap = buildMap(name, template);
+ customDefMap.put(type, buildGroupCustomDefs());
+ return new Group(name, template, null, customDefMap);
+ }
+
+ private LinkedHashMap<String, Object> buildGroupCustomDefs() {
+ LinkedHashMap<String, Object> customDefs = buildCustomDefs();
+ customDefs.put("members", null);
+ return customDefs;
+ }
+
+ private LinkedHashMap<String, Object> buildCustomDefs() {
+ LinkedHashMap<String, Object> 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<String, Object> buildMap(String key, Object value) {
+ LinkedHashMap<String, Object> map = new LinkedHashMap<>();
+ map.put(key, value);
+ return map;
+ }
}
diff --git a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
index 297bb4d..84a2934 100644
--- a/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
+++ b/src/test/java/org/onap/aai/babel/service/CsarToXmlConverterTest.java
@@ -191,6 +191,16 @@ public class CsarToXmlConverterTest {
assertThatGeneratedFilesMatchExpected(createExpectedXmlFiles(filesToLoad), CsarTest.PORT_MIRROR_CSAR);
}
+ @Test
+ public void generateXmlFromServiceProxyCsar()
+ throws CsarConverterException, IOException, XmlArtifactGenerationException {
+ List<String> filesToLoad = new ArrayList<>();
+ filesToLoad.add("AAI-Grouping Service for Test-service-1.0.xml");
+ filesToLoad.add("AAI-groupingservicefortest..ResourceInstanceGroup..0-resource-1.xml");
+ filesToLoad.add("AAI-groupingservicefortest..ResourceInstanceGroup..1-resource-1.xml");
+ assertThatGeneratedFilesMatchExpected(createExpectedXmlFiles(filesToLoad), CsarTest.SERVICE_PROXY_CSAR_FILE);
+ }
+
public Matcher<String> matches(final String expected) {
return new BaseMatcher<String>() {
protected String theExpected = expected;
diff --git a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
index 0def88b..4f4c8ad 100644
--- a/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
+++ b/src/test/java/org/onap/aai/babel/testdata/CsarTest.java
@@ -43,8 +43,8 @@ public enum CsarTest {
NO_YAML_FILES("noYmlFilesArchive.zip"),
PORT_MIRROR_CSAR("service_PortMirror.csar"),
MULTIPLE_VNF_CSAR("catalog_csar_too_many_vnfConfigurations.csar"),
- NETWORK_COLLECTION_CSAR_FILE("service_NetworkCollection.csar");
-
+ NETWORK_COLLECTION_CSAR_FILE("service_NetworkCollection.csar"),
+ SERVICE_PROXY_CSAR_FILE("service-S1-csar.csar");
// @formatter:on
private String filename;
diff --git a/src/test/resources/compressedArtifacts/service-S1-csar.csar b/src/test/resources/compressedArtifacts/service-S1-csar.csar
new file mode 100644
index 0000000..9bd9889
--- /dev/null
+++ b/src/test/resources/compressedArtifacts/service-S1-csar.csar
Binary files differ
diff --git a/src/test/resources/generatedXml/AAI-Grouping Service for Test-service-1.0.xml b/src/test/resources/generatedXml/AAI-Grouping Service for Test-service-1.0.xml
new file mode 100644
index 0000000..2bafb2f
--- /dev/null
+++ b/src/test/resources/generatedXml/AAI-Grouping Service for Test-service-1.0.xml
@@ -0,0 +1,69 @@
+<model xmlns="http://org.onap.aai.inventory/v14">
+ <model-invariant-id>service-invariant-uuid</model-invariant-id>
+ <model-type>service</model-type>
+ <model-vers>
+ <model-ver>
+ <model-version-id>service-uuid</model-version-id>
+ <model-name>Grouping Service for Test</model-name>
+ <model-version>1.0</model-version>
+ <model-description>xxx</model-description>
+ <model-elements>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ <model-elements>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ <model-elements/>
+ <relationship-list>
+ <relationship>
+ <related-to>model-ver</related-to>
+ <relationship-data>
+ <relationship-key>model-ver.model-version-id</relationship-key>
+ <relationship-value>instance-group-0-version-id</relationship-value>
+ </relationship-data>
+ <relationship-data>
+ <relationship-key>model.model-invariant-id</relationship-key>
+ <relationship-value>instance-group-0-invariant-id</relationship-value>
+ </relationship-data>
+ </relationship>
+ </relationship-list>
+ </model-element>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ <model-elements/>
+ <relationship-list>
+ <relationship>
+ <related-to>model-ver</related-to>
+ <relationship-data>
+ <relationship-key>model-ver.model-version-id</relationship-key>
+ <relationship-value>instance-group-1-version-id</relationship-value>
+ </relationship-data>
+ <relationship-data>
+ <relationship-key>model.model-invariant-id</relationship-key>
+ <relationship-value>instance-group-1-invariant-id</relationship-value>
+ </relationship-data>
+ </relationship>
+ </relationship-list>
+ </model-element>
+ </model-elements>
+ <relationship-list>
+ <relationship>
+ <related-to>model-ver</related-to>
+ <relationship-data>
+ <relationship-key>model-ver.model-version-id</relationship-key>
+ <relationship-value>service-instance-version-id</relationship-value>
+ </relationship-data>
+ <relationship-data>
+ <relationship-key>model.model-invariant-id</relationship-key>
+ <relationship-value>service-instance-invariant-id</relationship-value>
+ </relationship-data>
+ </relationship>
+ </relationship-list>
+ </model-element>
+ </model-elements>
+ </model-ver>
+ </model-vers>
+</model> \ No newline at end of file
diff --git a/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..0-resource-1.xml b/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..0-resource-1.xml
new file mode 100644
index 0000000..b246667
--- /dev/null
+++ b/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..0-resource-1.xml
@@ -0,0 +1,32 @@
+<model xmlns="http://org.onap.aai.inventory/v14">
+ <model-invariant-id>instance-group-0-invariant-id</model-invariant-id>
+ <model-type>resource</model-type>
+ <model-vers>
+ <model-ver>
+ <model-version-id>instance-group-0-version-id</model-version-id>
+ <model-name>groupingservicefortest..ResourceInstanceGroup..0</model-name>
+ <model-version>1</model-version>
+ <model-description>DDD0</model-description>
+ <model-elements>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ <model-elements/>
+ <relationship-list>
+ <relationship>
+ <related-to>model-ver</related-to>
+ <relationship-data>
+ <relationship-key>model-ver.model-version-id</relationship-key>
+ <relationship-value>instance-group-version-id</relationship-value>
+ </relationship-data>
+ <relationship-data>
+ <relationship-key>model.model-invariant-id</relationship-key>
+ <relationship-value>instance-group-invariant-id</relationship-value>
+ </relationship-data>
+ </relationship>
+ </relationship-list>
+ </model-element>
+ </model-elements>
+ </model-ver>
+ </model-vers>
+</model> \ No newline at end of file
diff --git a/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..1-resource-1.xml b/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..1-resource-1.xml
new file mode 100644
index 0000000..d49e480
--- /dev/null
+++ b/src/test/resources/generatedXml/AAI-groupingservicefortest..ResourceInstanceGroup..1-resource-1.xml
@@ -0,0 +1,32 @@
+<model xmlns="http://org.onap.aai.inventory/v14">
+ <model-invariant-id>instance-group-1-invariant-id</model-invariant-id>
+ <model-type>resource</model-type>
+ <model-vers>
+ <model-ver>
+ <model-version-id>instance-group-1-version-id</model-version-id>
+ <model-name>groupingservicefortest..ResourceInstanceGroup..1</model-name>
+ <model-version>1</model-version>
+ <model-description>DDD1</model-description>
+ <model-elements>
+ <model-element>
+ <new-data-del-flag>T</new-data-del-flag>
+ <cardinality>unbounded</cardinality>
+ <model-elements/>
+ <relationship-list>
+ <relationship>
+ <related-to>model-ver</related-to>
+ <relationship-data>
+ <relationship-key>model-ver.model-version-id</relationship-key>
+ <relationship-value>instance-group-version-id</relationship-value>
+ </relationship-data>
+ <relationship-data>
+ <relationship-key>model.model-invariant-id</relationship-key>
+ <relationship-value>instance-group-invariant-id</relationship-value>
+ </relationship-data>
+ </relationship>
+ </relationship-list>
+ </model-element>
+ </model-elements>
+ </model-ver>
+ </model-vers>
+</model>