2 * Copyright 2016 Huawei Technologies Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
18 import static org.junit.Assert.*;
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;
27 import net.sf.json.JSONArray;
28 import net.sf.json.JSONObject;
30 public class VnfmUtilTest {
33 public void getVnfmByIdTestNull(){
34 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
38 public void getVnfmByIdTest(){
39 new MockUp<VnfmRestfulUtil>(){
41 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
42 RestfulResponse resp = new RestfulResponse();
44 JSONObject json = new JSONObject();
45 json.put("id", "1234");
46 resp.setResponseJson(json.toString());
50 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
54 public void getVnfmByIdTest2(){
55 new MockUp<VnfmRestfulUtil>(){
57 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
58 RestfulResponse resp = new RestfulResponse();
63 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
67 public void getVnfmIdByIpNullResp(){
68 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
69 assertEquals(resp,"");
72 public void getVnfmIdByIpInternalError(){
73 new MockUp<VnfmRestfulUtil>(){
75 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
76 RestfulResponse resp = new RestfulResponse();
81 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
82 assertEquals(resp,"");
85 public void getVnfmIdByIp(){
86 new MockUp<VnfmRestfulUtil>(){
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());
100 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
101 assertEquals(resp,"1111");
105 public void getVnfmIdByIpInvalidIP(){
106 new MockUp<VnfmRestfulUtil>(){
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());
120 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.2");
121 assertEquals(resp,"");