summaryrefslogtreecommitdiffstats
path: root/vid-app-common/src
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt37
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java67
2 files changed, 75 insertions, 29 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt
index cdd2550a8..1a625014b 100644
--- a/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt
+++ b/vid-app-common/src/main/java/org/onap/vid/asdc/parser/ServiceModelInflator.kt
@@ -26,10 +26,21 @@ import org.springframework.stereotype.Component
@Component
class ServiceModelInflator {
+ private data class Ids (val modelCustomizationId: String?, val modelVersionId: String)
data class Names (val modelCustomizationName: String?, val modelKey: String?)
fun toNamesByVersionId(model: ServiceModel): Map<String, Names> {
- return emptyMap<String, Names>()
+ return toNamesByIds(model).mapKeys { it.key.modelVersionId }
+ }
+
+ fun toNamesByCustomizationId(model: ServiceModel): Map<String, Names> {
+ return toNamesByIds(model)
+ .filterKeys { it.modelCustomizationId != null }
+ .mapKeys { it.key.modelCustomizationId!! }
+ }
+
+ private fun toNamesByIds(model: ServiceModel): Map<Ids, Names> {
+ return emptyMap<Ids, Names>()
.plus(inflate(model.networks))
.plus(inflate(model.vnfs))
.plus(inflate(model.vnfGroups))
@@ -37,31 +48,31 @@ class ServiceModelInflator {
.plus(inflate(model.collectionResources))
}
- private fun inflate(instances: Map<String, *>): Map<String, Names> {
+ private fun inflate(instances: Map<String, *>): Map<Ids, Names> {
return instances.entries.map { inflate(it.key, it.value) }.fold(emptyMap()) { acc, it -> acc.plus(it) }
}
- private fun inflate(modelKey: String, vnf: VNF): Map<String, Names> {
- return mapOf(vnf.uuid to Names(vnf.modelCustomizationName, modelKey))
+ private fun inflate(modelKey: String, vnf: VNF): Map<Ids, Names> {
+ return mapOf(Ids(vnf.customizationUuid, vnf.uuid) to Names(vnf.modelCustomizationName, modelKey))
.plus(inflate(vnf.vfModules))
.plus(inflate(vnf.volumeGroups))
}
- private fun inflate(modelKey: String, cr: CR): Map<String, Names> {
- return mapOf(cr.uuid to Names(null, modelKey))
+ private fun inflate(modelKey: String, cr: CR): Map<Ids, Names> {
+ return mapOf(Ids(cr.customizationUuid, cr.uuid) to Names(null, modelKey))
.plus(inflate(cr.networksCollection))
}
- private fun inflate(modelKey: String, instance: Any?): Map<String, Names> {
+ private fun inflate(modelKey: String, instance: Any?): Map<Ids, Names> {
return when (instance) {
- is Network -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
- is VfModule -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
- is VolumeGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
- is ResourceGroup -> mapOf(instance.uuid to Names(instance.modelCustomizationName, modelKey))
+ is Network -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
+ is VfModule -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
+ is VolumeGroup -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
+ is ResourceGroup -> mapOf(Ids(null, instance.uuid) to Names(instance.modelCustomizationName, modelKey))
is VNF -> inflate(modelKey, instance)
is CR -> inflate(modelKey, instance)
- is NetworkCollection -> mapOf(instance.uuid to Names(null, modelKey))
- is Node -> mapOf(instance.uuid to Names(null, modelKey))
+ is NetworkCollection -> mapOf(Ids(null, instance.uuid) to Names(null, modelKey))
+ is Node -> mapOf(Ids(instance.customizationUuid, instance.uuid) to Names(null, modelKey))
else -> {
// sink
diff --git a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java
index d6c080d55..01fdd804c 100644
--- a/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/asdc/parser/ToscaParserInflatorTest.java
@@ -23,6 +23,8 @@ package org.onap.vid.asdc.parser;
import static java.util.Collections.emptyMap;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
+import static org.onap.vid.asdc.parser.ToscaParserInflatorTest.INFLATION_MODE.ByCustomizationId;
+import static org.onap.vid.asdc.parser.ToscaParserInflatorTest.INFLATION_MODE.ByVersionId;
import com.google.common.collect.ImmutableMap;
import java.io.IOException;
@@ -48,6 +50,7 @@ import org.onap.vid.asdc.parser.ServiceModelInflator.Names;
import org.onap.vid.model.ServiceModel;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
public class ToscaParserInflatorTest {
@@ -62,6 +65,28 @@ public class ToscaParserInflatorTest {
private AsdcClient asdcClient;
+ enum INFLATION_MODE {
+ ByVersionId, ByCustomizationId
+ }
+
+ @DataProvider
+ public static Object[][] inflationModes() {
+ return new Object[][] {
+ {ByVersionId}, {ByCustomizationId}
+ };
+ }
+
+ private String select(INFLATION_MODE mode, String byVersionId, String byCustomizationId) {
+ switch (mode) {
+ case ByVersionId:
+ return byVersionId;
+ case ByCustomizationId:
+ return byCustomizationId;
+ default:
+ throw new IllegalStateException();
+ }
+ }
+
@BeforeClass
void init() throws IOException {
@@ -80,29 +105,37 @@ public class ToscaParserInflatorTest {
}
- @Test
- public void inflateFabricConfigurationModel_allIdsAreGiven() throws Exception {
+ @Test(dataProvider = "inflationModes")
+ public void inflateFabricConfigurationModel_noIdsAreGiven(INFLATION_MODE inflationMode) throws Exception {
final String fabricConfigurationUuid = "12344bb4-a416-4b4e-997e-0059973630b9";
- final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
+ final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid, inflationMode);
// see vf-with-annotation-csar.json
assertThat(inflated, is(ImmutableMap.of(
- "ea81d6f7-0861-44a7-b7d5-d173b562c350", doubleName("2017-488_PASQUALE-vPE 0"),
- "a5d8df05-11cb-4351-96e0-b6d4168ea4df", new Names("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1", "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1"),
- "b3e8b26e-cff0-49fc-a4e6-f3e16c8440fe", new Names("2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2","2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2"),
- "040e591e-5d30-4e0d-850f-7266e5a8e013", new Names("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0","2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0")
+ select(inflationMode, "ea81d6f7-0861-44a7-b7d5-d173b562c350", "41516cc6-5098-4b40-a619-f8d5f55fc4d8"),
+ doubleName("2017-488_PASQUALE-vPE 0"),
+
+ select(inflationMode, "a5d8df05-11cb-4351-96e0-b6d4168ea4df", "f3d97417-0c8d-424e-8ff7-b2eb4fbcecc3"),
+ new Names("2017488PasqualeVpe..PASQUALE_vRE_BV..module-1", "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vRE_BV..module-1"),
+
+ select(inflationMode, "b3e8b26e-cff0-49fc-a4e6-f3e16c8440fe", "6e410843-257c-46d9-ba8a-8d94e1362452"),
+ new Names("2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2", "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_vPFE_BV..module-2"),
+
+ select(inflationMode, "040e591e-5d30-4e0d-850f-7266e5a8e013", "5c5f91f9-5e31-4120-b892-5536587ec258"),
+ new Names("2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0", "2017488_pasqualevpe0..2017488PasqualeVpe..PASQUALE_base_vPE_BV..module-0")
)));
}
- @Test
- public void inflateVlModel_allIdsAreGiven() throws Exception {
+ @Test(dataProvider = "inflationModes")
+ public void inflateVlModel_allIdsAreGiven(INFLATION_MODE inflationMode) throws Exception {
final String fabricConfigurationUuid = "cb49608f-5a24-4789-b0f7-2595473cb997";
- final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid);
+ final Map<String, Names> inflated = inflateModelByUuid(fabricConfigurationUuid, inflationMode);
// see vl-csar.json
assertThat(inflated, is(ImmutableMap.of(
- "af584529-d7f0-420e-a6f3-c38b689c030f", doubleName("ExtVL 0")
+ select(inflationMode, "af584529-d7f0-420e-a6f3-c38b689c030f", "664f8aa7-3989-46ac-81c0-dd72a8a63f26"),
+ doubleName("ExtVL 0")
)));
}
@@ -111,21 +144,23 @@ public class ToscaParserInflatorTest {
return new Names(modelCustomizationName, modelCustomizationName);
}
- @Test
- public void inflateConfigurationByPolicyFalseUuid_allIdsAreGiven() throws Exception {
+ @Test(dataProvider = "inflationModes")
+ public void inflateConfigurationByPolicyFalseUuid_allIdsAreGiven(INFLATION_MODE inflationMode) throws Exception {
final String configurationByPolicyFalseUuid = "ee6d61be-4841-4f98-8f23-5de9da845544";
- final Map<String, Names> inflated = inflateModelByUuid(configurationByPolicyFalseUuid);
+ final Map<String, Names> inflated = inflateModelByUuid(configurationByPolicyFalseUuid, inflationMode);
// see policy-configuration-by-policy-false.json
// no relevant model here
assertThat(inflated, is(emptyMap()));
}
- private Map<String, Names> inflateModelByUuid(String fabricConfigurationUuid) throws SdcToscaParserException, AsdcCatalogException {
+ private Map<String, Names> inflateModelByUuid(String fabricConfigurationUuid, INFLATION_MODE inflationMode) throws SdcToscaParserException, AsdcCatalogException {
ServiceModel actualServiceModel = serviceModelByUuid(fabricConfigurationUuid);
ServiceModelInflator serviceModelInflator = new ServiceModelInflator();
- return serviceModelInflator.toNamesByVersionId(actualServiceModel);
+ return inflationMode == ByVersionId
+ ? serviceModelInflator.toNamesByVersionId(actualServiceModel)
+ : serviceModelInflator.toNamesByCustomizationId(actualServiceModel);
}
private ServiceModel serviceModelByUuid(String uuid) throws SdcToscaParserException, AsdcCatalogException {