From a26e2683d10fdd4484d67bb8b7d6a2e0a41ab753 Mon Sep 17 00:00:00 2001 From: ojasdubey Date: Thu, 29 Mar 2018 11:41:55 +0530 Subject: Component Dependency create VF bug fix 1. Fixed create VF issues for scenarios where dependencies were added from the UI 2. Added supporting tests and fixed existing Change-Id: Ib8bb0074183567c263855f8723028646c9629038 Issue-ID: SDC-1184 Signed-off-by: ojasdubey --- .../tosca/AbstractSubstituteToscaEnricherTest.java | 71 +++++++++++++++++++--- 1 file changed, 62 insertions(+), 9 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 ca116a9ae3..11cab5f0a5 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 @@ -1,6 +1,15 @@ package org.openecomp.sdc.enrichment.impl.tosca; +import static org.mockito.Mockito.when; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION; +import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE; + import org.apache.commons.collections.map.HashedMap; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -17,15 +26,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.mockito.Mockito.when; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.HIGH_AVAIL_MODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MANDATORY; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MAX_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.MIN_INSTANCES; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_CODE; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_FUNCTION; -import static org.openecomp.sdc.enrichment.impl.util.EnrichmentConstants.VFC_NAMING_CODE; - public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest { @Mock @@ -165,4 +165,57 @@ public class AbstractSubstituteToscaEnricherTest extends BaseToscaEnrichmentTest Assert.assertEquals(errors.size(), 0); } + + @Test + public void testEnrichComponentAddDependencies() throws Exception { + outputFilesPath = "/mock/enrichComponentAddDependencies/out"; + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/mock/enrichComponentAddDependencies/in", + "/mock/toscaGlobalServiceTemplates/", + "MainServiceTemplate.yaml"); + + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); + List targets = new ArrayList<>(); + targets.add("ps_server"); + sourceToTargetDependencies.put("pd_server", targets); + + when(utilMock.getSourceToTargetComponent()).thenReturn(map); + + when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies); + 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); + } + + @Test + public void testEnrichComponentNoDependencies() throws Exception { + outputFilesPath = "/mock/enrichComponentNoDependencies/out"; + ToscaServiceModel toscaServiceModel = + loadToscaServiceModel("/mock/enrichComponentNoDependencies/in", + "/mock/toscaGlobalServiceTemplates/", + "MainServiceTemplate.yaml"); + + Map map = new HashMap<>(); + Map> sourceToTargetDependencies = new HashMap<>(); + + when(utilMock.getSourceToTargetComponent()).thenReturn(map); + + when(utilMock.populateDependencies(vspId,version,map)).thenReturn(sourceToTargetDependencies); + 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