summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib
diff options
context:
space:
mode:
authoreleonorali <eleonoral@amdocs.com>2018-06-14 14:00:40 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-06-27 08:38:58 +0000
commit0cc593ea8c181cfbcde343be45b8cf1cdd6ddbff (patch)
tree46a2c05db832b105559ae98ec998f26ff7d1877b /openecomp-be/lib
parentc928dd43210e96b4bbd5054d52a143778e43bf7a (diff)
TOSCA Consolidation Data - Refactoring Part 3
- Add Missing UTs for refactored code - Refactor APIs: - addVolumeToConsolidationData - addGroupIdToConsolidationData Change-Id: I83dedcbdf9715c6f72faa5fc242e76ea10efe386 Issue-ID: SDC-1330 Signed-off-by: eleonorali <eleonoral@amdocs.com>
Diffstat (limited to 'openecomp-be/lib')
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java35
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java172
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java31
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java14
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java227
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataTest.java153
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeTemplateConsolidationDataTest.java140
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationDataTest.java42
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FileComputeConsolidationDataTest.java144
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationDataTest.java102
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataTest.java225
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ServiceTemplateFileNameEnum.java7
-rw-r--r--openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/TypeComputeConsolidationDataTest.java59
13 files changed, 1112 insertions, 239 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
index dc2fc96169..8e319e96a0 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandler.java
@@ -94,26 +94,49 @@ public class ComputeConsolidationDataHandler implements ConsolidationDataHandler
}
/**
- * Add port to compute consolidation data entity base on given keys.s
+ * Add port to compute consolidation data entity base on given keys.
*
*/
public void addPortToConsolidationData(TranslateTo translateTo, String computeNodeType,
String computeNodeTemplateId, String portType, String portNodeTemplateId) {
- ComputeTemplateConsolidationData entityConsolidationData =
+ ComputeTemplateConsolidationData consolidationData =
getComputeTemplateConsolidationData(translateTo, computeNodeType, computeNodeTemplateId);
- entityConsolidationData.addPort(portType, portNodeTemplateId);
+ consolidationData.addPort(portType, portNodeTemplateId);
+ }
+
+ /**
+ * Add volume to consolidation data.
+ *
+ */
+ public void addVolumeToConsolidationData(TranslateTo translateTo, String computeNodeType,
+ String computeNodeTemplateId, String requirementId, RequirementAssignment requirementAssignment) {
+ ComputeTemplateConsolidationData consolidationData =
+ getComputeTemplateConsolidationData(translateTo, computeNodeType,
+ computeNodeTemplateId);
+ consolidationData.addVolume(requirementId, requirementAssignment);
+ }
+
+ /**
+ * Add group id information to consolidation data.
+ *
+ * @param translatedGroupId Group id of which compute node is a part
+ */
+
+ public void addGroupIdToConsolidationData(TranslateTo translateTo, String computeNodeType,
+ String computeNodeTemplateId, String translatedGroupId) {
+ ComputeTemplateConsolidationData consolidationData =
+ getComputeTemplateConsolidationData(translateTo, computeNodeType,
+ computeNodeTemplateId);
+ consolidationData.addGroupId(translatedGroupId);
}
private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
TranslateTo translateTo, String computeNodeType, String computeNodeTemplateId) {
-
ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
String serviceTemplateFileName = ToscaUtil.getServiceTemplateFileName(serviceTemplate);
return getComputeTemplateConsolidationData(serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
-
}
-
private ComputeTemplateConsolidationData getComputeTemplateConsolidationData(
String serviceTemplateFileName, String computeNodeType, String computeNodeTemplateId) {
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
index 7101037562..3987c54054 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/EntityConsolidationData.java
@@ -67,42 +67,42 @@ public class EntityConsolidationData {
}
/**
- * Gets group ids point to me.
- *
- * @return the group ids point to me
- */
+ * Gets group ids point to me.
+ *
+ * @return the group ids point to me
+ */
public List<String> getGroupIds() {
return groupIds;
}
/**
- * Sets group ids point to me.
- *
- * @param groupIds the group ids point to me
- */
+ * Sets group ids point to me.
+ *
+ * @param groupIds the group ids point to me
+ */
public void setGroupIds(List<String> groupIds) {
this.groupIds = groupIds;
}
/**
- * Sets node connected to me.
- *
- * @param nodesConnectedIn the node connected to me
- */
+ * Sets node connected to me.
+ *
+ * @param nodesConnectedIn the node connected to me
+ */
public void setNodesConnectedIn(Map<String, List<RequirementAssignmentData>> nodesConnectedIn) {
this.nodesConnectedIn = nodesConnectedIn;
}
/**
- * Add nodeConnectedIn.
- *
- * @param nodeTemplateId the node template id which has connection to me
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
+ * Add node connected to me.
+ *
+ * @param nodeTemplateId the node template id which has connection to me
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
public void addNodesConnectedIn(String nodeTemplateId, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
if (this.nodesConnectedIn == null) {
this.nodesConnectedIn = new HashMap<>();
@@ -114,42 +114,42 @@ public class EntityConsolidationData {
}
/**
- * Gets node connected to me.
- *
- * @return the node connected to me
- */
+ * Gets node connected to me.
+ *
+ * @return the node connected to me
+ */
public Map<String, List<RequirementAssignmentData>> getNodesConnectedIn() {
return nodesConnectedIn;
}
/**
- * Gets node connected from me.
- *
- * @return the node connected from me
- */
+ * Gets node connected from me.
+ *
+ * @return the node connected from me
+ */
public Map<String, List<RequirementAssignmentData>> getNodesConnectedOut() {
return nodesConnectedOut;
}
/**
- * Sets node connected from me.
- *
- * @param nodesConnectedOut the node connected from me
- */
+ * Sets node connected from me.
+ *
+ * @param nodesConnectedOut the node connected from me
+ */
public void setNodesConnectedOut(Map<String, List<RequirementAssignmentData>> nodesConnectedOut) {
this.nodesConnectedOut = nodesConnectedOut;
}
/**
- * Add nodeConnectedOut.
- *
- * @param nodeTemplateId the node template id which is connected from me
- * @param requirementId the requirement id
- * @param requirementAssignment the requirement assignment
- */
+ * Add nodeConnectedOut.
+ *
+ * @param nodeTemplateId the node template id which is connected from me
+ * @param requirementId the requirement id
+ * @param requirementAssignment the requirement assignment
+ */
public void addNodesConnectedOut(String nodeTemplateId, String requirementId,
- RequirementAssignment requirementAssignment) {
+ RequirementAssignment requirementAssignment) {
if (this.nodesConnectedOut == null) {
this.nodesConnectedOut = new HashMap<>();
@@ -161,29 +161,29 @@ public class EntityConsolidationData {
}
/**
- * Gets nodes get attr in.
- *
- * @return the get attr in
- */
+ * Gets nodes get attr in.
+ *
+ * @return the get attr in
+ */
public Map<String, List<GetAttrFuncData>> getNodesGetAttrIn() {
return nodesGetAttrIn;
}
/**
- * Sets nodes get attr in.
- *
- * @param nodesGetAttrIn the get attr in
- */
+ * Sets nodes get attr in.
+ *
+ * @param nodesGetAttrIn the get attr in
+ */
public void setNodesGetAttrIn(Map<String, List<GetAttrFuncData>> nodesGetAttrIn) {
this.nodesGetAttrIn = nodesGetAttrIn;
}
/**
- * Add nodes get attr in data.
- *
- * @param nodeTemplateId the node template id
- * @param getAttrFuncData get attr data
- */
+ * Add nodes get attr in data.
+ *
+ * @param nodeTemplateId the node template id
+ * @param getAttrFuncData get attr data
+ */
public void addNodesGetAttrIn(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
if (nodesGetAttrIn == null) {
@@ -195,28 +195,28 @@ public class EntityConsolidationData {
}
/**
- * Gets output parameters get attr from me.
- *
- * @return the get attr from me
- */
+ * Gets output parameters get attr from me.
+ *
+ * @return the get attr from me
+ */
public List<GetAttrFuncData> getOutputParametersGetAttrIn() {
return outputParametersGetAttrIn;
}
/**
- * Sets output parameters get attr from me.
- *
- * @param outputParametersGetAttrIn the output parameters get attr from me
- */
+ * Sets output parameters get attr from me.
+ *
+ * @param outputParametersGetAttrIn the output parameters get attr from me
+ */
public void setOutputParametersGetAttrIn(List<GetAttrFuncData> outputParametersGetAttrIn) {
this.outputParametersGetAttrIn = outputParametersGetAttrIn;
}
/**
- * Add output parameters get attr data.
- *
- * @param getAttrFuncData get attr data
- */
+ * Add output parameters get attr data.
+ *
+ * @param getAttrFuncData get attr data
+ */
public void addOutputParamGetAttrIn(GetAttrFuncData getAttrFuncData) {
if (outputParametersGetAttrIn == null) {
@@ -227,29 +227,29 @@ public class EntityConsolidationData {
}
/**
- * Gets nodes get attr out.
- *
- * @return the get attr out
- */
+ * Gets nodes get attr out.
+ *
+ * @return the get attr out
+ */
public Map<String, List<GetAttrFuncData>> getNodesGetAttrOut() {
return nodesGetAttrOut;
}
/**
- * Sets nodes get attr out.
- *
- * @param nodesGetAttrOut the get attr out
- */
+ * Sets nodes get attr out.
+ *
+ * @param nodesGetAttrOut the get attr out
+ */
public void setNodesGetAttrOut(Map<String, List<GetAttrFuncData>> nodesGetAttrOut) {
this.nodesGetAttrOut = nodesGetAttrOut;
}
/**
- * Add nodes get attr out data.
- *
- * @param nodeTemplateId the node template id
- * @param getAttrFuncData get attr data
- */
+ * Add nodes get attr out data.
+ *
+ * @param nodeTemplateId the node template id
+ * @param getAttrFuncData get attr data
+ */
public void addNodesGetAttrOut(String nodeTemplateId, GetAttrFuncData getAttrFuncData) {
if (nodesGetAttrOut == null) {
@@ -277,10 +277,8 @@ public class EntityConsolidationData {
* @return true in case get attr list same for all port types.
* otherwise return false
*/
- public boolean isGetAttrOutFromEntityLegal(
- Collection<? extends EntityConsolidationData> entityConsolidationDataList,
- Map<String, List<String>> portTypeToIds) {
-
+ public boolean isGetAttrOutFromEntityLegal(Collection<? extends EntityConsolidationData>
+ entityConsolidationDataList, Map<String, List<String>> portTypeToIds) {
for (String portType : portTypeToIds.keySet()) {
Set<GetAttrFuncData> startingGetAttrFunc =
getEntityGetAttrFuncAsSet(portType);
@@ -293,7 +291,6 @@ public class EntityConsolidationData {
}
}
}
-
return true;
}
@@ -307,4 +304,17 @@ public class EntityConsolidationData {
.flatMap(entry -> entry.getValue().stream())
.collect(Collectors.toSet());
}
+
+ /**
+ * Add group id information to consolidation data.
+ *
+ * @param groupId Group id of which compute node is a part
+ */
+
+ void addGroupId(String groupId) {
+ if (groupIds == null) {
+ groupIds = new ArrayList<>();
+ }
+ groupIds.add(groupId);
+ }
}
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
index 0d8a07a41f..b766f30388 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtil.java
@@ -16,7 +16,6 @@
package org.openecomp.sdc.translator.services.heattotosca;
-import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
@@ -36,6 +35,7 @@ import org.openecomp.sdc.tosca.services.ToscaUtil;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationData;
+import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationDataHandler;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationData;
import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ConsolidationDataHandler;
@@ -283,21 +283,6 @@ public class ConsolidationDataUtil {
}
/**
- * Update group id information in consolidation data.
- *
- * @param entityConsolidationData Entity consolidation data (Port/Compute)
- * @param translatedGroupId Group id of which compute node is a part
- */
- public static void updateGroupIdInConsolidationData(EntityConsolidationData
- entityConsolidationData,
- String translatedGroupId) {
- if (entityConsolidationData.getGroupIds() == null) {
- entityConsolidationData.setGroupIds(new ArrayList<>());
- }
- entityConsolidationData.getGroupIds().add(translatedGroupId);
- }
-
- /**
* Update volume information in consolidation data.
*
* @param translateTo {@link TranslateTo} object
@@ -309,17 +294,13 @@ public class ConsolidationDataUtil {
String computeType,
String computeNodeTemplateId,
String requirementId,
- RequirementAssignment
- requirementAssignment) {
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData =
- getComputeTemplateConsolidationData(translationContext, serviceTemplate, computeType,
- computeNodeTemplateId);
- computeTemplateConsolidationData.addVolume(requirementId, requirementAssignment);
+ RequirementAssignment requirementAssignment) {
+ ComputeConsolidationDataHandler handler =
+ translateTo.getContext().getComputeConsolidationDataHandler();
+ handler.addVolumeToConsolidationData(
+ translateTo, computeType, computeNodeTemplateId, requirementId, requirementAssignment);
}
-
/**
* Update port in consolidation data.
*
diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
index d6f0d7a2b8..e70ca5f2f9 100644
--- a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
+++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/main/java/org/openecomp/sdc/translator/services/heattotosca/impl/resourcetranslation/ResourceTranslationNovaServerImpl.java
@@ -55,7 +55,7 @@ import org.openecomp.sdc.translator.datatypes.heattotosca.PropertyRegexMatcher;
import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslatedHeatResource;
-import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeTemplateConsolidationData;
+import org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation.ComputeConsolidationDataHandler;
import org.openecomp.sdc.translator.services.heattotosca.ConsolidationDataUtil;
import org.openecomp.sdc.translator.services.heattotosca.Constants;
import org.openecomp.sdc.translator.services.heattotosca.HeatToToscaUtil;
@@ -167,14 +167,10 @@ public class ResourceTranslationNovaServerImpl extends ResourceTranslationBase {
}
private void updateComputeConsolidationDataGroup(TranslateTo translateTo,
- NodeTemplate novaNodeTemplate,
- String groupId) {
- TranslationContext translationContext = translateTo.getContext();
- ServiceTemplate serviceTemplate = translateTo.getServiceTemplate();
- ComputeTemplateConsolidationData computeTemplateConsolidationData = ConsolidationDataUtil
- .getComputeTemplateConsolidationData(translationContext, serviceTemplate,
- novaNodeTemplate.getType(), translateTo.getTranslatedId());
- ConsolidationDataUtil.updateGroupIdInConsolidationData(computeTemplateConsolidationData, groupId);
+ NodeTemplate novaNodeTemplate, String groupId) {
+ ComputeConsolidationDataHandler handler = translateTo.getContext().getComputeConsolidationDataHandler();
+ handler.addGroupIdToConsolidationData(translateTo,novaNodeTemplate.getType(),
+ translateTo.getTranslatedId(), groupId);
}
private boolean isHintOfTypeNovaServerGroup(HeatOrchestrationTemplate heatOrchestrationTemplate,
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/ComputeConsolidationDataHandlerTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ComputeConsolidationDataHandlerTest.java
new file mode 100644
index 0000000000..6df781e375
--- /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/ComputeConsolidationDataHandlerTest.java
@@ -0,0 +1,227 @@
+/*
+ * 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.HashMap;
+import java.util.Map;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+
+import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
+import org.onap.sdc.tosca.datatypes.model.RequirementAssignment;
+import org.onap.sdc.tosca.datatypes.model.ServiceTemplate;
+import org.onap.sdc.tosca.datatypes.model.TopologyTemplate;
+import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
+import org.openecomp.sdc.tosca.services.ToscaConstants;
+import org.openecomp.sdc.translator.datatypes.heattotosca.to.TranslateTo;
+
+
+public class ComputeConsolidationDataHandlerTest {
+
+ private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
+ private static final String COMPUTE_NODE_TYPE_1 = "computeNodeType1";
+
+ private static final String PORT_NODE_TYPE_1 = "portType1";
+ private static final String PORT_NODE_TEMPLATE_ID_1 = "portNodeTemplateId1";
+
+ private static final String GROUP_ID = "groupId";
+ private static final String REQUIREMENT_ID = "requirementId";
+ private static final String SERVICE_FILE_NAME_PREFIX = "Main";
+ private static final String SERVICE_FILE_NAME = SERVICE_FILE_NAME_PREFIX + "ServiceTemplate.yaml";
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ consolidationDataHandler = new ComputeConsolidationDataHandler(computeConsolidationData);
+ }
+
+ @Mock
+ private static ComputeConsolidationData computeConsolidationData;
+ @Mock
+ private static TranslateTo translateTo;
+ @Mock
+ private static ServiceTemplate serviceTemplate;
+ @Mock
+ private static ComputeTemplateConsolidationData consolidationData;
+ @Mock
+ private static HeatOrchestrationTemplate heatOrchestrationTemplate;
+
+ private static ComputeConsolidationDataHandler consolidationDataHandler;
+ private static final RequirementAssignment requirementAssignment = new RequirementAssignment();
+
+ @Test
+ public void testAddNodesConnectedOut() {
+ mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler.addNodesConnectedOut(
+ translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData).addNodesConnectedOut(
+ COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ }
+
+ @Test
+ public void testAddNodesConnectedOut_consolidationDataNotExist() {
+ mockEntities_NullConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler.addNodesConnectedOut(
+ translateTo, COMPUTE_NODE_TEMPLATE_ID_1, REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData, Mockito.times(0)).addNodesConnectedOut(
+ Mockito.any(), Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void testAddNodesConnectedIn() {
+ String sourceNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_1;
+ String dependentNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_2;
+ mockEntities(dependentNodeTemplateId);
+ consolidationDataHandler.addNodesConnectedIn(translateTo, sourceNodeTemplateId,
+ dependentNodeTemplateId, "targetResourceId", REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
+ Mockito.verify(consolidationData).addNodesConnectedIn(
+ sourceNodeTemplateId, REQUIREMENT_ID, requirementAssignment);
+ }
+
+ @Test
+ public void testAddNodesConnectedIn_consolidationDataNotExist() {
+ String dependentNodeTemplateId = COMPUTE_NODE_TEMPLATE_ID_2;
+ mockEntities_NullConsolidationData(dependentNodeTemplateId);
+ consolidationDataHandler.addNodesConnectedIn(translateTo, COMPUTE_NODE_TEMPLATE_ID_1,
+ dependentNodeTemplateId, "targetResourceId", REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, dependentNodeTemplateId);
+ Mockito.verify(consolidationData, Mockito.times(0)).addNodesConnectedIn(
+ Mockito.any(), Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void testRemoveParamNameFromAttrFuncList() {
+ mockEntities(COMPUTE_NODE_TEMPLATE_ID_2);
+ consolidationDataHandler.removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate,
+ "paramName", COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(consolidationData).removeParamNameFromAttrFuncList("paramName");
+ }
+
+ @Test
+ public void testRemoveParamNameFromAttrFuncList_consolidationDataNotExist() {
+ mockEntities_NullConsolidationData(COMPUTE_NODE_TEMPLATE_ID_2);
+ consolidationDataHandler.removeParamNameFromAttrFuncList(serviceTemplate, heatOrchestrationTemplate,
+ "paramName", COMPUTE_NODE_TEMPLATE_ID_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
+ Mockito.verify(consolidationData, Mockito.times(0))
+ .removeParamNameFromAttrFuncList(Mockito.any());
+ }
+
+ @Test
+ public void testAddConsolidationData() {
+ consolidationDataHandler.addConsolidationData(SERVICE_FILE_NAME,
+ COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ }
+
+ @Test
+ public void testAddPortToConsolidationData() {
+ mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler.addPortToConsolidationData(translateTo, COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TEMPLATE_ID_1, PORT_NODE_TYPE_1, PORT_NODE_TEMPLATE_ID_1);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData).addPort(PORT_NODE_TYPE_1, PORT_NODE_TEMPLATE_ID_1);
+ }
+
+ @Test
+ public void testAddVolumeToConsolidationData() {
+ mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler.addVolumeToConsolidationData(
+ translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1,
+ REQUIREMENT_ID, requirementAssignment);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData).addVolume(REQUIREMENT_ID, requirementAssignment);
+ }
+
+
+ @Test
+ public void testAddGroupIdToConsolidationData() {
+ mockEntities(COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationDataHandler.addGroupIdToConsolidationData(
+ translateTo, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1, GROUP_ID);
+ Mockito.verify(computeConsolidationData).addComputeTemplateConsolidationData(
+ SERVICE_FILE_NAME, COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Mockito.verify(consolidationData).addGroupId(GROUP_ID);
+ }
+
+ private void mockEntities(String nodeTemplateId) {
+ mockServiceTemplate(nodeTemplateId);
+ mockTranslateTo(nodeTemplateId);
+ mockComputeConsolidationData();
+ }
+
+ private void mockEntities_NullConsolidationData(String nodeTemplateId) {
+ mockServiceTemplate(nodeTemplateId);
+ mockTranslateTo(nodeTemplateId);
+ mockNullConsolidationData();
+ }
+
+ private void mockServiceTemplate(String nodeTemplateId) {
+ TopologyTemplate topologyTemplate = createTopologyTemplate(nodeTemplateId);
+ Mockito.when(serviceTemplate.getTopology_template()).thenReturn(topologyTemplate);
+
+ Map<String, String> metadata = new HashMap<>();
+ metadata.put(ToscaConstants.ST_METADATA_TEMPLATE_NAME, SERVICE_FILE_NAME_PREFIX);
+ Mockito.when(serviceTemplate.getMetadata()).thenReturn(metadata);
+ }
+
+ private void mockTranslateTo(String nodeTemplateId) {
+ Mockito.when(translateTo.getTranslatedId()).thenReturn(nodeTemplateId);
+ Mockito.when(translateTo.getServiceTemplate()).thenReturn(serviceTemplate);
+ }
+
+ private void mockComputeConsolidationData() {
+ Mockito.when(computeConsolidationData
+ .addComputeTemplateConsolidationData(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(consolidationData);
+ }
+
+ private void mockNullConsolidationData() {
+ Mockito.when(computeConsolidationData
+ .addComputeTemplateConsolidationData(Mockito.anyString(), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(null);
+ }
+
+ private TopologyTemplate createTopologyTemplate(String nodeTemplateId) {
+ TopologyTemplate topologyTemplate = new TopologyTemplate();
+ Map<String, NodeTemplate> nodeTemplates = new HashMap<>();
+ NodeTemplate nodeTemplate = new NodeTemplate();
+ nodeTemplate.setType(COMPUTE_NODE_TYPE_1);
+ nodeTemplates.put(nodeTemplateId, nodeTemplate);
+ topologyTemplate.setNode_templates(nodeTemplates);
+ return topologyTemplate;
+ }
+
+}
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
index a92e298c0a..32e9f0d30d 100644
--- 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
@@ -16,83 +16,125 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+import java.util.EnumMap;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
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";
+ private final EnumMap<ServiceTemplateFileNameEnum, FileComputeConsolidationData> mockMap =
+ new EnumMap<>(ServiceTemplateFileNameEnum.class);
+
+ @Mock
+ private FileComputeConsolidationData mockFileComputeConsolidationData1;
+ @Mock
+ private FileComputeConsolidationData mockFileComputeConsolidationData2;
+
+ private final ComputeConsolidationData consolidationData = new ComputeConsolidationData();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ addMocksToMap();
+ }
+
@Test
public void testAddComputeTemplateConsolidationData() {
- ComputeConsolidationData consolidationData = new ComputeConsolidationData();
- consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
- COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ String serviceTemplate = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addComputeTemplateConsolidationData(
+ serviceTemplate, 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);
+ expectedServiceTemplateNames.add(serviceTemplate);
+ checkComputeConsolidationData(consolidationData, serviceTemplate,
+ expectedServiceTemplateNames);
}
@Test
public void testAddSameConsolidationDataTwice_noNewCreated() {
- ComputeConsolidationData consolidationData = new ComputeConsolidationData();
- consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ String serviceTemplate = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate,
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);
+ expectedServiceTemplateNames.add(serviceTemplate);
+ checkComputeConsolidationData(consolidationData, serviceTemplate, expectedServiceTemplateNames);
- consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate,
COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
- consolidationData.getFileComputeConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1);
- checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+ checkComputeConsolidationData(consolidationData, serviceTemplate, expectedServiceTemplateNames);
}
@Test
- public void testAddDiffConsolidationData_SameServiceTemplate_DiffNodeTypes() {
- ComputeConsolidationData consolidationData = new ComputeConsolidationData();
-
- consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ public void testAddDiffConsolidationData_diffNodeTypes() {
+ String serviceTemplate = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate,
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);
+ expectedServiceTemplateNames.add(serviceTemplate);
+ checkComputeConsolidationData(consolidationData, serviceTemplate, expectedServiceTemplateNames);
- consolidationData.addComputeTemplateConsolidationData(SERVICE_TEMPLATE_FILE_NAME_1,
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate,
COMPUTE_NODE_TYPE_2, COMPUTE_NODE_TEMPLATE_ID_2);
- checkComputeConsolidationData(consolidationData, SERVICE_TEMPLATE_FILE_NAME_1, expectedServiceTemplateNames);
+ checkComputeConsolidationData(consolidationData, serviceTemplate, 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);
+ public void testAddDiffConsolidationData_diffServiceTemplate() {
+ String serviceTemplate1 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate1, 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);
+ expectedServiceTemplateNames.add(serviceTemplate1);
+ checkComputeConsolidationData(consolidationData, serviceTemplate1, expectedServiceTemplateNames);
+
+ String serviceTemplate2 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2.name();
+ consolidationData.addComputeTemplateConsolidationData(serviceTemplate2, COMPUTE_NODE_TYPE_2,
+ COMPUTE_NODE_TEMPLATE_ID_2);
+ expectedServiceTemplateNames.add(serviceTemplate2);
+ checkComputeConsolidationData(consolidationData, serviceTemplate2, 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);
+ @Test
+ public void testAddSameConsolidationDataTwice_testWithMock() throws Exception {
+ String serviceTemplate = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate, COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TEMPLATE_ID_1);
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate, COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TEMPLATE_ID_1, 2);
+ }
+ @Test
+ public void testAddDiffConsolidationData_diffNodeTypes_testWithMock() throws Exception {
+ String serviceTemplate = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate, COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TEMPLATE_ID_1);
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate, COMPUTE_NODE_TYPE_2,
+ COMPUTE_NODE_TEMPLATE_ID_2);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_diffServiceTemplate_testWithMock() throws Exception {
+ String serviceTemplate1 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate1, COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TEMPLATE_ID_1);
+ String serviceTemplate2 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckComputeTemplateConsolidationData(serviceTemplate2, COMPUTE_NODE_TYPE_2,
+ COMPUTE_NODE_TEMPLATE_ID_2);
}
private void checkComputeConsolidationData(ComputeConsolidationData consolidationData,
String serviceTemplateFileName, Set<String> expectedServiceTemplateNames) {
-
FileComputeConsolidationData fileComputeConsolidationData = consolidationData
.getFileComputeConsolidationData(serviceTemplateFileName);
Assert.assertNotNull(fileComputeConsolidationData);
@@ -107,5 +149,44 @@ public class ComputeConsolidationDataTest {
Assert.assertTrue(allServiceTemplateFileNames.containsAll(expectedServiceTemplateNames));
}
+ private void addAndCheckComputeTemplateConsolidationData(String serviceTemplateFileName,
+ String computeNodeType, String computeNodeTemplateId) throws Exception {
+ addAndCheckComputeTemplateConsolidationData(serviceTemplateFileName, computeNodeType,
+ computeNodeTemplateId, 1);
+ }
+
+ private void addAndCheckComputeTemplateConsolidationData(String serviceTemplateFileName,
+ String computeNodeType, String computeNodeTemplateId, int expectedTime) throws Exception {
+ FileComputeConsolidationData fileComputeConsolidationDataMock =
+ setFileComputeConsolidationDataMock(serviceTemplateFileName);
+ consolidationData.addComputeTemplateConsolidationData(
+ serviceTemplateFileName, computeNodeType, computeNodeTemplateId);
+
+ Mockito.verify(fileComputeConsolidationDataMock, Mockito.times(expectedTime))
+ .addComputeTemplateConsolidationData(computeNodeType, computeNodeTemplateId);
+ }
+
+ private FileComputeConsolidationData setFileComputeConsolidationDataMock(
+ String serviceTemplateName) throws Exception {
+ FileComputeConsolidationData mock = getFileComputeConsolidationDataMock(serviceTemplateName);
+ consolidationData.setFileComputeConsolidationData(serviceTemplateName, mock);
+ return mock;
+ }
+
+ private void addMocksToMap() {
+ mockMap.put(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1, mockFileComputeConsolidationData1);
+ mockMap.put(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2, mockFileComputeConsolidationData2);
+ }
+
+ private FileComputeConsolidationData getFileComputeConsolidationDataMock(String serviceTemplateName)
+ throws Exception {
+ ServiceTemplateFileNameEnum enumValue = ServiceTemplateFileNameEnum.valueOf(serviceTemplateName);
+ FileComputeConsolidationData mock = mockMap.get(enumValue);
+ if (mock == null) {
+ throw new Exception("This service Template File Name doesn't supported. "
+ + "Please add it to ServiceTemplateFileName enum");
+ }
+ return mock;
+ }
}
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
new file mode 100644
index 0000000000..9f32aec8aa
--- /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/ComputeTemplateConsolidationDataTest.java
@@ -0,0 +1,140 @@
+/*
+ * 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;
+
+public class ComputeTemplateConsolidationDataTest {
+
+ private static final String COMPUTE_NODE_TEMPLATE_ID_1 = "computeNodeTemplateId1";
+ private static final String COMPUTE_NODE_TEMPLATE_ID_2 = "computeNodeTemplateId2";
+ private static final String REQUIREMENT_ID_1 = "requirementId1";
+ private static final String REQUIREMENT_ID_2 = "requirementId2";
+
+ private static final String PORT_TYPE_1 = "portType1";
+ 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 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});
+ 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});
+ 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});
+ addAndCheckPorts(PORT_TYPE_1, PORT_NODE_TEMPLATE_ID_1, expectedPorts);
+
+ 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});
+ 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});
+ 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});
+ addAndCheckVolume(REQUIREMENT_ID_1, COMPUTE_NODE_TEMPLATE_ID_1, expectedVolumes);
+
+ 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) {
+ consolidationData.addPort(portType, portNodeTemplateId);
+ checkPorts(consolidationData.getPorts(), expectedPorts);
+ }
+
+ private void checkPorts(Map<String, List<String>> actualAllPorts,
+ Map<String, String[]> expectedAllPorts) {
+ Assert.assertNotNull(actualAllPorts);
+ expectedAllPorts.keySet().forEach(expectedPortType -> {
+ Assert.assertTrue(actualAllPorts.containsKey(expectedPortType));
+ Assert.assertEquals(expectedAllPorts.size(), actualAllPorts.size());
+ checkPortsPerType(actualAllPorts, expectedAllPorts, 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)));
+ }
+
+ private void addAndCheckVolume(String requirementId, String computeNodeTemplateId,
+ Map<String, String[]> expectedVolumes) {
+ RequirementAssignment requirementAssignment1 = createRequirement(computeNodeTemplateId);
+ consolidationData.addVolume(requirementId, requirementAssignment1);
+ checkVolumes(consolidationData.getVolumes(), expectedVolumes);
+ }
+
+ private void checkVolumes(Map<String, List<RequirementAssignmentData>> actualVolumes,
+ Map<String, String[]> expectedVolumes) {
+ Assert.assertNotNull(actualVolumes);
+ expectedVolumes.keySet().forEach(nodeTemplateId -> {
+ Assert.assertTrue(actualVolumes.containsKey(nodeTemplateId));
+ Assert.assertEquals(expectedVolumes.size(), actualVolumes.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);
+ List<String> requirementIds = Arrays.asList(expectedVolumes.get(nodeTemplateId));
+ Assert.assertEquals(requirementIds.size(), actualRequirementAssignmentData.size());
+ actualRequirementAssignmentData.forEach(actualRequirementAssignment ->
+ Assert.assertTrue(requirementIds.contains(actualRequirementAssignment.getRequirementId())));
+ }
+
+ private RequirementAssignment createRequirement(String nodeTemplateId) {
+ RequirementAssignment requirementAssignment = new RequirementAssignment();
+ requirementAssignment.setNode(nodeTemplateId);
+ return 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/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 fd96f93bb5..447314c25f 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
@@ -34,6 +34,13 @@ public class EntityConsolidationDataTest {
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";
+ private static final String GROUP_ID_1 = "groupId1";
+ private static final String GROUP_ID_2 = "groupId2";
+ private static final String FIELD_1 = "field1";
+ private static final String FIELD_2 = "field2";
+
+
+ private final EntityConsolidationData consolidationData = new EntityConsolidationData();
@Test
public void testIsGetAttrOutFromEntityLegal() {
@@ -74,7 +81,6 @@ public class EntityConsolidationDataTest {
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));
@@ -82,7 +88,6 @@ public class EntityConsolidationDataTest {
entityConsolidationData.setNodesGetAttrOut(getAttOutMap);
EntityConsolidationData entityConsolidationData1 = new EntityConsolidationData();
- //entityConsolidationData1.setNodesGetAttrOut(getAttOutMap1);
List<EntityConsolidationData> entityConsolidationDataList =
Arrays.asList(entityConsolidationData, entityConsolidationData1);
@@ -125,9 +130,7 @@ public class EntityConsolidationDataTest {
@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);
@@ -139,9 +142,7 @@ public class EntityConsolidationDataTest {
@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);
@@ -153,9 +154,7 @@ public class EntityConsolidationDataTest {
@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);
@@ -167,9 +166,7 @@ public class EntityConsolidationDataTest {
@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);
@@ -181,15 +178,13 @@ public class EntityConsolidationDataTest {
@Test
public void testAddOutputParamGetAttrIn() {
- EntityConsolidationData consolidationData = new EntityConsolidationData();
- GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1");
-
+ GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData(FIELD_1);
consolidationData.addOutputParamGetAttrIn(getAttrFuncData1);
List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
Assert.assertEquals(1, outputParametersGetAttrIn.size());
Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1));
- GetAttrFuncData getAttrFuncData2 = createGetAttrFuncData("field2");
+ GetAttrFuncData getAttrFuncData2 = createGetAttrFuncData(FIELD_2);
consolidationData.addOutputParamGetAttrIn(getAttrFuncData2);
Assert.assertEquals(2,outputParametersGetAttrIn.size());
Assert.assertTrue(outputParametersGetAttrIn.contains(getAttrFuncData1));
@@ -198,15 +193,13 @@ public class EntityConsolidationDataTest {
@Test
public void testRemoveParamNameFromAttrFuncList() {
- EntityConsolidationData consolidationData = new EntityConsolidationData();
- GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData("field1");
-
+ GetAttrFuncData getAttrFuncData1 = createGetAttrFuncData(FIELD_1);
consolidationData.addOutputParamGetAttrIn(getAttrFuncData1);
// verify that getAttrFuncData was added
List<GetAttrFuncData> outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
Assert.assertEquals(1, outputParametersGetAttrIn.size());
- consolidationData.removeParamNameFromAttrFuncList("field2");
+ consolidationData.removeParamNameFromAttrFuncList(FIELD_2);
//verify that not existing getAttrFuncData parameter wasn't removed and no Exception
outputParametersGetAttrIn = consolidationData.getOutputParametersGetAttrIn();
Assert.assertEquals(1, outputParametersGetAttrIn.size());
@@ -217,6 +210,19 @@ public class EntityConsolidationDataTest {
Assert.assertEquals(0, outputParametersGetAttrIn.size());
}
+ @Test
+ public void testAddGroupId() {
+ consolidationData.addGroupId(GROUP_ID_1);
+ List<String> groupIds = consolidationData.getGroupIds();
+ Assert.assertNotNull(groupIds);
+ Assert.assertTrue(groupIds.contains(GROUP_ID_1));
+ Assert.assertEquals(1, consolidationData.getGroupIds().size());
+
+ consolidationData.addGroupId(GROUP_ID_2);
+ Assert.assertEquals(2, consolidationData.getGroupIds().size());
+ Assert.assertTrue(groupIds.contains(GROUP_ID_2));
+ }
+
private GetAttrFuncData createGetAttrFuncData(String field) {
GetAttrFuncData getAttrFuncData = new GetAttrFuncData();
getAttrFuncData.setFieldName(field);
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
index eab3bd25b1..5d3d58e74c 100644
--- 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
@@ -17,67 +17,109 @@
package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
import java.util.Collection;
+import java.util.EnumMap;
import java.util.HashSet;
import java.util.Set;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
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";
+ private final FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+
+ private enum ComputeNodeTypeEnum {
+ COMPUTE_NODE_TYPE_1,
+ COMPUTE_NODE_TYPE_2
+ }
+
+ private final EnumMap<ComputeNodeTypeEnum, TypeComputeConsolidationData> mockMap =
+ new EnumMap<>(ComputeNodeTypeEnum.class);
+
+ @Mock
+ private TypeComputeConsolidationData mockTypeComputeConsolidationData1;
+ @Mock
+ private TypeComputeConsolidationData mockTypeComputeConsolidationData2;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ addMocksToMap();
+ }
@Test
public void testAddComputeTemplateConsolidationData() {
- FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
- consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
-
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
Set<String> expectedComputeNodeTypes = new HashSet<>();
- expectedComputeNodeTypes.add(COMPUTE_NODE_TYPE_1);
- checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+ expectedComputeNodeTypes.add(computeNodeType);
+ checkComputeConsolidationData(consolidationData, computeNodeType, expectedComputeNodeTypes);
}
@Test
public void testAddSameConsolidationDataTwice_noNewCreated() {
- FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
- consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
TypeComputeConsolidationData firstTypeComputeConsolidationData =
- consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1);
+ consolidationData.getTypeComputeConsolidationData(computeNodeType);
- consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_1);
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
TypeComputeConsolidationData secondTypeComputeConsolidationData =
- consolidationData.getTypeComputeConsolidationData(COMPUTE_NODE_TYPE_1);
+ consolidationData.getTypeComputeConsolidationData(computeNodeType);
Assert.assertEquals(firstTypeComputeConsolidationData, secondTypeComputeConsolidationData);
}
@Test
- public void testAddDiffConsolidationData_DiffNodeType() {
- FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+ public void testAddConsolidationData_diffNodeType() {
+ String computeNodeType1 = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType1, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(computeNodeType1);
+ checkComputeConsolidationData(consolidationData, computeNodeType1, expectedComputeNodeTypes);
- 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);
+ String computeNodeType2 = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_2.name();
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType2, COMPUTE_NODE_TEMPLATE_ID_2);
+ expectedComputeNodeTypes.add(computeNodeType2);
+ checkComputeConsolidationData(consolidationData, computeNodeType2, expectedComputeNodeTypes);
+ }
+
+ @Test
+ public void testAddConsolidationData_diffNodeTemplateId() {
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(computeNodeType);
+ checkComputeConsolidationData(consolidationData, computeNodeType, 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);
+ consolidationData.addComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_2);
+ checkComputeConsolidationData(consolidationData, computeNodeType, expectedComputeNodeTypes);
}
@Test
- public void testAddDiffConsolidationData_SameNodeType_MultiNodeTemplateId() {
- FileComputeConsolidationData consolidationData = new FileComputeConsolidationData();
+ public void testAddSameConsolidationDataTwice_testWithMock() throws Exception {
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1, 2);
+ }
- 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 testAddConsolidationData_diffNodeType_testWithMock() throws Exception {
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_2);
+ }
- consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TYPE_1, COMPUTE_NODE_TEMPLATE_ID_2);
- checkComputeConsolidationData(consolidationData, COMPUTE_NODE_TYPE_1, expectedComputeNodeTypes);
+ @Test
+ public void testAddConsolidationData_diffNodeTemplateId_testWithMock() throws Exception {
+ String computeNodeType = ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1.name();
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_1);
+ addAndCheckComputeTemplateConsolidationData(computeNodeType, COMPUTE_NODE_TEMPLATE_ID_2);
}
private void checkComputeConsolidationData(FileComputeConsolidationData fileComputeConsolidationData,
@@ -89,10 +131,52 @@ public class FileComputeConsolidationDataTest {
}
private void checkGetAllComputeTypes(FileComputeConsolidationData fileComputeConsolidationData,
- Set<String> expectedComputeNodeTypes) {
+ Set<String> expectedComputeNodeTypes) {
Collection<String> allComputeTypes = fileComputeConsolidationData.getAllComputeTypes();
Assert.assertNotNull(allComputeTypes);
Assert.assertEquals(allComputeTypes.size(), expectedComputeNodeTypes.size());
Assert.assertTrue(allComputeTypes.containsAll(expectedComputeNodeTypes));
}
+
+ private void addAndCheckComputeTemplateConsolidationData(
+ String computeNodeType, String computeNodeTemplateId) throws Exception {
+ addAndCheckComputeTemplateConsolidationData(computeNodeType,
+ computeNodeTemplateId, 1);
+ }
+
+ private void addAndCheckComputeTemplateConsolidationData(String computeNodeType,
+ String computeNodeTemplateId, int expectedTime) throws Exception {
+ TypeComputeConsolidationData fileComputeConsolidationDataMock =
+ setTypeComputeConsolidationDataMock(computeNodeType);
+
+ consolidationData.addComputeTemplateConsolidationData(
+ computeNodeType, computeNodeTemplateId);
+
+ Mockito.verify(fileComputeConsolidationDataMock, Mockito.times(expectedTime))
+ .addComputeTemplateConsolidationData(computeNodeTemplateId);
+ }
+
+ private void addMocksToMap() {
+ mockMap.put(ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_1, mockTypeComputeConsolidationData1);
+ mockMap.put(ComputeNodeTypeEnum.COMPUTE_NODE_TYPE_2, mockTypeComputeConsolidationData2);
+ }
+
+ private TypeComputeConsolidationData setTypeComputeConsolidationDataMock(
+ String computeType) throws Exception {
+ TypeComputeConsolidationData typeComputeConsolidationDataMock =
+ getFileComputeConsolidationDataMock(computeType);
+ consolidationData.setTypeComputeConsolidationData(computeType, typeComputeConsolidationDataMock);
+ return typeComputeConsolidationDataMock;
+ }
+
+ private TypeComputeConsolidationData getFileComputeConsolidationDataMock(String computeType) throws Exception {
+ ComputeNodeTypeEnum enumValue = ComputeNodeTypeEnum.valueOf(computeType);
+ TypeComputeConsolidationData mock = mockMap.get(enumValue);
+ if (mock == null) {
+ throw new Exception("This compute Type doesn't support. "
+ + "Please add it to ComputeNodeTypeEnum enum");
+ }
+ return mock;
+ }
+
}
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/FilePortConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/FilePortConsolidationDataTest.java
new file mode 100644
index 0000000000..8dd0307a43
--- /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/FilePortConsolidationDataTest.java
@@ -0,0 +1,102 @@
+/*
+ * 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;
+
+import org.openecomp.sdc.heat.datatypes.model.HeatResourcesTypes;
+
+public class FilePortConsolidationDataTest {
+
+ 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_RESOURCE_ID_1 = "pcm_port_01";
+ private static final String PORT_RESOURCE_ID_2 = "pcm_port_02";
+ private static final String PORT_RESOURCE_TYPE = HeatResourcesTypes.NEUTRON_PORT_RESOURCE_TYPE.getHeatResource();
+
+ private final FilePortConsolidationData consolidationData = new FilePortConsolidationData();
+
+ @Test
+ public void testAddPortConsolidationData() {
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_1,
+ PORT_RESOURCE_TYPE);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(PORT_NODE_TEMPLATE_ID_1);
+ checkComputeConsolidationData(consolidationData, PORT_NODE_TEMPLATE_ID_1, expectedComputeNodeTypes);
+ }
+
+ @Test
+ public void testAddSameConsolidationDataTwice_noNewCreated() {
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_1,
+ PORT_RESOURCE_TYPE);
+ PortTemplateConsolidationData firstPortTemplateConsolidationData =
+ consolidationData.getPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1);
+
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_1,
+ PORT_RESOURCE_TYPE);
+ PortTemplateConsolidationData secondPortTemplateConsolidationData =
+ consolidationData.getPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1);
+ Assert.assertEquals(firstPortTemplateConsolidationData, secondPortTemplateConsolidationData);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_diffNodeTemplateIds() {
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_1,
+ PORT_RESOURCE_TYPE);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(PORT_NODE_TEMPLATE_ID_1);
+ checkComputeConsolidationData(consolidationData, PORT_NODE_TEMPLATE_ID_1, expectedComputeNodeTypes);
+
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_2, PORT_RESOURCE_ID_2,
+ PORT_RESOURCE_TYPE);
+ expectedComputeNodeTypes.add(PORT_NODE_TEMPLATE_ID_2);
+ checkComputeConsolidationData(consolidationData, PORT_NODE_TEMPLATE_ID_2, expectedComputeNodeTypes);
+ }
+
+ @Test
+ public void testAddDiffConsolidationData_diffResourceIds() {
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_1,
+ PORT_RESOURCE_TYPE);
+ Set<String> expectedComputeNodeTypes = new HashSet<>();
+ expectedComputeNodeTypes.add(PORT_NODE_TEMPLATE_ID_1);
+ checkComputeConsolidationData(consolidationData, PORT_NODE_TEMPLATE_ID_1, expectedComputeNodeTypes);
+
+ consolidationData.addPortTemplateConsolidationData(PORT_NODE_TEMPLATE_ID_1, PORT_RESOURCE_ID_2,
+ PORT_RESOURCE_TYPE);
+ checkComputeConsolidationData(consolidationData, PORT_NODE_TEMPLATE_ID_1, expectedComputeNodeTypes);
+ }
+
+ private void checkComputeConsolidationData(FilePortConsolidationData filePortConsolidationData,
+ String computeNodeTemplateId, Set<String> expectedPortNodeTemplateIds) {
+ PortTemplateConsolidationData consolidationData =
+ filePortConsolidationData.getPortTemplateConsolidationData(computeNodeTemplateId);
+ Assert.assertNotNull(consolidationData);
+ checkGetTemplateIds(filePortConsolidationData, expectedPortNodeTemplateIds);
+ }
+
+ private void checkGetTemplateIds(FilePortConsolidationData filePortConsolidationData,
+ Set<String> expectedPortNodeTemplateIds) {
+ Collection<String> allPortNodeTemplateIds = filePortConsolidationData.getAllPortNodeTemplateIds();
+ Assert.assertNotNull(allPortNodeTemplateIds);
+ Assert.assertEquals(allPortNodeTemplateIds.size(), expectedPortNodeTemplateIds.size());
+ Assert.assertTrue(allPortNodeTemplateIds.containsAll(expectedPortNodeTemplateIds));
+ }
+}
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/PortConsolidationDataTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/PortConsolidationDataTest.java
new file mode 100644
index 0000000000..05382e12ce
--- /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/PortConsolidationDataTest.java
@@ -0,0 +1,225 @@
+/*
+ * 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.EnumMap;
+import java.util.HashSet;
+import java.util.Set;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.openecomp.sdc.heat.datatypes.model.Resource;
+
+public class PortConsolidationDataTest {
+
+ private static final String PORT_NODE_TYPE_1 = "portNodeType1";
+ private static final String PORT_NODE_TYPE_2 = "portNodeType2";
+ private static final String PORT_NODE_TEMPLATE_ID_1 = "portNodeTemplateId1";
+ private static final String PORT_NODE_TEMPLATE_ID_2 = "portNodeTemplateId2";
+ private static final String SUB_INTERFACE_NODE_TEMPLATE_ID_1 = "subInterfaceNodeTemplateId1";
+ private static final String SUB_INTERFACE_NODE_TEMPLATE_ID_2 = "subInterfaceNodeTemplateId2";
+ private static final String PORT_RESOURCE_ID = "portResourceId";
+ private static final String PORT_RESOURCE_TYPE = "portResourceType";
+
+ private final EnumMap<ServiceTemplateFileNameEnum, FilePortConsolidationData> mockMap =
+ new EnumMap<>(ServiceTemplateFileNameEnum.class);
+
+ @Mock
+ private FilePortConsolidationData mockFilePortConsolidationData1;
+ @Mock
+ private FilePortConsolidationData mockFilePortConsolidationData2;
+
+ private final Resource resource = new Resource();
+ private final PortConsolidationData consolidationData = new PortConsolidationData();
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ addMocksToMap();
+ }
+
+ @Test
+ public void testAddConsolidationData_noNewCreated() {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addPortTemplateConsolidationData(serviceTemplateName, PORT_NODE_TYPE_1,
+ PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ consolidationData.getFilePortConsolidationData(serviceTemplateName);
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(serviceTemplateName);
+ checkPortConsolidationData(consolidationData, serviceTemplateName, expectedServiceTemplateNames);
+
+ consolidationData.addPortTemplateConsolidationData(serviceTemplateName, PORT_NODE_TYPE_1,
+ PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ consolidationData.getFilePortConsolidationData(serviceTemplateName);
+ checkPortConsolidationData(consolidationData, serviceTemplateName, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddConsolidationData_DiffNodeTypes() {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addPortTemplateConsolidationData(serviceTemplateName, PORT_NODE_TYPE_1,
+ PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(serviceTemplateName);
+ checkPortConsolidationData(consolidationData, serviceTemplateName, expectedServiceTemplateNames);
+ consolidationData.addPortTemplateConsolidationData(serviceTemplateName, PORT_NODE_TYPE_2,
+ PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ checkPortConsolidationData(consolidationData, serviceTemplateName, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddConsolidationData_DiffServiceTemplate() {
+ String serviceTemplateName1 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ consolidationData.addPortTemplateConsolidationData(
+ serviceTemplateName1, PORT_NODE_TYPE_1, PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ Set<String> expectedServiceTemplateNames = new HashSet<>();
+ expectedServiceTemplateNames.add(serviceTemplateName1);
+ checkPortConsolidationData(consolidationData, serviceTemplateName1, expectedServiceTemplateNames);
+
+ String serviceTemplateName2 = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2.name();
+ consolidationData.addPortTemplateConsolidationData(
+ serviceTemplateName2, PORT_NODE_TYPE_2, PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ expectedServiceTemplateNames.add(serviceTemplateName2);
+ checkPortConsolidationData(consolidationData, serviceTemplateName2, expectedServiceTemplateNames);
+ }
+
+ @Test
+ public void testAddConsolidationData_DiffNodeTypes_testWithMock() throws Exception {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckPortTemplateConsolidationData(serviceTemplateName,
+ PORT_NODE_TYPE_1);
+ addAndCheckPortTemplateConsolidationData(serviceTemplateName,
+ PORT_NODE_TYPE_2);
+ }
+
+ @Test
+ public void testAddConsolidationData_DiffServiceTemplate_testWithMock() throws Exception {
+ addAndCheckPortTemplateConsolidationData(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name(),
+ PORT_NODE_TYPE_1);
+ addAndCheckPortTemplateConsolidationData(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2.name(),
+ PORT_NODE_TYPE_2);
+ }
+
+ @Test
+ public void testAddSubInterfaceConsolidationData_Same() throws Exception {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_1);
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_1, 2);
+ }
+
+ @Test
+ public void testAddSubInterfaceConsolidationData_diffNodeTempId() throws Exception {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_1);
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_2, PORT_NODE_TEMPLATE_ID_1);
+ }
+
+ @Test
+ public void testAddSubInterfaceConsolidationData_diffNodeTempId_diffParentPort() throws Exception {
+ String serviceTemplateName = ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name();
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_1, PORT_NODE_TEMPLATE_ID_1);
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateName,
+ SUB_INTERFACE_NODE_TEMPLATE_ID_2, PORT_NODE_TEMPLATE_ID_2);
+ }
+
+ @Test
+ public void testAddSubInterfaceConsolidationData_diffServiceTemp() throws Exception {
+ addAndCheckSubInterfaceTemplateConsolidationData(
+ ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1.name(),
+ SUB_INTERFACE_NODE_TEMPLATE_ID_1, SUB_INTERFACE_NODE_TEMPLATE_ID_1);
+ addAndCheckSubInterfaceTemplateConsolidationData(
+ ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2.name(),
+ SUB_INTERFACE_NODE_TEMPLATE_ID_2, SUB_INTERFACE_NODE_TEMPLATE_ID_2);
+ }
+
+ private void addAndCheckPortTemplateConsolidationData(String serviceTemplateFileName,
+ String portNodeType) throws Exception {
+ FilePortConsolidationData filePortConsolidationDataMock =
+ setFilePortConsolidationDataMock(serviceTemplateFileName);
+
+ consolidationData.addPortTemplateConsolidationData(
+ serviceTemplateFileName, portNodeType, PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+
+ Mockito.verify(filePortConsolidationDataMock)
+ .addPortTemplateConsolidationData(portNodeType, PORT_RESOURCE_ID, PORT_RESOURCE_TYPE);
+ }
+
+ private void addAndCheckSubInterfaceTemplateConsolidationData(String serviceTemplateFileName,
+ String subInterfaceNodeTemplateId, String subInterfaceNodeTemplateType) throws Exception {
+ addAndCheckSubInterfaceTemplateConsolidationData(serviceTemplateFileName, subInterfaceNodeTemplateId,
+ subInterfaceNodeTemplateType, 1);
+ }
+
+ private void addAndCheckSubInterfaceTemplateConsolidationData(String serviceTemplateFileName,
+ String subInterfaceNodeTemplateId, String parentPortNodeTemplateId, int expectedTime) throws Exception {
+
+ FilePortConsolidationData filePortConsolidationDataMock =
+ setFilePortConsolidationDataMock(serviceTemplateFileName);
+ consolidationData.addSubInterfaceTemplateConsolidationData(serviceTemplateFileName, resource,
+ subInterfaceNodeTemplateId, parentPortNodeTemplateId);
+
+ Mockito.verify(filePortConsolidationDataMock, Mockito.times(expectedTime))
+ .addSubInterfaceTemplateConsolidationData(resource, subInterfaceNodeTemplateId,
+ parentPortNodeTemplateId);
+ }
+
+ private void addMocksToMap() {
+ mockMap.put(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_1, mockFilePortConsolidationData1);
+ mockMap.put(ServiceTemplateFileNameEnum.SERVICE_TEMPLATE_FILE_NAME_2, mockFilePortConsolidationData2);
+ }
+
+ private FilePortConsolidationData setFilePortConsolidationDataMock(String serviceTemplateName) throws Exception {
+ FilePortConsolidationData filePortConsolidationDataMock =
+ getFileComputeConsolidationDataMock(serviceTemplateName);
+ consolidationData.setFilePortConsolidationData(serviceTemplateName, filePortConsolidationDataMock);
+ return filePortConsolidationDataMock;
+ }
+
+ private FilePortConsolidationData getFileComputeConsolidationDataMock(String serviceTemplateName) throws Exception {
+ ServiceTemplateFileNameEnum enumValue = ServiceTemplateFileNameEnum.valueOf(serviceTemplateName);
+ FilePortConsolidationData mock = mockMap.get(enumValue);
+ if (mock == null) {
+ throw new Exception("This service Template File Name doesn't supported. "
+ + "Please add it to ServiceTemplateFileName enum");
+ }
+ return mock;
+ }
+
+ private void checkPortConsolidationData(PortConsolidationData consolidationData,
+ String serviceTemplateFileName, Set<String> expectedServiceTemplateNames) {
+ FilePortConsolidationData filePortConsolidationData = consolidationData
+ .getFilePortConsolidationData(serviceTemplateFileName);
+ Assert.assertNotNull(filePortConsolidationData);
+ checkGetAllServiceTemplateFileNames(consolidationData, expectedServiceTemplateNames);
+ }
+
+ private void checkGetAllServiceTemplateFileNames(PortConsolidationData consolidationData,
+ Set<String> expectedServiceTemplateNames) {
+ Set<String> allServiceTemplateFileNames = consolidationData.getAllServiceTemplateFileNames();
+ Assert.assertNotNull(allServiceTemplateFileNames);
+ Assert.assertEquals(expectedServiceTemplateNames.size(), allServiceTemplateFileNames.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/ServiceTemplateFileNameEnum.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/datatypes/heattotosca/unifiedmodel/consolidation/ServiceTemplateFileNameEnum.java
new file mode 100644
index 0000000000..63da373c3a
--- /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/ServiceTemplateFileNameEnum.java
@@ -0,0 +1,7 @@
+package org.openecomp.sdc.translator.datatypes.heattotosca.unifiedmodel.consolidation;
+
+public enum ServiceTemplateFileNameEnum {
+ SERVICE_TEMPLATE_FILE_NAME_1,
+ SERVICE_TEMPLATE_FILE_NAME_2
+}
+
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 6388620e7c..727dd5c43c 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
@@ -33,51 +33,47 @@ 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";
+ private static final String SERVER_NETWORK_ROLE_1_PORT = "server_network_role_1_port";
+ private static final String SERVER_NETWORK_ROLE_2_PORT = "server_network_role_2_port";
+
+ private final TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
@Test
public void testCollectAllPortsOfEachTypeFromComputesNoPorts() {
- TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
-
ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
-
- typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.setComputeTemplateConsolidationData("server_type",
computeTemplateConsolidationData);
- Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes();
+ Map<String, List<String>> stringListMap = consolidationData.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"));
+ ports.put(SERVER_NETWORK_ROLE_1_PORT,
+ Arrays.asList("server_0_network_role_1_port", "server_1_network_role_1_port"));
ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
computeTemplateConsolidationData.setPorts(ports);
- typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.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);
-
+ Map<String, List<String>> stringListMap = consolidationData.collectAllPortsOfEachTypeFromComputes();
+ Assert.assertTrue(stringListMap.containsKey(SERVER_NETWORK_ROLE_1_PORT)
+ && stringListMap.get(SERVER_NETWORK_ROLE_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"));
+ ports.put(SERVER_NETWORK_ROLE_1_PORT,
+ Arrays.asList("server_0_network_role_1_port_1", "server_1_network_role_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"));
+ ports1.put(SERVER_NETWORK_ROLE_2_PORT,
+ Arrays.asList("server_0_network_role_2_port_1", "server_1_network_role_2_port_2"));
ComputeTemplateConsolidationData computeTemplateConsolidationData = new ComputeTemplateConsolidationData();
computeTemplateConsolidationData.setPorts(ports);
@@ -85,27 +81,25 @@ public class TypeComputeConsolidationDataTest {
ComputeTemplateConsolidationData computeTemplateConsolidationData1 = new ComputeTemplateConsolidationData();
computeTemplateConsolidationData1.setPorts(ports1);
- TypeComputeConsolidationData typeComputeConsolidationData = new TypeComputeConsolidationData();
- typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type",
+ consolidationData.setComputeTemplateConsolidationData("server_type",
computeTemplateConsolidationData);
- typeComputeConsolidationData.setComputeTemplateConsolidationData("server_type1",
+ consolidationData.setComputeTemplateConsolidationData("server_type1",
computeTemplateConsolidationData1);
- Map<String, List<String>> stringListMap = typeComputeConsolidationData.collectAllPortsOfEachTypeFromComputes();
+ Map<String, List<String>> stringListMap = consolidationData.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_NETWORK_ROLE_1_PORT).size() == 2);
+ Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).contains("server_0_network_role_1_port_1")
+ && stringListMap.get(SERVER_NETWORK_ROLE_1_PORT).contains("server_1_network_role_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"));
+ Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).size() == 2);
+ Assert.assertTrue(stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).contains("server_0_network_role_2_port_1")
+ && stringListMap.get(SERVER_NETWORK_ROLE_2_PORT).contains("server_1_network_role_2_port_2"));
}
@Test
public void testAddComputeTemplateConsolidationData() {
- TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
consolidationData.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
Set<String> expectedNodeTemplateIds = new HashSet<>();
@@ -115,7 +109,6 @@ public class TypeComputeConsolidationDataTest {
@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);
@@ -128,8 +121,6 @@ public class TypeComputeConsolidationDataTest {
@Test
public void testAddDiffConsolidationData_DiffNodeTemplateId() {
- TypeComputeConsolidationData consolidationData = new TypeComputeConsolidationData();
-
final ComputeTemplateConsolidationData firstComputeTemplateConsolidationData = consolidationData
.addComputeTemplateConsolidationData(COMPUTE_NODE_TEMPLATE_ID_1);
Set<String> expectedNodeTemplateIds1 = new HashSet<>();