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.
17 package org.openo.nfvo.vnfmadapter.common;
19 import static org.junit.Assert.*;
21 import org.junit.Test;
22 import org.openo.baseservice.roa.util.restclient.RestfulResponse;
23 import org.openo.nfvo.vnfmadapter.common.servicetoken.VnfmRestfulUtil;
27 import net.sf.json.JSONArray;
28 import net.sf.json.JSONObject;
30 public class VnfmUtilTest {
33 public void getVnfmByIdTestNullResp(){
34 JSONObject resp = VnfmUtil.getVnfmById("1234");
39 public void getVnfmByIdTestSuccess(){
40 new MockUp<VnfmRestfulUtil>(){
42 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
43 RestfulResponse resp = new RestfulResponse();
48 JSONObject resp = VnfmUtil.getVnfmById("1234");
53 public void getVnfmIdByIpTestNullResp(){
54 String resp = VnfmUtil.getVnfmIdByIp("localhost");
55 assertTrue("".equals(resp));
59 public void getVnfmIdByIpTestSuccess(){
60 new MockUp<VnfmRestfulUtil>(){
62 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
63 RestfulResponse resp = new RestfulResponse();
65 JSONArray respArray = new JSONArray();
66 JSONObject obj = new JSONObject();
67 obj.put("url", "localhost");
68 obj.put("vnfmId", "1234");
70 resp.setResponseJson(respArray.toString());
74 String resp = VnfmUtil.getVnfmIdByIp("localhost");
75 assertTrue("1234".equals(resp));
79 public void getVnfmIdByIpTestSuccessInvalidIP(){
80 new MockUp<VnfmRestfulUtil>(){
82 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
83 RestfulResponse resp = new RestfulResponse();
85 JSONArray respArray = new JSONArray();
86 JSONObject obj = new JSONObject();
87 obj.put("url", "127.0.0.1");
88 obj.put("vnfmId", "1234");
90 resp.setResponseJson(respArray.toString());
94 String resp = VnfmUtil.getVnfmIdByIp("localhost");
95 assertTrue("".equals(resp));
98 public void getVnfmIdByIpTestSuccessEmptyResp(){
99 new MockUp<VnfmRestfulUtil>(){
101 public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
102 RestfulResponse resp = new RestfulResponse();
104 JSONArray respArray = new JSONArray();
105 resp.setResponseJson(respArray.toString());
109 String resp = VnfmUtil.getVnfmIdByIp("localhost");
110 assertTrue("".equals(resp));