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.openo.nfvo.jujuvnfmadapter.common;
18 import static org.junit.Assert.*;
20 import org.junit.Test;
21 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
22 import org.openo.nfvo.jujuvnfmadapter.common.servicetoken.VnfmRestfulUtil;
26 import net.sf.json.JSONArray;
27 import net.sf.json.JSONObject;
29 public class VnfmUtilTest {
32 public void getVnfmByIdTestNull(){
33 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
37 public void getVnfmByIdTest(){
38 new MockUp<VnfmRestfulUtil>(){
40 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
41 RestfulResponse resp = new RestfulResponse();
43 JSONObject json = new JSONObject();
44 json.put("id", "1234");
45 resp.setResponseJson(json.toString());
49 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
53 public void getVnfmByIdTest2(){
54 new MockUp<VnfmRestfulUtil>(){
56 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
57 RestfulResponse resp = new RestfulResponse();
62 JSONObject resp = VnfmUtil.getVnfmById("vnfmId");
66 public void getVnfmIdByIpNullResp(){
67 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
68 assertEquals(resp,"");
71 public void getVnfmIdByIpInternalError(){
72 new MockUp<VnfmRestfulUtil>(){
74 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
75 RestfulResponse resp = new RestfulResponse();
80 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
81 assertEquals(resp,"");
84 public void getVnfmIdByIp(){
85 new MockUp<VnfmRestfulUtil>(){
87 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
88 RestfulResponse resp = new RestfulResponse();
89 JSONArray jsonArray = new JSONArray();
90 JSONObject jsonobj = new JSONObject();
91 jsonobj.put("url", "1.1.1.1");
92 jsonobj.put("vnfmId", "1111");
93 jsonArray.add(jsonobj);
94 resp.setResponseJson(jsonArray.toString());
99 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.1");
100 assertEquals(resp,"1111");
104 public void getVnfmIdByIpInvalidIP(){
105 new MockUp<VnfmRestfulUtil>(){
107 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
108 RestfulResponse resp = new RestfulResponse();
109 JSONArray jsonArray = new JSONArray();
110 JSONObject jsonobj = new JSONObject();
111 jsonobj.put("url", "1.1.1.1");
112 jsonobj.put("vnfmId", "1111");
113 jsonArray.add(jsonobj);
114 resp.setResponseJson(jsonArray.toString());
119 String resp = VnfmUtil.getVnfmIdByIp("1.1.1.2");
120 assertEquals(resp,"");