Fix gvnfm juju compile problem
[vfc/nfvo/driver/vnfm/gvnfm.git] / juju / juju-vnfmadapter / Juju-vnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / gvnfm / jujuvnfmadapter / common / StringUtilTest.java
1 /*
2  * Copyright 2016-2017 Huawei Technologies Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
18
19 import static org.junit.Assert.assertEquals;
20 import static org.junit.Assert.assertFalse;
21 import static org.junit.Assert.assertTrue;
22
23 import java.lang.reflect.Constructor;
24 import java.lang.reflect.Modifier;
25
26 import net.sf.json.JSONArray;
27
28 import org.junit.Test;
29 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.StringUtil;
30
31 public class StringUtilTest {
32
33     @Test
34     public void testIsValidString() {
35         boolean result = StringUtil.isValidString("abc");
36         assertTrue(result);
37     }
38
39     @Test
40     public void testIsValidString1() {
41         boolean result = StringUtil.isValidString(" abc ");
42         assertTrue(result);
43     }
44
45     @Test
46     public void testIsValidString2() {
47         boolean result = StringUtil.isValidString("  ");
48         assertFalse(result);
49     }
50
51     @Test
52     public void testIsValidString3() {
53         boolean result = StringUtil.isValidString("");
54         assertFalse(result);
55     }
56
57     @Test
58     public void testIsValidString4() {
59         boolean result = StringUtil.isValidString(null);
60         assertFalse(result);
61     }
62
63     @Test
64     public void testIsValidUrl() {
65         boolean result = StringUtil.isValidUrl("https://127.0.0.1:31943");
66         assertTrue(result);
67     }
68
69     @Test
70     public void testIsValidUrl1() {
71         boolean result = StringUtil.isValidUrl("http://255.250.255.1:31943");
72         assertTrue(result);
73     }
74
75     @Test
76     public void testIsValidUrl2() {
77         boolean result = StringUtil.isValidUrl("http:");
78         assertFalse(result);
79     }
80
81     @Test
82     public void testIsValidUrl3() {
83         boolean result = StringUtil.isValidUrl("http://255.250");
84         assertFalse(result);
85     }
86
87     @Test
88     public void testIsValidUrl4() {
89         boolean result = StringUtil.isValidUrl("");
90         assertFalse(result);
91     }
92
93     @Test
94     public void testIsValidAnyString() {
95         boolean result = StringUtil.isValidAnyString("abc", "aaa", "bbb");
96         assertTrue(result);
97     }
98
99     @Test
100     public void testIsValidAnyString1() {
101         boolean result = StringUtil.isValidAnyString("abc", "", "bbb");
102         assertFalse(result);
103     }
104
105     @Test
106     public void testTransSitesToArray() {
107         String sites = "Beijing&Shanghai";
108         JSONArray result = StringUtil.transSitesToArray(sites);
109
110         JSONArray siteArray = new JSONArray();
111         siteArray.add("Beijing");
112         siteArray.add("Shanghai");
113         assertEquals(siteArray, result);
114     }
115     @Test
116     public void testPrivateConstructor() throws Exception {
117         Constructor constructor = StringUtil.class.getDeclaredConstructor();
118         assertTrue("Constructor  private", Modifier.isPrivate(constructor.getModifiers()));
119         constructor.setAccessible(true);
120         constructor.newInstance();
121     }
122 }