Junit coverage increased
[vfc/nfvo/driver/vnfm/svnfm.git] / huawei / vnfmadapter / VnfmadapterService / service / src / test / java / org / onap / vfc / nfvo / vnfm / svnfm / vnfmadapter / common / VnfmUtilTest.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.common;
18
19 import static org.junit.Assert.*;
20
21 import org.junit.Test;
22 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.VnfmUtil;
23 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
24 import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient.RestfulResponse;
25
26 import mockit.Mock;
27 import mockit.MockUp;
28 import net.sf.json.JSONArray;
29 import net.sf.json.JSONObject;
30
31 public class VnfmUtilTest {
32
33     @Test
34     public void getVnfmByIdTestNullResp(){
35         JSONObject resp = VnfmUtil.getVnfmById("1234");
36         assertNull(resp);
37     }
38
39     @Test
40     public void getVnfmByIdTestSuccess(){
41 //        new MockUp<VnfmRestfulUtil>(){
42 //            @Mock
43 //            public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
44 //                RestfulResponse resp = new RestfulResponse();
45 //                resp.setStatus(200);
46 //                return resp;
47 //            }
48 //        };
49         JSONObject resp = VnfmUtil.getVnfmById("1234");
50         assertNotNull(resp);
51     }
52
53     @Test
54     public void getVnfmIdByIpTestNullResp(){
55         String resp = VnfmUtil.getVnfmIdByIp("localhost");
56         assertTrue("".equals(resp));
57     }
58
59     @Test
60     public void getVnfmIdByIpTestSuccess(){
61 //        new MockUp<VnfmRestfulUtil>(){
62 //            @Mock
63 //            public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
64 //                RestfulResponse resp = new RestfulResponse();
65 //                resp.setStatus(200);
66 //                JSONArray respArray = new JSONArray();
67 //                JSONObject obj = new JSONObject();
68 //                obj.put("url", "localhost");
69 //                obj.put("vnfmId", "1234");
70 //                respArray.add(obj);
71 //                resp.setResponseJson(respArray.toString());
72 //                return resp;
73 //            }
74 //        };
75         String resp = VnfmUtil.getVnfmIdByIp("localhost");
76         assertTrue("1234".equals(resp));
77     }
78
79     @Test
80     public void getVnfmIdByIpTestSuccessInvalidIP(){
81 //        new MockUp<VnfmRestfulUtil>(){
82 //            @Mock
83 //            public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
84 //                RestfulResponse resp = new RestfulResponse();
85 //                resp.setStatus(200);
86 //                JSONArray respArray = new JSONArray();
87 //                JSONObject obj = new JSONObject();
88 //                obj.put("url", "127.0.0.1");
89 //                obj.put("vnfmId", "1234");
90 //                respArray.add(obj);
91 //                resp.setResponseJson(respArray.toString());
92 //                return resp;
93 //            }
94 //        };
95         String resp = VnfmUtil.getVnfmIdByIp("localhost");
96         assertTrue("".equals(resp));
97     }
98     @Test
99     public void getVnfmIdByIpTestSuccessEmptyResp(){
100 //        new MockUp<VnfmRestfulUtil>(){
101 //            @Mock
102 //            public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
103 //                RestfulResponse resp = new RestfulResponse();
104 //                resp.setStatus(200);
105 //                JSONArray respArray = new JSONArray();
106 //                resp.setResponseJson(respArray.toString());
107 //                return resp;
108 //            }
109 //        };
110         VnfmUtil.mockForTest("Vfnid");
111         String resp = VnfmUtil.getVnfmIdByIp("localhost");
112         assertTrue("".equals(resp));
113     }
114
115 }