diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test')
-rw-r--r-- | openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java | 160 |
1 files changed, 156 insertions, 4 deletions
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<ComponentEntity> componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection<ProcessEntity> 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<ServiceArtifact> 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<ComponentEntity> componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection<ProcessEntity> 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<ServiceArtifact> 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<ComponentEntity> componentList = new ArrayList<>(); + componentList.add(componentEntity); + when(componentDaoMock.list(anyObject())).thenReturn(componentList); + + Collection<ProcessEntity> 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<ServiceArtifact> 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); - }*/ + } } |