From 280d31feb0585132610e0079234a562a3c0577a1 Mon Sep 17 00:00:00 2001 From: siddharth0905 Date: Tue, 7 Nov 2017 17:00:31 +0530 Subject: Test Cases for the Port scaling Utility Test cases to cover all possible scenario which might come as port type. Change-Id: Icdfa35fea52cba86bc5128fad3ec2f857c1d6079 Issue-ID: SDC-573 Signed-off-by: siddharth0905 --- .../heattotosca/ConsolidationDataUtil.java | 2 +- .../heattotosca/ConsolidationDataUtilTest.java | 76 ++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtilTest.java (limited to 'openecomp-be/lib/openecomp-sdc-translator-lib') 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 a09d56672d..0a94d2a3d9 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 @@ -527,7 +527,7 @@ public class ConsolidationDataUtil { */ public static String getPortType(String portNodeTemplateId) { - if (!StringUtils.isNotBlank(portNodeTemplateId)) { + if (StringUtils.isBlank(portNodeTemplateId)) { return portNodeTemplateId; } diff --git a/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtilTest.java b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtilTest.java new file mode 100644 index 0000000000..019d143792 --- /dev/null +++ b/openecomp-be/lib/openecomp-sdc-translator-lib/openecomp-sdc-translator-core/src/test/java/org/openecomp/sdc/translator/services/heattotosca/ConsolidationDataUtilTest.java @@ -0,0 +1,76 @@ +package org.openecomp.sdc.translator.services.heattotosca; + +import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; + +public class ConsolidationDataUtilTest { + private static final String PORT_TYPE_FORMAT_1 = "a_11_network_port_22"; + private static final String PORT_TYPE_FORMAT_2 = "a_11_network_port22"; + private static final String PORT_TYPE_FORMAT_3 = "a_network_port_22"; + private static final String PORT_TYPE_FORMAT_4 = "a_network_port22"; + private static final String PORT_TYPE_FORMAT_5 = "network_port_22"; + private static final String PORT_TYPE_FORMAT_6 = "network_port22"; + private static final String PORT_TYPE_FORMAT_7 = "a_network_11_port22"; + private static final String PORT_TYPE_OUTPUT_1 = "a_network_port"; + private static final String PORT_TYPE_OUTPUT_2 = "network_port"; + private static final String PORT_TYPE_OUTPUT_3 = "a_network_11_port"; + + @Test + public void testGetPortType_Empty() throws Exception { + String port = ""; + assertEquals(ConsolidationDataUtil.getPortType(port), port); + } + + @Test + public void testGetPortType_Spaces() throws Exception { + String port = " "; + assertEquals(ConsolidationDataUtil.getPortType(port), port); + } + + @Test + public void testGetPortType_Null() throws Exception { + String port = null; + assertEquals(ConsolidationDataUtil.getPortType(port), port); + } + + @Test + public void testGetPortType_OnlyPortType() throws Exception { + String port = "network"; + assertEquals(ConsolidationDataUtil.getPortType(port), port); + } + + @Test + public void testGetPortType_WithServerAndPortIndex() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_1), PORT_TYPE_OUTPUT_1); + } + + @Test + public void testGetPortType_Input_WithServerAndPortIndexWithoutUnderscore() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_2), PORT_TYPE_OUTPUT_1); + } + + @Test + public void testGetPortType_Input_WithoutServerIndexAndWithPortIndex() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_3), PORT_TYPE_OUTPUT_1); + } + + @Test + public void testGetPortType_Input_WithoutServerIndexAndWithPortIndexWithoutUnderscore() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_4), PORT_TYPE_OUTPUT_1); + } + + @Test + public void testGetPortType_Input_PortTypeWithIndex() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_5), PORT_TYPE_OUTPUT_2); + } + + @Test + public void testGetPortType_Input_PortIndexWithoutUnderscore() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_6), PORT_TYPE_OUTPUT_2); + } + + @Test + public void testGetPortType_Input_PortIndexAndDigitInBetween() throws Exception { + assertEquals(ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_7), PORT_TYPE_OUTPUT_3); + } +} -- cgit 1.2.3-korg