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 / 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 package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
17
18 import static org.junit.Assert.*;
19
20 import org.junit.Test;
21 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.VnfmUtil;
22 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil;
23 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
24
25 import mockit.Mock;
26 import mockit.MockUp;
27 import net.sf.json.JSONArray;
28 import net.sf.json.JSONObject;
29
30 public class VnfmUtilTest {
31     
32     @Test
33     public void getVnfmByIdTestNull(){ 
34         JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
35         assertNull(resp);
36     }
37     @Test
38     public void getVnfmByIdTest(){
39         new MockUp<VnfmRestfulUtil>(){
40             @Mock
41             public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
42                 RestfulResponse resp = new RestfulResponse();
43                 resp.setStatus(200);
44                 JSONObject json = new JSONObject();
45                 json.put("id", "1234");
46                 resp.setResponseJson(json.toString());
47                 return resp;
48             }
49         };
50         JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
51         assertNotNull(resp);
52     }
53     @Test
54     public void getVnfmByIdTest2(){
55         new MockUp<VnfmRestfulUtil>(){
56             @Mock
57             public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
58                 RestfulResponse resp = new RestfulResponse();
59                 resp.setStatus(500);
60                 return resp;
61             }
62         };
63         JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
64         assertNull(resp);
65     }
66     @Test
67     public void getVnfmIdByIpNullResp(){
68         String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
69         assertEquals(resp,"");
70     }
71     @Test
72     public void getVnfmIdByIpInternalError(){
73         new MockUp<VnfmRestfulUtil>(){
74             @Mock
75             public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
76                 RestfulResponse resp = new RestfulResponse();
77                 resp.setStatus(500);
78                 return resp;
79             }
80         };
81         String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
82         assertEquals(resp,"");
83     }
84     @Test
85     public void getVnfmIdByIp(){
86         new MockUp<VnfmRestfulUtil>(){
87             @Mock
88             public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
89                 RestfulResponse resp = new RestfulResponse();
90                 JSONArray jsonArray = new JSONArray();
91                 JSONObject jsonobj = new JSONObject();
92                 jsonobj.put("url", "1.1.1.1");
93                 jsonobj.put("vnfmId", "1111");
94                 jsonArray.add(jsonobj);
95                 resp.setResponseJson(jsonArray.toString());
96                 resp.setStatus(200);
97                 return resp;
98             }
99         };
100         String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
101         assertEquals(resp,"1111");
102     }
103     
104     @Test
105     public void getVnfmIdByIpInvalidIP(){
106         new MockUp<VnfmRestfulUtil>(){
107             @Mock
108             public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
109                 RestfulResponse resp = new RestfulResponse();
110                 JSONArray jsonArray = new JSONArray();
111                 JSONObject jsonobj = new JSONObject();
112                 jsonobj.put("url", "1.1.1.1");
113                 jsonobj.put("vnfmId", "1111");
114                 jsonArray.add(jsonobj);
115                 resp.setResponseJson(jsonArray.toString());
116                 resp.setStatus(200);
117                 return resp;
118             }
119         };
120         String resp = VnfmUtil.getVnfmIdByIp("1.1.1.2");
121         assertEquals(resp,"");
122     }
123
124 }