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.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
19 import static org.junit.Assert.*;
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;
28 import net.sf.json.JSONArray;
29 import net.sf.json.JSONObject;
31 public class VnfmUtilTest {
34 public void getVnfmByIdTestNullResp(){
35 JSONObject resp = VnfmUtil.getVnfmById("1234");
40 public void getVnfmByIdTestSuccess(){
41 // new MockUp<VnfmRestfulUtil>(){
43 // public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
44 // RestfulResponse resp = new RestfulResponse();
45 // resp.setStatus(200);
49 JSONObject resp = VnfmUtil.getVnfmById("1234");
54 public void getVnfmIdByIpTestNullResp(){
55 String resp = VnfmUtil.getVnfmIdByIp("localhost");
56 assertTrue("".equals(resp));
60 public void getVnfmIdByIpTestSuccess(){
61 // new MockUp<VnfmRestfulUtil>(){
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());
75 String resp = VnfmUtil.getVnfmIdByIp("localhost");
76 assertTrue("1234".equals(resp));
80 public void getVnfmIdByIpTestSuccessInvalidIP(){
81 // new MockUp<VnfmRestfulUtil>(){
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());
95 String resp = VnfmUtil.getVnfmIdByIp("localhost");
96 assertTrue("".equals(resp));
99 public void getVnfmIdByIpTestSuccessEmptyResp(){
100 // new MockUp<VnfmRestfulUtil>(){
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());
110 VnfmUtil.mockForTest("Vfnid");
111 String resp = VnfmUtil.getVnfmIdByIp("localhost");
112 assertTrue("".equals(resp));