Added oparent to sdc main
[sdc.git] / openecomp-be / lib / openecomp-sdc-translator-lib / openecomp-sdc-translator-core / src / test / java / org / openecomp / sdc / translator / services / heattotosca / ConsolidationDataUtilTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.translator.services.heattotosca;
22
23 import org.junit.Test;
24
25 import static org.junit.Assert.assertEquals;
26
27 public class ConsolidationDataUtilTest {
28     private static final String PORT_TYPE_FORMAT_1 = "a_11_network_port_22";
29     private static final String PORT_TYPE_FORMAT_2 = "a_11_network_port22";
30     private static final String PORT_TYPE_FORMAT_3 = "a_network_port_22";
31     private static final String PORT_TYPE_FORMAT_4 = "a_network_port22";
32     private static final String PORT_TYPE_FORMAT_5 = "network_port_22";
33     private static final String PORT_TYPE_FORMAT_6 = "network_port22";
34     private static final String PORT_TYPE_FORMAT_7 = "a_network_11_port22";
35     private static final String PORT_TYPE_OUTPUT_1 = "a_network_port_22";
36     private static final String PORT_TYPE_OUTPUT_2 =  "a_network_port22";
37     private static final String PORT_TYPE_OUTPUT_3 = "network_port_22";
38     private static final String PORT_TYPE_OUTPUT_4 = "network_port22";
39     private static final String PORT_TYPE_OUTPUT_5 = "a_network_11_port22";
40
41     private static final String VM_TYPE = "a";
42
43     @Test
44     public void testGetPortType_Empty() {
45         String port = "";
46         assertEquals(ConsolidationDataUtil.getPortType(port, VM_TYPE), port);
47     }
48
49     @Test
50     public void testGetPortType_Spaces() {
51         String port = "   ";
52         assertEquals(ConsolidationDataUtil.getPortType(port, VM_TYPE), port);
53     }
54
55     @Test
56     public void testGetPortType_Null() {
57         String port = null;
58         assertEquals(ConsolidationDataUtil.getPortType(port, VM_TYPE), port);
59     }
60
61     @Test
62     public void testGetPortType_OnlyPortType() {
63         String port = "network";
64         assertEquals(ConsolidationDataUtil.getPortType(port, VM_TYPE), port);
65     }
66
67     @Test
68     public void testGetPortType_WithServerAndPortIndex() {
69         assertEquals(PORT_TYPE_OUTPUT_1, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_1, VM_TYPE));
70     }
71
72     @Test
73     public void testGetPortType_Input_WithServerAndPortIndexWithoutUnderscore() {
74         assertEquals(PORT_TYPE_OUTPUT_2, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_2, VM_TYPE));
75     }
76
77     @Test
78     public void testGetPortType_Input_WithoutServerIndexAndWithPortIndex() {
79         assertEquals(PORT_TYPE_OUTPUT_1, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_3, VM_TYPE));
80     }
81
82     @Test
83     public void testGetPortType_Input_WithoutServerIndexAndWithPortIndexWithoutUnderscore() {
84         assertEquals(PORT_TYPE_OUTPUT_2, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_4, VM_TYPE));
85     }
86
87     @Test
88     public void testGetPortType_Input_PortTypeWithIndex() {
89         assertEquals(PORT_TYPE_OUTPUT_3, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_5, VM_TYPE));
90     }
91
92     @Test
93     public void testGetPortType_Input_PortIndexWithoutUnderscore() {
94         assertEquals(PORT_TYPE_OUTPUT_4, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_6, VM_TYPE));
95     }
96
97     @Test
98     public void testGetPortType_Input_PortIndexAndDigitInBetween() {
99         assertEquals(PORT_TYPE_OUTPUT_5, ConsolidationDataUtil.getPortType(PORT_TYPE_FORMAT_7, VM_TYPE));
100     }
101 }