First part of onap rename
[appc.git] / appc-common / src / test / java / org / openecomp / appc / util / TestStringHelper.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * 
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  * ============LICENSE_END=========================================================
23  */
24
25
26
27 package org.onap.appc.util;
28
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertNotNull;
31 import static org.junit.Assert.assertTrue;
32
33 import java.util.Properties;
34
35 import org.junit.Test;
36 import org.onap.appc.util.StringHelper;
37
38
39 public class TestStringHelper {
40
41     @Test
42     public void testAsListWithNullList() {
43         String value = StringHelper.asList((String[]) null);
44         assertNotNull(value);
45         assertEquals("[]", value);
46     }
47
48     @Test
49     public void testAsListWithEmptyList() {
50         String value = StringHelper.asList(new String[] {});
51         assertNotNull(value);
52         assertEquals("[]", value);
53     }
54
55     @Test
56     public void testAsListWithSingleValue() {
57         String value = StringHelper.asList("one");
58         assertNotNull(value);
59         assertEquals("[one]", value);
60     }
61
62     @Test
63     public void testAsListWithTwoValues() {
64         String value = StringHelper.asList("one", "two");
65         assertNotNull(value);
66         assertEquals("[one,two]", value);
67     }
68
69     @Test
70     public void testAsListWithFiveValues() {
71         String value = StringHelper.asList("one", "two", "three", "four", "five");
72         assertNotNull(value);
73         assertEquals("[one,two,three,four,five]", value);
74     }
75
76     @Test
77     public void testPropertiesToString() {
78         String key1 = "key1";
79         String val1 = "val1";
80         String key2 = "key2";
81         String val2 = "val2";
82
83         assertEquals(null, StringHelper.propertiesToString(null));
84
85         Properties props = new Properties();
86
87         String result = StringHelper.propertiesToString(props);
88         assertNotNull(result);
89         assertEquals("[ ]", result);
90
91         props.setProperty(key1, val1);
92         result = StringHelper.propertiesToString(props);
93         assertNotNull(result);
94         assertTrue(result.contains(key1));
95         assertTrue(result.contains(val1));
96         assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma
97
98         props.setProperty(key2, val2);
99         result = StringHelper.propertiesToString(props);
100         assertNotNull(result);
101         assertTrue(result.contains(key1));
102         assertTrue(result.contains(val1));
103         assertTrue(result.contains(key2));
104         assertTrue(result.contains(val2));
105         assertTrue(result.lastIndexOf(",") < result.length() - 3); // No trailing comma
106     }
107 }