diff options
author | 2018-05-22 16:26:35 +0300 | |
---|---|---|
committer | 2018-05-31 11:49:42 +0000 | |
commit | ba61c887dbcb1b81e31e15b18a44f68ff344b2fb (patch) | |
tree | dd31ec8b358392c3309b680f045003d0350abf5b /openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org | |
parent | 5bf62dca8740c67fd7b7492874808fe152514fc3 (diff) |
TOSCA Consolidation Data - Refactoring Part 2
Refactor get Compute/Port/Nested/SubInterface
Consolidation Data APIs
Change-Id: Ibce3abcd766555fe0eeaaf2f728d3a384935877d
Issue-ID: SDC-1330
Signed-off-by: eleonorali <eleonoral@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org')
5 files changed, 525 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/ComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java new file mode 100644 index 0000000000..a92e298c0a --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java @@ -0,0 +1,111 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; + +import java.util.HashSet; +import java.util.Set; +import org.junit.Assert; +import org.junit.Test; + +public class ComputeConsolidationDataTest { + + private static final String SERVICE_TEMPLATE_FILE_NAME_1 = "serviceTemplateFileName1"; + private static final String SERVICE_TEMPLATE_FILE_NAME_2 = "serviceTemplateFileName2"; + private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1"; + private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2"; + private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1"; + private static final String COMPUTE_NODE_TYPE_2 = "computeNodeType2"; + + @Test + public void testAddComputeTemplateConsolidationData() { + ComputeConsolidationData consolidationData = new ComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + + Set<String> expectedServiceTemplateNames = new HashSet<>(); + expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + } + + @Test + public void testAddSameConsolidationDataTwice_noNewCreated() { + ComputeConsolidationData consolidationData = new ComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + consolidationData.getFileComputeConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1); + + Set<String> expectedServiceTemplateNames = new HashSet<>(); + expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + consolidationData.getFileComputeConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + } + + @Test + public void testAddDiffConsolidationData_SameServiceTemplate_DiffNodeTypes() { + ComputeConsolidationData consolidationData = new ComputeConsolidationData(); + + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + Set<String> expectedServiceTemplateNames = new HashSet<>(); + expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + } + + @Test + public void testAddDiffConsolidationData_DiffServiceTemplate() { + ComputeConsolidationData consolidationData = new ComputeConsolidationData(); + + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1, + COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + Set<String> expectedServiceTemplateNames = new HashSet<>(); + expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_1); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames); + + consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_2, + COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2); + expectedServiceTemplateNames.add(SERVICE_TEMPLATE_FILE_NAME_2); + checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_2, expectedServiceTemplateNames); + + } + + private void checkComputeConsolidationData(ComputeConsolidationData consolidationData, + String serviceTemplateFileName, Set<String> expectedServiceTemplateNames) { + + FileComputeConsolidationData fileComputeConsolidationData = consolidationData + .getFileComputeConsolidationData(serviceTemplateFileName); + Assert.assertNotNull(fileComputeConsolidationData); + checkGetAllServiceTemplateFileNames(consolidationData, expectedServiceTemplateNames); + } + + private void checkGetAllServiceTemplateFileNames(ComputeConsolidationData consolidationData, + Set<String> expectedServiceTemplateNames) { + Set<String> allServiceTemplateFileNames = consolidationData.getAllServiceTemplateFileNames(); + Assert.assertNotNull(allServiceTemplateFileNames); + Assert.assertEquals(allServiceTemplateFileNames.size(), expectedServiceTemplateNames.size()); + Assert.assertTrue(allServiceTemplateFileNames.containsAll(expectedServiceTemplateNames)); + } + + +} 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/ConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java new file mode 100644 index 0000000000..726a76c2d2 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ConsolidationDataTest.java @@ -0,0 +1,57 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; + +import java.util.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.openecomp.sdc.translator.services.heattotosca.ConsolidationEntityType; + +public class ConsolidationDataTest { + + private final ConsolidationData consolidationData = new ConsolidationData(); + + @Test + public void testGetConsolidationDataHandler() { + + checkHandlerIsValid(ConsolidationEntityType.COMPUTE, ComputeConsolidationDataHandler.class); + checkHandlerIsValid(ConsolidationEntityType.PORT, PortConsolidationDataHandler.class); + checkHandlerIsValid(ConsolidationEntityType.SUB_INTERFACE, SubInterfaceConsolidationDataHandler.class); + checkHandlerIsValid(ConsolidationEntityType.NESTED, NestedConsolidationDataHandler.class); + checkHandlerIsValid(ConsolidationEntityType.VFC_NESTED, NestedConsolidationDataHandler.class); + } + + @Test + public void testGetConsolidationDataHandler_Negative() { + checkHandlerNotExist(ConsolidationEntityType.OTHER); + checkHandlerNotExist(ConsolidationEntityType.VOLUME); + } + + private void checkHandlerIsValid(ConsolidationEntityType consolidationEntityType, Class cls) { + Optional<ConsolidationDataHandler> consolidationDataHandler = + consolidationData.getConsolidationDataHandler(consolidationEntityType); + Assert.assertTrue(consolidationDataHandler.isPresent()); + Assert.assertTrue(cls.isInstance(consolidationDataHandler.get())); + } + + private void checkHandlerNotExist(ConsolidationEntityType consolidationEntityType) { + Optional<ConsolidationDataHandler> consolidationDataHandler = + consolidationData.getConsolidationDataHandler(consolidationEntityType); + Assert.assertFalse(consolidationDataHandler.isPresent()); + } + +} 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 new file mode 100644 index 0000000000..ec65b43fef --- /dev/null +++ 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 @@ -0,0 +1,170 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Assert; +import org.junit.Test; + +import org.onap.sdc.tosca.datatypes.model.RequirementAssignment; + +@SuppressWarnings("Duplicates") +public class EntityConsolidationDataTest { + + private static final String NODE_TEMPLATE_ID_1 = "nodeTemplateId1"; + private static final String NODE_TEMPLATE_ID_2 = "nodeTemplateId2"; + private static final String REQUIREMENT_ID_1 = "requirementId1"; + private static final String REQUIREMENT_ID_2 = "requirementId2"; + + @Test + public void testAddNodesConnectedIn_SameNodeTemplateIds() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); + + addNodesConnectedIn(consolidationData,NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData); + + addNodesConnectedIn(consolidationData,NODE_TEMPLATE_ID_1, REQUIREMENT_ID_2); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2}); + checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData); + } + + @Test + public void testAddNodesConnectedIn_DiffNodeTemplateIds() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); + + addNodesConnectedIn(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData); + + addNodesConnectedIn(consolidationData, NODE_TEMPLATE_ID_2, REQUIREMENT_ID_2); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2}); + checkNodesConnected(consolidationData.getNodesConnectedIn(), expectedNodesConnectedData); + } + + @Test + public void testAddNodesConnectedOut_SameNodeTemplateIds() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); + + addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData); + + addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_2); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1, REQUIREMENT_ID_2}); + checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData); + } + + @Test + public void testAddNodesConnectedOut_DiffNodeTemplateIds() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + Map<String, String[]> expectedNodesConnectedData = new HashMap<>(); + + addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_1, REQUIREMENT_ID_1); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_1, new String[]{REQUIREMENT_ID_1}); + checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData); + + addNodesConnectedOut(consolidationData, NODE_TEMPLATE_ID_2, REQUIREMENT_ID_2); + expectedNodesConnectedData.put(NODE_TEMPLATE_ID_2, new String[]{REQUIREMENT_ID_2}); + checkNodesConnected(consolidationData.getNodesConnectedOut(), expectedNodesConnectedData); + } + + @Test + public void testAddOutputParamGetAttrIn() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1"); + + consolidationData.addOutputParamGetAttrIn(getAttrFuncData1); + List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn(); + Assert.assertEquals(1, outputParametersGetAttrIn.size()); + Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1)); + + GetAttrFuncData getAttrFuncData2 = createGetAttrFuncData("field2"); + consolidationData.addOutputParamGetAttrIn(getAttrFuncData2); + Assert.assertEquals(2,outputParametersGetAttrIn.size()); + Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1)); + Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData2)); + } + + @Test + public void testRemoveParamNameFromAttrFuncList() { + EntityConsolidationData consolidationData = new EntityConsolidationData(); + GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1"); + + consolidationData.addOutputParamGetAttrIn(getAttrFuncData1); + // verify that getAttrFuncData was added + List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn(); + Assert.assertEquals(1, outputParametersGetAttrIn.size()); + + consolidationData.removeParamNameFromAttrFuncList("field2"); + //verify that not existing getAttrFuncData parameter wasn't removed and no Exception + outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn(); + Assert.assertEquals(1, outputParametersGetAttrIn.size()); + + consolidationData.removeParamNameFromAttrFuncList("field1"); + //verify that existing getAttrFuncData parameter was removed + outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn(); + Assert.assertEquals(0, outputParametersGetAttrIn.size()); + } + + private GetAttrFuncData createGetAttrFuncData(String field) { + GetAttrFuncData getAttrFuncData = new GetAttrFuncData(); + getAttrFuncData.setFieldName(field); + getAttrFuncData.setAttributeName("attribute"); + return getAttrFuncData; + } + + private void checkNodesConnected(Map<String, List<RequirementAssignmentData>> actualNodesConnected, + Map<String, String[]> expectedNodesConnected) { + Assert.assertNotNull(actualNodesConnected); + + expectedNodesConnected.keySet().forEach(expectedNodeTemplateId -> { + Assert.assertTrue(actualNodesConnected.containsKey(expectedNodeTemplateId)); + Assert.assertEquals(expectedNodesConnected.size(), actualNodesConnected.size()); + + List<RequirementAssignmentData> actualRequirementAssignmentData = + actualNodesConnected.get(expectedNodeTemplateId); + List<String> expectedRequirementIdList = + Arrays.asList(expectedNodesConnected.get(expectedNodeTemplateId)); + Assert.assertEquals(expectedRequirementIdList.size(), actualRequirementAssignmentData.size()); + + actualRequirementAssignmentData.forEach(actualRequirementAssignment -> + Assert.assertTrue(expectedRequirementIdList + .contains(actualRequirementAssignment.getRequirementId()))); + }); + + } + + private void addNodesConnectedIn(EntityConsolidationData consolidationData, + String nodeTemplateId, String requirementId) { + RequirementAssignment requirementAssignment = new RequirementAssignment(); + consolidationData.addNodesConnectedIn(nodeTemplateId, requirementId, requirementAssignment); + } + + private void addNodesConnectedOut(EntityConsolidationData consolidationData, + String nodeTemplateId, String requirementId) { + RequirementAssignment requirementAssignment = new RequirementAssignment(); + consolidationData.addNodesConnectedOut(nodeTemplateId, requirementId, requirementAssignment); + } +} 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/FileComputeConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java new file mode 100644 index 0000000000..eab3bd25b1 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java @@ -0,0 +1,98 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Test; + +public class FileComputeConsolidationDataTest { + + private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1"; + private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2"; + private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1"; + private static final String COMPUTE_NODE_TYPE_2 = "computeNodeType2"; + + @Test + public void testAddComputeTemplateConsolidationData() { + FileComputeConsolidationData consolidationData = new FileComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + + Set<String> expectedComputeNodeTypes = new HashSet<>(); + expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1); + checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes); + } + + @Test + public void testAddSameConsolidationDataTwice_noNewCreated() { + FileComputeConsolidationData consolidationData = new FileComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + TypeComputeConsolidationData firstTypeComputeConsolidationData = + consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + TypeComputeConsolidationData secondTypeComputeConsolidationData = + consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1); + Assert.assertEquals(firstTypeComputeConsolidationData, secondTypeComputeConsolidationData); + } + + @Test + public void testAddDiffConsolidationData_DiffNodeType() { + FileComputeConsolidationData consolidationData = new FileComputeConsolidationData(); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + Set<String> expectedComputeNodeTypes = new HashSet<>(); + expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1); + checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2); + expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_2); + checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_2, expectedComputeNodeTypes); + } + + @Test + public void testAddDiffConsolidationData_SameNodeType_MultiNodeTemplateId() { + FileComputeConsolidationData consolidationData = new FileComputeConsolidationData(); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1); + Set<String> expectedComputeNodeTypes = new HashSet<>(); + expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1); + checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2); + checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes); + } + + private void checkComputeConsolidationData(FileComputeConsolidationData fileComputeConsolidationData, + String computeNodeType, Set<String> expectedComputeNodeTypes) { + TypeComputeConsolidationData typeComputeConsolidationData = + fileComputeConsolidationData.getTypeComputeConsolidationData(computeNodeType); + Assert.assertNotNull(typeComputeConsolidationData); + checkGetAllComputeTypes(fileComputeConsolidationData, expectedComputeNodeTypes); + } + + private void checkGetAllComputeTypes(FileComputeConsolidationData fileComputeConsolidationData, + Set<String> expectedComputeNodeTypes) { + Collection<String> allComputeTypes = fileComputeConsolidationData.getAllComputeTypes(); + Assert.assertNotNull(allComputeTypes); + Assert.assertEquals(allComputeTypes.size(), expectedComputeNodeTypes.size()); + Assert.assertTrue(allComputeTypes.containsAll(expectedComputeNodeTypes)); + } +} 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 new file mode 100644 index 0000000000..7a3c8fa526 --- /dev/null +++ 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 @@ -0,0 +1,89 @@ +/* + * Copyright © 2016-2018 European Support Limited + * + * 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. + */ + +package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.junit.Assert; +import org.junit.Test; + +public class TypeComputeConsolidationDataTest { + + private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1"; + private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2"; + + @Test + public void testAddComputeTemplateConsolidationData() { + TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + + Set<String> expectedNodeTemplateIds = new HashSet<>(); + expectedNodeTemplateIds.add(COMPUTE_NODE_TEMPLATE_ID_1); + verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_1, expectedNodeTemplateIds); + } + + @Test + public void testAddSameConsolidationDataTwice_noNewCreated() { + TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData(); + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + ComputeTemplateConsolidationData firstComputeTemplateConsolidationData = + consolidationData.getComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + + consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + ComputeTemplateConsolidationData secondComputeTemplateConsolidationData = + consolidationData.getComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + Assert.assertEquals(firstComputeTemplateConsolidationData, secondComputeTemplateConsolidationData); + } + + @Test + public void testAddDiffConsolidationData_DiffNodeTemplateId() { + TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData(); + + final ComputeTemplateConsolidationData firstComputeTemplateConsolidationData = consolidationData + .addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1); + Set<String> expectedNodeTemplateIds1 = new HashSet<>(); + expectedNodeTemplateIds1.add(COMPUTE_NODE_TEMPLATE_ID_1); + verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_1, expectedNodeTemplateIds1); + + final ComputeTemplateConsolidationData secondComputeTemplateConsolidationData = consolidationData + .addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_2); + Set<String> expectedNodeTemplateIds2 = new HashSet<>(); + expectedNodeTemplateIds2.add(COMPUTE_NODE_TEMPLATE_ID_2); + verifyComputeTemplateConsolidationData(consolidationData, COMPUTE_NODE_TEMPLATE_ID_2, expectedNodeTemplateIds2); + + Assert.assertNotEquals(firstComputeTemplateConsolidationData, secondComputeTemplateConsolidationData); + } + + private void verifyComputeTemplateConsolidationData(TypeComputeConsolidationData typeComputeConsolidationData, + String computeNodeTemplateId, Set<String> expectedComputeNodeTemplateIds) { + ComputeTemplateConsolidationData computeTemplateConsolidationData = + typeComputeConsolidationData.getComputeTemplateConsolidationData(computeNodeTemplateId); + Assert.assertNotNull(computeTemplateConsolidationData); + Assert.assertEquals(computeTemplateConsolidationData.getNodeTemplateId(), computeNodeTemplateId); + + verifyGetAllComputeNodeTemplateId(typeComputeConsolidationData, expectedComputeNodeTemplateIds); + } + + private void verifyGetAllComputeNodeTemplateId(TypeComputeConsolidationData typeComputeConsolidationData, + Set<String> expectedComputeNodeTemplateIds) { + Collection<String> allComputeNodeTemplateIds = typeComputeConsolidationData.getAllComputeNodeTemplateIds(); + Assert.assertNotNull(allComputeNodeTemplateIds); + Assert.assertTrue(allComputeNodeTemplateIds.containsAll(expectedComputeNodeTemplateIds)); + } +} |