From 6068ce140c9a65f13a0bd245c9b9a50befaddc32 Mon Sep 17 00:00:00 2001 From: xuegao Date: Thu, 11 Feb 2021 15:16:36 +0100 Subject: Fix pnf csar package issue Generate the dependencies and imports even derivedFrom list is empty. Issue-ID: SDC-3391 Signed-off-by: xuegao Change-Id: Ia07d1d6a73a1e08fb8f5ba1678b15e71aecd54b0 Signed-off-by: xuegao --- .../sdc/be/tosca/ToscaExportHandlerTest.java | 43 ++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'catalog-be/src/test/java/org') diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java index a87460fa93..71a43acdb4 100644 --- a/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/tosca/ToscaExportHandlerTest.java @@ -37,6 +37,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; import static org.openecomp.sdc.be.tosca.PropertyConvertor.PropertyType.PROPERTY; @@ -46,6 +48,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.LinkedList; import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -72,6 +75,7 @@ import org.openecomp.sdc.be.datatypes.elements.RequirementDataDefinition; import org.openecomp.sdc.be.datatypes.elements.ToscaArtifactDataDefinition; import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum; import org.openecomp.sdc.be.datatypes.enums.OriginTypeEnum; +import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum; import org.openecomp.sdc.be.exception.ToscaExportException; import org.openecomp.sdc.be.model.ArtifactDefinition; import org.openecomp.sdc.be.model.CapabilityDefinition; @@ -328,6 +332,45 @@ public class ToscaExportHandlerTest extends BeConfDependentTest { Assert.assertNotNull(result); } + @Test + public void testSetImports() throws Exception { + Resource resource = new Resource(); + resource.setResourceType(ResourceTypeEnum.PNF); + + Component component = resource; + component.setName("TestResourceName"); + Map artifactList = new HashMap<>(); + ArtifactDefinition artifact = new ArtifactDefinition(); + artifact.setArtifactName("name.name2"); + artifactList.put("assettoscatemplate", artifact); + component.setArtifacts(artifactList); + component.setToscaArtifacts(artifactList); + ToscaTemplate toscaTemplate = new ToscaTemplate(""); + + + ComponentInstance ci = new ComponentInstance(); + ci.setComponentUid("name"); + ci.setOriginType(OriginTypeEnum.PNF); + ci.setSourceModelUid("modelName"); + List componentInstanceList = new LinkedList<>(); + componentInstanceList.add(ci); + component.setComponentInstances(componentInstanceList); + + when(toscaOperationFacade.getToscaFullElement(eq("name"))).thenReturn(Either.left(component)); + + Either>, ToscaError> result; + result = Deencapsulation.invoke(testSubject, "fillImports", component, toscaTemplate); + + verify(toscaOperationFacade, times(1)).getToscaFullElement("name"); + Assert.assertTrue(result.isLeft()); + ToscaTemplate toscaTemplateRes = result.left().value().left; + Assert.assertTrue(toscaTemplateRes.getImports().size() == 8); + Assert.assertNotNull(toscaTemplateRes.getImports().get(6).get("resource-TestResourceName-interface")); + Assert.assertNotNull(toscaTemplateRes.getImports().get(7).get("resource-TestResourceName")); + Assert.assertTrue(toscaTemplateRes.getDependencies().size() == 1); + Assert.assertNotNull(toscaTemplateRes.getDependencies().get(0).getLeft().equals("name.name2")); + } + @Test public void testConvertToscaTemplate() throws Exception { -- cgit 1.2.3-korg