summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter
diff options
context:
space:
mode:
Diffstat (limited to 'huawei/vnfmadapter')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/RegisterConfigInfoTest.java45
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java35
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmExceptionTest.java31
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java93
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceExceptionTest.java46
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java79
6 files changed, 250 insertions, 79 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/RegisterConfigInfoTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/RegisterConfigInfoTest.java
new file mode 100644
index 00000000..276052f7
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/RegisterConfigInfoTest.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.InjectMocks;
+import org.mockito.runners.MockitoJUnitRunner;
+@RunWith(MockitoJUnitRunner.class)
+public class RegisterConfigInfoTest {
+
+ @InjectMocks
+ RegisterConfigInfo registerConfigInfo;
+
+
+
+ @Test
+ public void test() {
+ assertNotNull(registerConfigInfo.getIp());
+ assertNotNull(registerConfigInfo.getPort());
+ assertNotNull(registerConfigInfo.getProtocol());
+ assertNotNull(registerConfigInfo.getServiceName());
+ assertNotNull(registerConfigInfo.getTtl());
+ assertNotNull(registerConfigInfo.getInstance());
+ assertNotNull(registerConfigInfo.getVersion());
+ assertNotNull(registerConfigInfo.getUrl());
+ }
+
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
index 3e93f2c2..8792f528 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/ResultRequestUtilTest.java
@@ -16,9 +16,11 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.constant.Constant;
import org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.service.csm.connect.ConnectMgrVnfm;
import mockit.Mock;
@@ -36,10 +38,15 @@ public class ResultRequestUtilTest {
return 500;
}
};
+
+
JSONObject vnfmObject = new JSONObject();
String path = "http://localhost:8080";
String methodName = "get";
String paramsJson = "";
+ vnfmObject.put("url", path);
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
assertTrue(resp.get("data").equals("connect fail."));
}
@@ -91,5 +98,33 @@ public class ResultRequestUtilTest {
JSONObject resp = ResultRequestUtil.call(vnfmObject, path, methodName, paramsJson);
assertTrue(resp.get("data").equals("get connection error"));
}
+
+
+ @Test
+ public void call() {
+
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url","https://localhost:8080/%s" );
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+ String path = "https://localhost:8080/%s";
+ String methodName = "get";
+ String paramsJson = "";
+ assertNotNull(ResultRequestUtil.call( vnfmObject, path, methodName, paramsJson,
+ "authModel"));
+
+ }
+
+ @Test
+ public void callSouth() {
+ JSONObject vnfmObject = new JSONObject();
+ vnfmObject.put("url", "https://localhost:8080/%s");
+ vnfmObject.put(Constant.USERNAME, Constant.USERNAME);
+ vnfmObject.put(Constant.PASSWORD, Constant.PASSWORD);
+ String path = "https://localhost:8080/%s";
+ String methodName = "get";
+ String paramsJson = "";
+ assertNotNull(ResultRequestUtil.callSouth(vnfmObject, path, methodName, paramsJson, "authModel"));
+ }
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmExceptionTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmExceptionTest.java
new file mode 100644
index 00000000..aeb15ba8
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmExceptionTest.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common;
+
+import org.junit.Test;
+
+public class VnfmExceptionTest {
+
+ @Test
+ public void test() {
+ VnfmException vnfmException = new VnfmException();
+ VnfmException vnfmExceptionWithMessage = new VnfmException("message");
+ VnfmException vnfmExceptionWithMessageThrowable = new VnfmException("message", new Throwable());
+ VnfmException vnfmExceptionWithThrowable = new VnfmException( new Throwable());
+
+ }
+
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
index e95e9578..3cd28d7a 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/VnfmUtilTest.java
@@ -38,14 +38,14 @@ public class VnfmUtilTest {
@Test
public void getVnfmByIdTestSuccess(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// return resp;
+// }
+// };
JSONObject resp = VnfmUtil.getVnfmById("1234");
assertNotNull(resp);
}
@@ -58,55 +58,56 @@ public class VnfmUtilTest {
@Test
public void getVnfmIdByIpTestSuccess(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("url", "localhost");
- obj.put("vnfmId", "1234");
- respArray.add(obj);
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// JSONObject obj = new JSONObject();
+// obj.put("url", "localhost");
+// obj.put("vnfmId", "1234");
+// respArray.add(obj);
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("1234".equals(resp));
}
@Test
public void getVnfmIdByIpTestSuccessInvalidIP(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- JSONObject obj = new JSONObject();
- obj.put("url", "127.0.0.1");
- obj.put("vnfmId", "1234");
- respArray.add(obj);
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// JSONObject obj = new JSONObject();
+// obj.put("url", "127.0.0.1");
+// obj.put("vnfmId", "1234");
+// respArray.add(obj);
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("".equals(resp));
}
@Test
public void getVnfmIdByIpTestSuccessEmptyResp(){
- new MockUp<VnfmRestfulUtil>(){
- @Mock
- public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
- RestfulResponse resp = new RestfulResponse();
- resp.setStatus(200);
- JSONArray respArray = new JSONArray();
- resp.setResponseJson(respArray.toString());
- return resp;
- }
- };
+// new MockUp<VnfmRestfulUtil>(){
+// @Mock
+// public RestfulResponse getRemoteResponse(String url, String methodType, String params) {
+// RestfulResponse resp = new RestfulResponse();
+// resp.setStatus(200);
+// JSONArray respArray = new JSONArray();
+// resp.setResponseJson(respArray.toString());
+// return resp;
+// }
+// };
+ VnfmUtil.mockForTest("Vfnid");
String resp = VnfmUtil.getVnfmIdByIp("localhost");
assertTrue("".equals(resp));
}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceExceptionTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceExceptionTest.java
new file mode 100644
index 00000000..b3739703
--- /dev/null
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceExceptionTest.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2017 Huawei Technologies Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import mockit.integration.junit4.JMockit;
+@RunWith(JMockit.class)
+public class ServiceExceptionTest {
+
+ @Test
+ public void test() {
+ ServiceException serviceException = new ServiceException();
+ ServiceException serviceWithThrowable = new ServiceException("id",new Throwable());
+ ServiceException serviceWithThrowableMessage = new ServiceException("id","message",new Throwable());
+
+ ServiceException serviceWithMessage = new ServiceException("message");
+ ServiceException serviceWithID = new ServiceException("id","message");
+ ServiceException serviceWithHttpCode = new ServiceException("id",200);
+ ServiceException serviceWithHttpCodeAndMessage = new ServiceException(200,"message");
+ ServiceException serviceWithexceptionArgs = new ServiceException("id",200,new ExceptionArgs());
+ ServiceException serviceWithMessageThowable =new ServiceException("id","message","args","args");
+ ServiceException serviceWithThowableAndArgs =new ServiceException("id","message",new Throwable(),"args");
+ assertNotNull(serviceWithThowableAndArgs.getArgs());
+ assertNotNull(serviceWithID.getId());
+ assertNotNull(serviceWithexceptionArgs.getExceptionArgs());
+ assertNotNull(serviceWithThowableAndArgs.getArgs());
+ }
+}
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
index fec98449..60b5f639 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/servicetoken/VnfmRestfulUtilTest.java
@@ -53,51 +53,51 @@ public class VnfmRestfulUtilTest {
@Test
public void testSendReqToApp() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":1,\"data\":\"success\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":1,\"data\":\"success\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_SUCCESS, result.get("retCode"));
}
@Test
public void testSendReqToAppByErrorMsg() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":-1,\"data\":\"fail\",\"msg\":\"fail\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_FAIL, result.get("retCode"));
}
@Test
public void testSendReqToAppByError() {
- new MockUp<VnfmRestfulUtil>() {
-
- @Mock
- public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
- RestfulResponse restfulResponse = new RestfulResponse();
- restfulResponse.setStatus(Constant.HTTP_OK);
- String responseString = "{\"retCode\":-1,\"data\":\"fail\"}";
- restfulResponse.setResponseJson(responseString);
- return restfulResponse;
- }
- };
+// new MockUp<VnfmRestfulUtil>() {
+//
+// @Mock
+// public RestfulResponse getRestResByDefault(String path, String methodNames, JSONObject bodyParam) {
+// RestfulResponse restfulResponse = new RestfulResponse();
+// restfulResponse.setStatus(Constant.HTTP_OK);
+// String responseString = "{\"retCode\":-1,\"data\":\"fail\"}";
+// restfulResponse.setResponseJson(responseString);
+// return restfulResponse;
+// }
+// };
JSONObject result = VnfmRestfulUtil.sendReqToApp("path", "put", new JSONObject());
assertEquals(Constant.REST_FAIL, result.get("retCode"));
}
@@ -238,4 +238,17 @@ public class VnfmRestfulUtilTest {
RestfulResponse resp = VnfmRestfulUtil.getRemoteResponse("/test/123", "", "test123");
assertNull(resp);
}
+
+ @Test
+ public void getRemoteResponse() {
+ Map <String, String > headerMap = new HashMap<String, String>();
+
+ VnfmRestfulUtil.getRemoteResponse( "url", "get", headerMap,"params");
+ VnfmRestfulUtil.getRemoteResponse( "url", "post", headerMap,"params");
+ VnfmRestfulUtil.getRemoteResponse( "url", "put", headerMap,"params");
+ assertNull(VnfmRestfulUtil.getRemoteResponse( "url", "delete", headerMap,"params"));
+
+
+
+ }
}