diff options
author | 2018-06-04 11:26:54 +0530 | |
---|---|---|
committer | 2018-06-04 12:15:30 +0000 | |
commit | 74bc96a289f9bf54a010fa7b027b839ebebead4c (patch) | |
tree | 678a0aa45e2e57b063fa3b1e282b37a1dd0771da /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp | |
parent | 03205dad582ffa5db54187f451b9a29d3d0af386 (diff) |
Refactoring - TOSCA Consolidation Data handling
Tried to handle class members from within class instead of outside
Change-Id: Iee6b396562cdcbd1569dd6ce7b31a205e1de6257
Issue-ID: SDC-1330
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp')
2 files changed, 164 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java index ec65b43fef..fd96f93bb5 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java @@ -17,6 +17,7 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -35,6 +36,94 @@ public class EntityConsolidationDataTest { private static final String REQUIREMENT_ID_2 = "requirementId2"; @Test + public void testIsGetAttrOutFromEntityLegal() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap1.put("server_1_networkrole_1_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertTrue(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalNegative() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_0_networkrole_2_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_2_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + //entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test + public void testIsGetAttrOutFromEntityLegalMultiplePortWithDiffAttr() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put("server_networkrole_1_port", + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + ports.put("server_networkrole_2_port", + Arrays.asList("server_0_networkrole_2_port", "server_0_networkrole_2_port")); + + GetAttrFuncData getAttrFuncData = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData)); + getAttOutMap.put("server_0_networkrole_2_port", Collections.singletonList(getAttrFuncData)); + + GetAttrFuncData getAttrFuncData1 = new GetAttrFuncData("vmac_address", "accessIPv4"); + Map<String, List<GetAttrFuncData>> getAttOutMap1 = new HashMap<>(); + getAttOutMap.put("server_0_networkrole_1_port", Collections.singletonList(getAttrFuncData1)); + + + EntityConsolidationData entityConsolidationData = new EntityConsolidationData(); + entityConsolidationData.setNodesGetAttrOut(getAttOutMap); + + EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData(); + entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1); + + List<EntityConsolidationData> entityConsolidationDataList = + Arrays.asList(entityConsolidationData, entityConsolidationData1); + + Assert.assertFalse(entityConsolidationData + .isGetAttrOutFromEntityLegal(entityConsolidationDataList, ports)); + } + + @Test public void testAddNodesConnectedIn_SameNodeTemplateIds() { EntityConsolidationData consolidationData = new EntityConsolidationData(); Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java index 7a3c8fa526..6388620e7c 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java @@ -16,10 +16,16 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import java.util.Arrays; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Objects; import java.util.Set; +import org.apache.commons.collections4.MapUtils; import org.junit.Assert; import org.junit.Test; @@ -27,6 +33,75 @@ public class TypeComputeConsolidationDataTest { private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1"; private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2"; + private static final String SERVER_NETWORKROLE_1_PORT = "server_networkrole_1_port"; + private static final String SERVER_NETWORKROLE_2_PORT = "server_networkrole_2_port"; + + @Test + public void testCollectAllPortsOfEachTypeFromComputesNoPorts() { + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(Objects.nonNull(stringListMap) && MapUtils.isEmpty(stringListMap)); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputes() { + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + Map<String, List<String>> ports = new HashMap<>(); + ports.put(SERVER_NETWORKROLE_1_PORT, + Arrays.asList("server_0_networkrole_1_port", "server_1_networkrole_1_port")); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData.setPorts(ports); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(stringListMap.containsKey(SERVER_NETWORKROLE_1_PORT) + && stringListMap.get(SERVER_NETWORKROLE_1_PORT).size() == 2); + + } + + @Test + public void testCollectAllPortsOfEachTypeFromComputesWithMultipleCompute() { + Map<String, List<String>> ports = new HashMap<>(); + ports.put(SERVER_NETWORKROLE_1_PORT, + Arrays.asList("server_0_networkrole_1_port_1", "server_1_networkrole_1_port_2")); + + Map<String, List<String>> ports1 = new HashMap<>(); + ports1.put(SERVER_NETWORKROLE_2_PORT, + Arrays.asList("server_0_networkrole_2_port_1", "server_1_networkrole_2_port_2")); + + ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData.setPorts(ports); + + ComputeTemplateConsolidationData computeTemplateConsolidationData1 = new ComputeTemplateConsolidationData(); + computeTemplateConsolidationData1.setPorts(ports1); + + TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData(); + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type", + computeTemplateConsolidationData); + + typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type1", + computeTemplateConsolidationData1); + + Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes(); + Assert.assertTrue(stringListMap.size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_1_PORT).size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_1_PORT).contains("server_0_networkrole_1_port_1") + && stringListMap.get(SERVER_NETWORKROLE_1_PORT).contains("server_1_networkrole_1_port_2")); + + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_2_PORT).size() == 2); + Assert.assertTrue(stringListMap.get(SERVER_NETWORKROLE_2_PORT).contains("server_0_networkrole_2_port_1") + && stringListMap.get(SERVER_NETWORKROLE_2_PORT).contains("server_1_networkrole_2_port_2")); + } @Test public void testAddComputeTemplateConsolidationData() { |