Code coverage should be at least 55%
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / service / csm / api / ConnectInfoTest.java
1 /*
2  * Copyright 2016 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.svnfm.vnfmadapter.service.csm.api;
18
19 import static org.junit.Assert.assertTrue;
20
21 import org.junit.Test;
22 import junit.framework.Assert;
23
24 public class ConnectInfoTest {
25
26     @Test
27     public void constructorTestNullUrl(){
28         ConnectInfo info = new ConnectInfo(null);
29         assertTrue(info.getUrl().equals(""));
30     }
31     @Test
32     public void constructorTestValidUrl(){
33         ConnectInfo info = new ConnectInfo("localhost");
34         assertTrue(info.getUrl().equals("localhost"));
35     }
36     @Test
37     public void constructorTest2NullData(){
38         ConnectInfo info = new ConnectInfo(null,null,null,null);
39         assertTrue(info.getUrl().equals("") && info.getUserName().equals("")
40                 && info.getUserPwd().equals("") && info.getAuthenticateMode().equals(""));
41     }
42     @Test
43     public void constructorTestValidData(){
44         ConnectInfo info = new ConnectInfo("localhost","user","password","auth");
45         assertTrue(info.getUrl().equals("localhost") && info.getUserName().equals("user")
46                 && info.getUserPwd().equals("password") && info.getAuthenticateMode().equals("auth"));
47     }
48     @Test
49     public void hashCodeTest(){
50         ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
51         ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
52         assertTrue(info1.hashCode() == info2.hashCode());
53     }
54
55     @Test
56     public void equalsTest(){
57         ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
58         ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
59         assertTrue(info1.equals(info2));
60     }
61     @Test
62     public void equalsTest2(){
63         ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
64         assertTrue(info1.equals(info1));
65     }
66     @Test
67     public void equalsTest3(){
68         ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
69         assertTrue(!info1.equals(null));
70     }
71     @Test
72     public void equalsTest4(){
73         ConnectInfo info1 = new ConnectInfo("localhost","user","password","auth");
74         assertTrue(!info1.equals(new Object()));
75     }
76     @Test
77     public void equalsTest5(){
78         ConnectInfo info1 = new ConnectInfo(null,"user","password","auth");
79         ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
80         assertTrue(!info1.equals(info2));
81     }
82     @Test
83     public void equalsTest6(){
84         ConnectInfo info1 = new ConnectInfo("testurl","user","password","auth");
85         ConnectInfo info2 = new ConnectInfo("localhost","user","password","auth");
86         assertTrue(!info1.equals(info2));
87     }
88         @Test
89         public void setUrlTest() throws NoSuchFieldException, IllegalAccessException {
90                 ConnectInfo connectInfo = new ConnectInfo("localhost");
91                 connectInfo.setUrl("localhost");
92                 assertTrue(connectInfo.getUrl().equals("localhost"));
93         }
94         @Test
95         public void setUserNameTest() throws NoSuchFieldException, IllegalAccessException {
96                 ConnectInfo connectInfo = new ConnectInfo("localhost");
97                 connectInfo.setUserName("user");
98                 assertTrue(connectInfo.getUserName().equals("user"));
99         }
100         @Test
101         public void setUserPwdTest() throws NoSuchFieldException, IllegalAccessException {
102                 ConnectInfo connectInfo = new ConnectInfo("localhost");
103                 connectInfo.setUserPwd("password");
104                 assertTrue(connectInfo.getUserPwd().equals("password"));
105         }
106         @Test
107         public void setAuthenticateModeTest() throws NoSuchFieldException, IllegalAccessException {
108                 ConnectInfo connectInfo = new ConnectInfo("localhost");
109                 connectInfo.setAuthenticateMode("auth");
110                 assertTrue(connectInfo.getAuthenticateMode().equals("auth"));
111         }
112         @Test
113         public void testToString() {
114         ConnectInfo connectInfo = new ConnectInfo("localhost","user","password","auth");
115                 String expected = connectInfo.toString(); 
116                 Assert.assertEquals(expected, connectInfo.toString());
117         }
118 }