From c9e7a45f31a60ec51b770febae2213f5b7668960 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Thu, 13 Dec 2018 18:02:21 +0530 Subject: Fix - nfc_naming_code and nfc_function 1. Fix for nfc_naming code not getting populated for more than one instance of same vm type 2. Added and updated the unit test cases and test data 3. Sonar fixes Change-Id: I50ddb7d388a5e6b2d4370dedfbbe23ba31a4b61d Issue-ID: SDC-2001 Signed-off-by: ojasdubey --- .../tosca/AbstractSubstituteToscaEnricherTest.java | 71 ++++++++++++++++------ 1 file changed, 54 insertions(+), 17 deletions(-) (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java') diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricherTest.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricherTest.java index 8430556f87..f185116598 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricherTest.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/tosca/AbstractSubstituteToscaEnricherTest.java @@ -30,7 +30,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.collections.map.HashedMap; + import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -49,8 +49,8 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest @InjectMocks AbstractSubstituteToscaEnricher toscaEnricher; - String vspId = null; - Version version = new Version(); + private String vspId = null; + private Version version = new Version(); @Before public void injectDoubles() { @@ -83,9 +83,9 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn (componentTypetoParams); - Map map = new HashMap(); - Map> sourceToTargetDependencies = new HashMap>(); - List targets = new ArrayList(); + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); + List targets = new ArrayList<>(); targets.add("fe"); targets.add("be"); sourceToTargetDependencies.put("pd_server", targets); @@ -110,8 +110,8 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest "/mock/toscaGlobalServiceTemplates/", "MainServiceTemplate.yaml"); - Map> componentTypetoParams = new HashMap(); - Map innerProps = new HashedMap(); + Map> componentTypetoParams = new HashMap<>(); + Map innerProps = new HashMap<>(); innerProps.put(MANDATORY, "NO"); innerProps.put(HIGH_AVAIL_MODE, ""); innerProps.put(NFC_NAMING_CODE, "pd_server_code1"); @@ -125,8 +125,8 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn (componentTypetoParams); - Map map = new HashMap(); - Map> sourceToTargetDependencies = new HashMap>(); + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); when(utilMock.getSourceToTargetComponent()).thenReturn(map); when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies); @@ -148,23 +148,23 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest "/mock/toscaGlobalServiceTemplates/", "MainServiceTemplate.yaml"); - Map> componentTypetoParams = new HashMap(); - Map innerProps = new HashedMap(); + Map> componentTypetoParams = new HashMap<>(); + Map innerProps = new HashMap<>(); innerProps.put(MANDATORY, ""); innerProps.put(MIN_INSTANCES, 1); innerProps.put(MAX_INSTANCES, 5); - componentTypetoParams.put("pd_server_vm", innerProps); + componentTypetoParams.put("pd_server", innerProps); when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn (componentTypetoParams); - Map map = new HashMap(); - Map> sourceToTargetDependencies = new HashMap>(); - List targets = new ArrayList(); + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); + List targets = new ArrayList<>(); targets.add("fe"); - sourceToTargetDependencies.put("pd_server_vm", targets); + sourceToTargetDependencies.put("pd_server", targets); when(utilMock.getSourceToTargetComponent()).thenReturn(map); @@ -233,4 +233,41 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest Assert.assertEquals(errors.size(), 0); } + + @Test + public void testEnrichComponentSameVmTypeNfcNamingFunction() throws Exception { + outputFilesPath = "/mock/enrichNfcNamingFunction/out"; + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/mock/enrichNfcNamingFunction/in", + "/mock/toscaGlobalServiceTemplates/", + "MainServiceTemplate.yaml"); + + Map> componentTypetoParams = new HashMap<>(); + Map innerProps = new HashMap<>(); + innerProps.put(MANDATORY, "NO"); + innerProps.put(HIGH_AVAIL_MODE, ""); + innerProps.put(NFC_NAMING_CODE, "cfed_changed_from_ui"); + innerProps.put(VFC_CODE, "pd_server_code"); + innerProps.put(NFC_FUNCTION, "cfed_naming_function"); + innerProps.put(MIN_INSTANCES, null); + innerProps.put(MAX_INSTANCES, null); + + componentTypetoParams.put("cfed", innerProps); + + when(utilMock.getPropertiesfromCompQuestionnaire(vspId,version)).thenReturn + (componentTypetoParams); + + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); + + when(utilMock.getSourceToTargetComponent()).thenReturn(map); + when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies); + + Map> errors = + toscaEnricher.enrich(toscaServiceModel, vspId, version ); + + compareActualAndExpectedModel(toscaServiceModel); + + Assert.assertEquals(errors.size(), 0); + } } -- cgit 1.2.3-korg