From df348f9866e922122c7eb9c48210e18da3679913 Mon Sep 17 00:00:00 2001 From: amitjai Date: Wed, 10 Jan 2018 15:02:59 +0530 Subject: Fixed Lifefcycle operation issue Artifact Process Entity is not populating with all filed hence nullpointer exception while writing artifact file. Change-Id: Ie26982471c25fc6c1a38bbe8a0e07efa7b33577d Issue-ID: SDC-896 Signed-off-by: amitjai --- .../external/artifact/ProcessArtifactEnricher.java | 2 +- .../artifact/ProcessArtifactEnricherTest.java | 160 ++++++++++++++++++++- 2 files changed, 157 insertions(+), 5 deletions(-) (limited to 'openecomp-be') diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java index e2ae60d87e..30a8965809 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/main/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricher.java @@ -65,7 +65,7 @@ public class ProcessArtifactEnricher implements ExternalArtifactEnricherInterfac ProcessEntity artifactEntity = new ProcessEntity(vspId, version, componentId, entity.getId()); - ProcessEntity artifactProcessEntity = getProcessDao().get(artifactEntity); + ProcessEntity artifactProcessEntity = getProcessDao().getArtifact(artifactEntity); if (artifactProcessEntity != null && ProcessType.Lifecycle_Operations.equals( artifactProcessEntity.getType()) && artifactProcessEntity.getArtifactName() != null ) { diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java index 59931a1a11..84050dce49 100644 --- a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java @@ -1,7 +1,37 @@ package org.openecomp.sdc.enrichment.impl.external.artifact; +import java.util.Collection; +import org.mockito.ArgumentCaptor; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.openecomp.core.enrichment.types.ArtifactCategory; +import org.openecomp.core.model.dao.EnrichedServiceModelDao; +import org.openecomp.core.model.types.ServiceArtifact; +import org.openecomp.core.utilities.file.FileUtils; +import org.openecomp.sdc.enrichment.EnrichmentInfo; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ProcessType; +import org.openecomp.sdc.versioning.dao.types.Version; +import org.testng.Assert; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.File; +import java.nio.ByteBuffer; +import java.util.ArrayList; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.when; + public class ProcessArtifactEnricherTest { - /*@Mock + @Mock ProcessDao processDaoMock; @Mock EnrichedServiceModelDao enrichedServiceModelDaoMock; @@ -42,12 +72,12 @@ public class ProcessArtifactEnricherTest { list.add(processEntity); when(processDaoMock.list(entity)).thenReturn(list); - when(processDaoMock.get(anyObject())).thenReturn(processEntity); + when(processDaoMock.getArtifact(anyObject())).thenReturn(processEntity); EnrichmentInfo info = new EnrichmentInfo(); info.setVersion(version); info.setKey(vspId); - processArtifactEnricher.enrich(info); + processArtifactEnricher.enrich(info, null); String componentName = componentEntity.getComponentCompositionData().getName(); @@ -63,6 +93,128 @@ public class ProcessArtifactEnricherTest { } + @Test + public void testEnrichComponentArtifactNameIsNull() throws Exception { + String vspId = "123"; + String componentId = "1111111111"; + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); + + ProcessEntity entity = new ProcessEntity(vspId, version, componentId, null); + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setType(ProcessType.Other); + processEntity.setVspId(vspId); + processEntity.setVersion(version); + processEntity.setComponentId(componentId); + processEntity.setArtifactName("artifact_1kb.txt"); + processEntity.setArtifact(getMibByteBuffer("/mock/enrichProcess/artifact_1kb.txt")); + + Collection componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection list = new ArrayList<>(); + list.add(processEntity); + when(processDaoMock.list(entity)).thenReturn(list); + + when(processDaoMock.getArtifact(anyObject())).thenReturn(processEntity); + + EnrichmentInfo info = new EnrichmentInfo(); + info.setVersion(version); + info.setKey(vspId); + processArtifactEnricher.enrich(info, null); + + String componentName = componentEntity.getComponentCompositionData().getName(); + + ArgumentCaptor expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + Mockito.verify(enrichedServiceModelDaoMock, never()) + .storeExternalArtifact(expectedServiceArtifact.capture()); + } + + @Test + public void testEnrichComponentProcessEntityIsNull() throws Exception { + String vspId = "123"; + String componentId = "1111111111"; + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); + + ProcessEntity entity = new ProcessEntity(vspId, version, componentId, null); + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setType(ProcessType.Other); + processEntity.setVspId(vspId); + processEntity.setVersion(version); + processEntity.setComponentId(componentId); + processEntity.setArtifactName("artifact_1kb.txt"); + processEntity.setArtifact(getMibByteBuffer("/mock/enrichProcess/artifact_1kb.txt")); + + Collection componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection list = new ArrayList<>(); + list.add(processEntity); + when(processDaoMock.list(entity)).thenReturn(list); + + when(processDaoMock.getArtifact(anyObject())).thenReturn(null); + + EnrichmentInfo info = new EnrichmentInfo(); + info.setVersion(version); + info.setKey(vspId); + processArtifactEnricher.enrich(info, null); + + ArgumentCaptor expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + Mockito.verify(enrichedServiceModelDaoMock, never()) + .storeExternalArtifact(expectedServiceArtifact.capture()); + } + + @Test + public void testEnrichComponentNotALifecycleOperations() throws Exception { + String vspId = "123"; + String componentId = "1111111111"; + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); + + ProcessEntity entity = new ProcessEntity(vspId, version, componentId, null); + ProcessEntity processEntity = new ProcessEntity(); + processEntity.setType(ProcessType.Lifecycle_Operations); + processEntity.setVspId(vspId); + processEntity.setVersion(version); + processEntity.setComponentId(componentId); + processEntity.setArtifactName(null); + processEntity.setArtifact(getMibByteBuffer("/mock/enrichProcess/artifact_1kb.txt")); + + Collection componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection list = new ArrayList<>(); + list.add(processEntity); + when(processDaoMock.list(entity)).thenReturn(list); + + when(processDaoMock.getArtifact(anyObject())).thenReturn(processEntity); + + EnrichmentInfo info = new EnrichmentInfo(); + info.setVersion(version); + info.setKey(vspId); + processArtifactEnricher.enrich(info, null); + + ArgumentCaptor expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + Mockito.verify(enrichedServiceModelDaoMock, never()) + .storeExternalArtifact(expectedServiceArtifact.capture()); + } + private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) { ComponentEntity componentEntity = new ComponentEntity(); componentEntity.setId(componentId); @@ -82,5 +234,5 @@ public class ProcessArtifactEnricherTest { byte[] mibBytes = FileUtils.readViaInputStream(this.getClass().getResource(fileName), stream -> FileUtils.toByteArray(stream)); return ByteBuffer.wrap(mibBytes); - }*/ + } } -- cgit 1.2.3-korg