diff options
author | mojahidi <mojahidul.islam@amdocs.com> | 2017-12-28 18:33:00 +0530 |
---|---|---|
committer | Avi Gaffa <avi.gaffa@amdocs.com> | 2018-01-02 15:20:27 +0000 |
commit | 9d79007d2b36d5ae4a03581eeca1fcf6232b3b09 (patch) | |
tree | 0638ab46c050e901995e03dcefe5d4c0314ec95d /openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test | |
parent | b38f18bb99a603012ec406053531c45fb4643d62 (diff) |
fix MIB assignment
Assign mib file to all of the components from the same VFC type
Change-Id: Ia6a1a5a08b7383ec64ace085193b0c8daa399c7f
Issue-ID: SDC-811
Signed-off-by: talio <tali.orenbach@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test')
4 files changed, 173 insertions, 23 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 index c01f986ab1..65444b9c46 100644 --- 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 @@ -20,6 +20,7 @@ package org.openecomp.sdc.enrichment.impl.external.artifact; +import org.apache.commons.collections4.CollectionUtils; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; @@ -32,7 +33,11 @@ import org.openecomp.core.model.types.ServiceArtifact; import org.openecomp.core.utilities.file.FileUtils; import org.openecomp.sdc.enrichment.EnrichmentInfo; import org.openecomp.sdc.tosca.datatypes.ToscaNodeType; +import org.openecomp.sdc.tosca.datatypes.ToscaServiceModel; +import org.openecomp.sdc.tosca.datatypes.model.ServiceTemplate; import org.openecomp.sdc.tosca.services.DataModelUtil; +import org.openecomp.sdc.tosca.services.ToscaUtil; +import org.openecomp.sdc.tosca.services.YamlUtil; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentArtifactDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.ComponentDao; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; @@ -43,10 +48,18 @@ import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; import java.io.File; +import java.io.IOException; import java.nio.ByteBuffer; import java.util.ArrayList; -import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; +import java.util.stream.Stream; import static org.mockito.Matchers.anyObject; import static org.mockito.Mockito.atLeastOnce; @@ -73,20 +86,23 @@ public class MonitoringMibEnricherTest { @Test public void testEnrichComponent() throws Exception { String vspId = "123"; - String componentId = "1111111111"; + String componentId = "1"; 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); - + ComponentEntity componentEntity = getComponentEntity(vspId, version, componentId, vspId + + "enrichMib_server"); + setMockToEnrichComponent(vspId, version, componentId); String componentName = componentEntity.getComponentCompositionData().getName(); String unifiedComponentName = ToscaNodeType.ABSTRACT_NODE_TYPE_PREFIX + DataModelUtil.getNamespaceSuffix(componentName); + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = ArgumentCaptor.forClass(ServiceArtifact.class); + monitoringMibEnricher.enrichComponent(vspId, version, componentEntity, + Stream.of(unifiedComponentName).collect(Collectors.toSet())); + Mockito.verify(enrichedServiceModelDaoMock, atLeastOnce()) .storeExternalArtifact(expectedServiceArtifact.capture()); Assert.assertEquals(expectedServiceArtifact.getValue().getName() @@ -98,7 +114,7 @@ public class MonitoringMibEnricherTest { } @Test - public void testEnrich() throws Exception { + public void testEnrichmentOfTwoComponentsFromSameType() throws IOException { EnrichmentInfo enrichmentInfo = new EnrichmentInfo(); Version version = new Version(); version.setMajor(1); @@ -106,24 +122,43 @@ public class MonitoringMibEnricherTest { String vspId = "123"; enrichmentInfo.setKey(vspId); enrichmentInfo.setVersion(version); - String componentId1 = "1111111111"; - String componentId2 = "2222222222"; + String componentId1 = "1"; + String componentId2 = "2"; + String abstType = "org.openecomp.resource.abstract.nodes.pd_server"; + String abstType1 = "org.openecomp.resource.abstract.nodes.pd_server_1"; + + List<ComponentEntity> returnedComponents = new ArrayList<>(); + returnedComponents.add(getComponentEntity(vspId, version, componentId1, + "pd_server")); + returnedComponents.add(getComponentEntity(vspId, version, componentId2, + "pd_server")); + Mockito.when(componentDaoMock.list(anyObject())) + .thenReturn(returnedComponents); + setMockToEnrichComponent(vspId, version, componentId1); + ToscaServiceModel mockServiceModel = + getMockServiceModel("/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType"); - Collection<ComponentEntity> returnedComponents = new ArrayList<>(); - returnedComponents.add(getComponentEntity(vspId, version, componentId1)); - returnedComponents.add(getComponentEntity(vspId, version, componentId2)); + ArgumentCaptor<ServiceArtifact> expectedServiceArtifact = + ArgumentCaptor.forClass(ServiceArtifact.class); + monitoringMibEnricher.enrich(enrichmentInfo, mockServiceModel); - Mockito.when(componentDaoMock.list(anyObject())) - .thenReturn(returnedComponents); - setMockToEnrichComponent(vspId, componentId1, version); + Mockito.verify(enrichedServiceModelDaoMock, times(24)) + .storeExternalArtifact(expectedServiceArtifact.capture()); + + Set<String> prefixes = getAllMibDirectoryPrefixes(expectedServiceArtifact.getAllValues()); - monitoringMibEnricher.enrich(enrichmentInfo); - Mockito.verify(enrichedServiceModelDaoMock, times(12)).storeExternalArtifact(anyObject()); + validateExpectedAbstractTypes(Stream.of(abstType, abstType1).collect(Collectors.toSet()), prefixes); + } + private void validateExpectedAbstractTypes(Set<String> expectedAbstractTypes, + Set<String> prefixes) { + for(String abstType : expectedAbstractTypes){ + Assert.assertTrue(prefixes.contains(abstType)); + } } - private void setMockToEnrichComponent(String vspId, String componentId, Version version) { + private void setMockToEnrichComponent(String vspId, Version version, String componentId) { ComponentMonitoringUploadEntity returnedArtifact = new ComponentMonitoringUploadEntity(); returnedArtifact.setVspId(vspId); returnedArtifact.setVersion(version); @@ -137,16 +172,18 @@ public class MonitoringMibEnricherTest { Mockito.doNothing().when(enrichedServiceModelDaoMock).storeExternalArtifact(anyObject()); } - private ComponentEntity getComponentEntity(String vspId, Version version, String componentId) { + private ComponentEntity getComponentEntity(String vspId, + Version version, + String componentId, + String componentNameSuffix) { 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" + + " \"name\": \"org.openecomp.resource.vfc.nodes.heat." + componentNameSuffix + "\",\n" + + " \"displayName\": \"" + componentNameSuffix + "\"\n" + "}"; componentEntity.setCompositionData(compositionData); return componentEntity; @@ -154,8 +191,42 @@ public class MonitoringMibEnricherTest { private ByteBuffer getMibByteBuffer(String fileName) { byte[] mibBytes = FileUtils.readViaInputStream(this.getClass().getResource(fileName), - stream -> FileUtils.toByteArray(stream)); + FileUtils::toByteArray); return ByteBuffer.wrap(mibBytes); } + private ToscaServiceModel getMockServiceModel(String serviceTemplatesDirectory) + throws IOException { + File directory = new File(this.getClass().getResource(serviceTemplatesDirectory).getFile()); + ToscaServiceModel serviceModel = new ToscaServiceModel(); + Map<String, ServiceTemplate> serviceTemplates = new HashMap<>(); + + for (final File serviceTemplateFile : directory.listFiles()) { + byte[] content = FileUtils + .readViaInputStream(this.getClass().getResource(serviceTemplatesDirectory + File + .separator + serviceTemplateFile.getName()), + FileUtils::toByteArray); + ServiceTemplate serviceTemplate = + new YamlUtil().yamlToObject(new String(content), ServiceTemplate.class); + serviceTemplates.put(ToscaUtil.getServiceTemplateFileName(serviceTemplate), serviceTemplate); + } + + serviceModel.setServiceTemplates(serviceTemplates); + return serviceModel; + } + + private Set<String> getAllMibDirectoryPrefixes(List<ServiceArtifact> serviceArtifacts) { + if(CollectionUtils.isEmpty(serviceArtifacts)){ + return new HashSet<>(); + } + + Set<String> prefixes = new HashSet<>(); + for(ServiceArtifact serviceArtifact : serviceArtifacts){ + String absolutePath = serviceArtifact.getName(); + prefixes.add(absolutePath.split(Pattern.quote(File.separator))[0]); + } + + return prefixes; + } + } diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml new file mode 100644 index 0000000000..afd5b4afd0 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/MainServiceTemplate.yaml @@ -0,0 +1,39 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Main +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + pd_flavor_name: + type: string + description: flavor name of PD instance + default: m3.xlarge + availabilityzone_name: + type: string + description: availabilityzone name + default: nova + + node_templates: + abstract_pd_server_0: + type: org.openecomp.resource.abstract.nodes.pd_server + directives: + - substitutable + properties: + service_template_filter: + substitute_service_template: Nested_pd_serverServiceTemplate.yaml + count: 1 + abstract_pd_server_1: + type: org.openecomp.resource.abstract.nodes.pd_server_1 + directives: + - substitutable + properties: + service_template_filter: + substitute_service_template: Nested_pd_1serverServiceTemplate.yaml + count: 1 diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml new file mode 100644 index 0000000000..1b8f9636ec --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_1serverServiceTemplate.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Nested_pd_1server +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.compute.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + index_value: + type: integer + description: Index value of this substitution service template runtime instance + required: false + default: 0 + constraints: + - greater_or_equal: 0 diff --git a/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml new file mode 100644 index 0000000000..61dae4b1fa --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-enrichment-lib/openecomp-sdc-enrichment-impl/src/test/resources/mock/enrichMib/toscaModel/twoAbstractNodesFromSameType/Nested_pd_serverServiceTemplate.yaml @@ -0,0 +1,20 @@ +tosca_definitions_version: tosca_simple_yaml_1_0_0 +metadata: + template_name: Nested_pd_server +imports: +- openecomp_heat_index: + file: openecomp-heat/_index.yml +- GlobalSubstitutionTypes: + file: GlobalSubstitutionTypesServiceTemplate.yaml +node_types: + org.openecomp.resource.vfc.compute.nodes.heat.pd_server: + derived_from: org.openecomp.resource.vfc.nodes.heat.nova.Server +topology_template: + inputs: + index_value: + type: integer + description: Index value of this substitution service template runtime instance + required: false + default: 0 + constraints: + - greater_or_equal: 0 |