diff options
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java')
1 files changed, 109 insertions, 26 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/ComputeTemplateConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java index 9f32aec8aa..36a0b7ec72 100644 --- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java @@ -16,10 +16,17 @@ package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; +import com.google.common.collect.Multimap; + +import java.util.AbstractMap; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import org.junit.Assert; import org.junit.Test; @@ -36,59 +43,67 @@ public class ComputeTemplateConsolidationDataTest { private static final String PORT_TYPE_2 = "portType2"; private static final String PORT_NODE_TEMPLATE_ID_1 = "portNodeTemplateId1"; private static final String PORT_NODE_TEMPLATE_ID_2 = "portNodeTemplateId2"; + private static final String PORT_NEUTRON = "port_neutron"; + private static final String PORT_NEUTRON_1 = "port_neutron_1"; + private static final String PORT_NEUTRON_2 = "port_neutron_2"; + private static final String PORT_NEUTRON_3 = "port_neutron_3"; + private ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData(); + + private Map<String, List<String>> mapToBeModified = new HashMap<String, List<String>>() { + { + put(PORT_NEUTRON, new ArrayList<>(Collections.singletonList(PORT_NEUTRON_3))); + } + }; - private final ComputeTemplateConsolidationData consolidationData - = new ComputeTemplateConsolidationData(); + private final ComputeTemplateConsolidationData consolidationData = new ComputeTemplateConsolidationData(); @Test public void testAddPort_SamePortType() { Map<String, String[]> expectedPorts = new HashMap<>(); - expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1}); + expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1}); addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_1, expectedPorts); - expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_2}); + expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_2}); addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_2, expectedPorts); } @Test public void testAddPort_DiffPortType() { Map<String, String[]> expectedPorts = new HashMap<>(); - expectedPorts.put(PORT_TYPE_1, new String[]{PORT_NODE_TEMPLATE_ID_1}); + expectedPorts.put(PORT_TYPE_1, new String[] {PORT_NODE_TEMPLATE_ID_1}); addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_1, expectedPorts); - expectedPorts.put(PORT_TYPE_2, new String[]{PORT_NODE_TEMPLATE_ID_2}); + expectedPorts.put(PORT_TYPE_2, new String[] {PORT_NODE_TEMPLATE_ID_2}); addAndCheckPorts(PORT_TYPE_2, PORT_NODE_TEMPLATE_ID_2, expectedPorts); } @Test public void testAddVolume_SameComputeNode() { Map<String, String[]> expectedVolumes = new HashMap<>(); - expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1}); addAndCheckVolume(REQUIREMENT_ID_1, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes); - expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2}); + expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1, REQUIREMENT_ID_2}); addAndCheckVolume(REQUIREMENT_ID_2, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes); } @Test public void testAddVolume_DiffComputeNode() { Map<String, String[]> expectedVolumes = new HashMap<>(); - expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_1, new String[] {REQUIREMENT_ID_1}); addAndCheckVolume(REQUIREMENT_ID_1, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes); - expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2}); + expectedVolumes.put(COMPUTE_NODE_TEMPLATE_ID_2, new String[] {REQUIREMENT_ID_2}); addAndCheckVolume(REQUIREMENT_ID_2, COMPUTE_NODE_TEMPLATE_ID_2, expectedVolumes); } - private void addAndCheckPorts(String portType, String portNodeTemplateId, - Map<String, String[]> expectedPorts) { + private void addAndCheckPorts(String portType, String portNodeTemplateId, Map<String, String[]> expectedPorts) { consolidationData.addPort(portType, portNodeTemplateId); checkPorts(consolidationData.getPorts(), expectedPorts); } - private void checkPorts(Map<String, List<String>> actualAllPorts, - Map<String, String[]> expectedAllPorts) { + private void checkPorts(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts) { Assert.assertNotNull(actualAllPorts); expectedAllPorts.keySet().forEach(expectedPortType -> { Assert.assertTrue(actualAllPorts.containsKey(expectedPortType)); @@ -97,39 +112,38 @@ public class ComputeTemplateConsolidationDataTest { }); } - private void checkPortsPerType(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts, - String expectedPortType) { + private void checkPortsPerType(Map<String, List<String>> actualAllPorts, Map<String, String[]> expectedAllPorts, + String expectedPortType) { List<String> actualPorts = actualAllPorts.get(expectedPortType); List<String> expectedPortList = Arrays.asList(expectedAllPorts.get(expectedPortType)); Assert.assertEquals(expectedPortList.size(), actualPorts.size()); - actualPorts.forEach(actualPort -> - Assert.assertTrue(expectedPortList.contains(actualPort))); + actualPorts.forEach(actualPort -> Assert.assertTrue(expectedPortList.contains(actualPort))); } private void addAndCheckVolume(String requirementId, String computeNodeTemplateId, - Map<String, String[]> expectedVolumes) { + Map<String, String[]> expectedVolumes) { RequirementAssignment requirementAssignment1 = createRequirement(computeNodeTemplateId); consolidationData.addVolume(requirementId, requirementAssignment1); checkVolumes(consolidationData.getVolumes(), expectedVolumes); } - private void checkVolumes(Map<String, List<RequirementAssignmentData>> actualVolumes, + private void checkVolumes(Multimap<String, RequirementAssignmentData> actualVolumes, Map<String, String[]> expectedVolumes) { Assert.assertNotNull(actualVolumes); expectedVolumes.keySet().forEach(nodeTemplateId -> { Assert.assertTrue(actualVolumes.containsKey(nodeTemplateId)); - Assert.assertEquals(expectedVolumes.size(), actualVolumes.size()); + Assert.assertEquals(expectedVolumes.size(), actualVolumes.keySet().size()); checkVolumesPerType(actualVolumes, expectedVolumes, nodeTemplateId); }); } - private void checkVolumesPerType(Map<String, List<RequirementAssignmentData>> - actualVolumes, Map<String, String[]> expectedVolumes, String nodeTemplateId) { - List<RequirementAssignmentData> actualRequirementAssignmentData = actualVolumes.get(nodeTemplateId); + private void checkVolumesPerType(Multimap<String, RequirementAssignmentData> actualVolumes, + Map<String, String[]> expectedVolumes, String nodeTemplateId) { + Collection<RequirementAssignmentData> actualRequirementAssignmentData = actualVolumes.get(nodeTemplateId); List<String> requirementIds = Arrays.asList(expectedVolumes.get(nodeTemplateId)); Assert.assertEquals(requirementIds.size(), actualRequirementAssignmentData.size()); - actualRequirementAssignmentData.forEach(actualRequirementAssignment -> - Assert.assertTrue(requirementIds.contains(actualRequirementAssignment.getRequirementId()))); + actualRequirementAssignmentData.forEach(actualRequirementAssignment -> Assert.assertTrue( + requirementIds.contains(actualRequirementAssignment.getRequirementId()))); } private RequirementAssignment createRequirement(String nodeTemplateId) { @@ -137,4 +151,73 @@ public class ComputeTemplateConsolidationDataTest { requirementAssignment.setNode(nodeTemplateId); return requirementAssignment; } + + @Test + public void collectAllPortsOfEachTypeFromComputeKeyPresent() { + Map<String, List<String>> portMap = new HashMap<>(); + portMap.put(PORT_NEUTRON, new ArrayList<>(Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2))); + + computeTemplateConsolidationData.setPorts(portMap); + + computeTemplateConsolidationData.collectAllPortsOfEachTypeFromCompute(mapToBeModified); + + Assert.assertTrue(mapToBeModified.size() == 1 && mapToBeModified.get(PORT_NEUTRON).size() == 3); + Assert.assertTrue(mapToBeModified.get(PORT_NEUTRON).containsAll( + Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2, PORT_NEUTRON_3))); + + } + + @Test + public void collectAllPortsOfEachTypeFromComputeKeyAbsent() { + Map<String, List<String>> portMap = new HashMap<>(); + portMap.put(PORT_NEUTRON, new ArrayList<>(Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2))); + + computeTemplateConsolidationData.setPorts(portMap); + + Map<String, List<String>> mapToBeModified = new HashMap<>(); + + computeTemplateConsolidationData.collectAllPortsOfEachTypeFromCompute(mapToBeModified); + + Assert.assertTrue(mapToBeModified.size() == 1 && Objects.nonNull(mapToBeModified.get(PORT_NEUTRON)) + && mapToBeModified.get(PORT_NEUTRON).size() == 2); + Assert.assertTrue(mapToBeModified.get(PORT_NEUTRON).containsAll( + Arrays.asList(PORT_NEUTRON_1, PORT_NEUTRON_2))); + } + + @Test + public void isNumberOfPortFromEachTypeLegal_Empty() { + Assert.assertTrue(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal()); + } + + @Test + public void isNumberOfPortFromEachTypeLegal_OnePort() { + computeTemplateConsolidationData.setPorts(mapToBeModified); + + Assert.assertTrue(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal()); + } + + @Test + public void isNumberOfPortFromEachTypeLegal_MultiplePorts() { + mapToBeModified.get(PORT_NEUTRON).addAll(Collections.singletonList("port_neutron_4")); + computeTemplateConsolidationData.setPorts(mapToBeModified); + + Assert.assertFalse(computeTemplateConsolidationData.isNumberOfPortFromEachTypeLegal()); + } + + @Test + public void getPortsIdsAndSizeEmpty() { + Assert.assertNotNull(computeTemplateConsolidationData.getPortsIds()); + Assert.assertEquals(0, computeTemplateConsolidationData.getNumberOfPorts()); + } + + @Test + public void getPortsIdsWithData() { + computeTemplateConsolidationData.setPorts(mapToBeModified); + Map.Entry<String, String> entry = new AbstractMap.SimpleEntry<>("port_neutron", PORT_NEUTRON_3); + + Assert.assertNotNull(computeTemplateConsolidationData.getPortsIds()); + Assert.assertEquals(1, computeTemplateConsolidationData.getNumberOfPorts()); + Assert.assertEquals("port_neutron", + computeTemplateConsolidationData.getPorts().entrySet().stream().findFirst().get().getKey()); + } } |