diff options
author | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
---|---|---|
committer | AviZi <avi.ziv@amdocs.com> | 2017-06-09 02:39:56 +0300 |
commit | 280f8015d06af1f41a3ef12e8300801c7a5e0d54 (patch) | |
tree | 9c1d3978c04cd28068f02073038c936bb49ca9e0 /openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact | |
parent | fd3821dad11780d33c5373d74c957c442489945e (diff) |
[SDC-29] Amdocs OnBoard 1707 initial commit.
Change-Id: Ie4d12a3f574008b792899b368a0902a8b46b5370
Signed-off-by: AviZi <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact')
2 files changed, 295 insertions, 0 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/MonitoringMibEnricherTest.java b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java new file mode 100644 index 0000000000..7a16b6945d --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/MonitoringMibEnricherTest.java @@ -0,0 +1,167 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.sdc.enrichment.impl.external.artifact; + +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.enrichment.types.ArtifactType; +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.MibDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.MibEntity; +import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; +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.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Optional; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.times; + + +/** + * @author shiria + * @since November 06, 2016. + */ + +public class MonitoringMibEnricherTest { + @Mock + private MibDao mibDaoMock; + @Mock + private EnrichedServiceModelDao enrichedServiceModelDaoMock; + @Mock + private VendorSoftwareProductDao vendorSoftwareProductDaoMock; + @Mock + private ComponentDao componentDaoMock; + + @InjectMocks + private MonitoringMibEnricher monitoringMibEnricher; + + + @BeforeMethod(alwaysRun = true) + public void injectDoubles() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testEnrichComponent() throws Exception { + String vspId = "123"; + String componentId = "1111111111"; + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); + setMockToEnrichComponent(vspId, componentId, version); + monitoringMibEnricher.enrichComponent(componentEntity, vspId, version); + + String componentName = componentEntity.getComponentCompositionData().getName(); + + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + Mockito.verify(enrichedServiceModelDaoMock, atLeastOnce()) + .storeExternalArtifact(expectedServiceArtifact.capture()); + Assert + .assertEquals(expectedServiceArtifact.getValue().getName().startsWith(componentName), true); + Assert.assertEquals(expectedServiceArtifact.getValue().getName(), + componentName + File.separator + ArtifactCategory.DEPLOYMENT.getDisplayName() + + File.separator + ArtifactType.SNMP_POLL + File.separator + "mib1.yml"); + + } + + @Test + public void testEnrich() throws Exception { + EnrichmentInfo enrichmentInfo = new EnrichmentInfo(); + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + String vspId = "123"; + enrichmentInfo.setKey(vspId); + enrichmentInfo.setVersion(version); + String componentId1 = "1111111111"; + String componentId2 = "2222222222"; + + + Collection<ComponentEntity> returnedComponents = new ArrayList<>(); + returnedComponents.add(getComponentEntity(vspId, version, componentId1)); + returnedComponents.add(getComponentEntity(vspId, version, componentId2)); + + Mockito.when(componentDaoMock.list(anyObject())) + .thenReturn(returnedComponents); + setMockToEnrichComponent(vspId, componentId1, version); + + monitoringMibEnricher.enrich(enrichmentInfo); + Mockito.verify(enrichedServiceModelDaoMock, times(8)).storeExternalArtifact(anyObject()); + + } + + private void setMockToEnrichComponent(String vspId, String componentId, Version version) { + MibEntity returnedArtifact = new MibEntity(); + returnedArtifact.setVspId(vspId); + returnedArtifact.setVersion(version); + returnedArtifact.setComponentId(componentId); + returnedArtifact.setType(ArtifactType.SNMP_POLL); + returnedArtifact.setArtifactName("mib.zip"); + returnedArtifact.setArtifact(getMibByteBuffer("/mock/enrichMib/MIB.zip")); + + Mockito.when(mibDaoMock.getByType(anyObject())) + .thenReturn(Optional.of(returnedArtifact)); + Mockito.doNothing().when(enrichedServiceModelDaoMock).storeExternalArtifact(anyObject()); + } + + private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) { + ComponentEntity componentEntity = new ComponentEntity(); + componentEntity.setId(componentId); + componentEntity.setVspId(vspId); + componentEntity.setVersion(version); + + String componentName = vspId + "enrichMib_server"; + String compositionData = "{\n" + + " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentName + "\",\n" + + " \"displayName\": \"" + componentName + "\"\n" + + "}"; + componentEntity.setCompositionData(compositionData); + return componentEntity; + } + + private ByteBuffer getMibByteBuffer(String fileName) { + InputStream mibFile = FileUtils.getFileInputStream(this.getClass().getResource(fileName)); + byte[] mibBytes = FileUtils.toByteArray(mibFile); + return ByteBuffer.wrap(mibBytes); + } + +} 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 new file mode 100644 index 0000000000..cfb241483a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/java/org/openecomp/sdc/enrichment/impl/external/artifact/ProcessArtifactEnricherTest.java @@ -0,0 +1,128 @@ +package org.openecomp.sdc.enrichment.impl.external.artifact; + +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.ProcessDao; +import org.openecomp.sdc.vendorsoftwareproduct.dao.VendorSoftwareProductDao; +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.io.InputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.Collection; + +import static org.mockito.Matchers.anyObject; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.when; + +public class ProcessArtifactEnricherTest { + @Mock + ProcessDao processDaoMock; + @Mock + EnrichedServiceModelDao enrichedServiceModelDaoMock; + @Mock + VendorSoftwareProductDao vendorSoftwareProductDaoMock; + + @InjectMocks + ProcessArtifactEnricher processArtifactEnricher; + + + @BeforeMethod(alwaysRun = true) + public void injectDoubles() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testEnrichComponent() throws Exception { + String vspId = "123"; + String componentId = "1111111111"; + Version version = new Version(); + version.setMajor(1); + version.setMinor(0); + + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId); + setMockToEnrichComponent(vspId, componentId, version); + + 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); + + Collection<ComponentEntity> componentList = new ArrayList<ComponentEntity>(); + componentList.add(componentEntity); + when(vendorSoftwareProductDaoMock.listComponents(vspId, version)).thenReturn(componentList); + + Collection<ProcessEntity> list = new ArrayList<ProcessEntity>(); + list.add(processEntity); + when(processDaoMock.list(entity)).thenReturn(list); + + EnrichmentInfo info = new EnrichmentInfo(); + info.setVersion(version); + info.setKey(vspId); + processArtifactEnricher.enrich(info); + + String componentName = componentEntity.getComponentCompositionData().getName(); + + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + Mockito.verify(enrichedServiceModelDaoMock, atLeastOnce()) + .storeExternalArtifact(expectedServiceArtifact.capture()); + Assert + .assertEquals(expectedServiceArtifact.getValue().getName().startsWith(componentName), true); + Assert.assertEquals(expectedServiceArtifact.getValue().getName(), + componentName + File.separator + ArtifactCategory.DEPLOYMENT.getDisplayName() + + File.separator + "Lifecycle Operations" + File.separator + "artifact_1kb.txt"); + + } + + private void setMockToEnrichComponent(String vspId, String componentId, Version version) { + ProcessEntity returnedArtifact = new ProcessEntity(); + returnedArtifact.setVspId(vspId); + returnedArtifact.setVersion(version); + returnedArtifact.setComponentId(componentId); + returnedArtifact.setArtifactName("artifact_1kb.txt"); + returnedArtifact.setArtifact(getMibByteBuffer("/mock/enrichProcess/artifact_1kb.txt")); + + Mockito.when(processDaoMock.get(anyObject())) + .thenReturn(returnedArtifact); + Mockito.doNothing().when(enrichedServiceModelDaoMock).storeExternalArtifact(anyObject()); + } + + private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) { + ComponentEntity componentEntity = new ComponentEntity(); + componentEntity.setId(componentId); + componentEntity.setVspId(vspId); + componentEntity.setVersion(version); + + String componentName = vspId + "enrichMib_server"; + String compositionData = "{\n" + + " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentName + "\",\n" + + " \"displayName\": \"" + componentName + "\"\n" + + "}"; + componentEntity.setCompositionData(compositionData); + return componentEntity; + } + + private ByteBuffer getMibByteBuffer(String fileName) { + InputStream mibFile = FileUtils.getFileInputStream(this.getClass().getResource(fileName)); + byte[] mibBytes = FileUtils.toByteArray(mibFile); + return ByteBuffer.wrap(mibBytes); + } +} |