summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorluxin <luxin7@huawei.com>2018-03-20 14:59:09 +0800
committerluxin <luxin7@huawei.com>2018-03-20 14:59:09 +0800
commit10bf323945c80e9f240fdb497e27a57f82d00239 (patch)
tree85fc6601c9693b013441b0449f52bc369c316bf7
parentd5163112d6dd696b7ce4e26a2ca66453682dda9f (diff)
Add test case for VnfRoa.java
Change-Id: Iad4d2abdc588c7433f092dc63abedbacd2f6cf0b Issue-ID: VFC-833 Signed-off-by: luxin <luxin7@huawei.com>
-rw-r--r--juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoaTest.java256
1 files changed, 209 insertions, 47 deletions
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoaTest.java b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoaTest.java
index 31d8bcd..9ba8f8a 100644
--- a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoaTest.java
+++ b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/service/rest/VnfRoaTest.java
@@ -13,22 +13,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertNotNull;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.core.Context;
import org.junit.Before;
import org.junit.Test;
import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.StringUtil;
+import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException;
import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.entity.JujuVnfmInfo;
import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.process.VnfMgr;
-import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.service.rest.VnfRoa;
-import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException;
import org.springframework.mock.web.MockHttpServletResponse;
import mockit.Mock;
@@ -36,16 +34,18 @@ import mockit.MockUp;
import net.sf.json.JSONObject;
public class VnfRoaTest {
-
+
VnfRoa roa = new VnfRoa();
+
@Before
- public void setUp(){
+ public void setUp() {
roa.setVnfMgr(new VnfMgr());
}
-
+
@Test
- public void addVnfTestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void addVnfTestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
@@ -57,33 +57,75 @@ public class VnfRoaTest {
String res = roa.addVnf(context, resp, vnfmId);
assertNotNull(res);
}
-
+
+ @Test
+ public void addVnfTest() throws ServiceException {
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
+ String vnfJsonStr = "{}";
+ return (T)JSONObject.fromObject(vnfJsonStr);
+ }
+ };
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject addVnf(JSONObject vnfObject, String vnfmId) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", -1);
+ return result;
+ }
+ };
+ HttpServletRequest context = null;
+ HttpServletResponse resp = new MockHttpServletResponse();
+ String vnfmId = "1234";
+ String res = roa.addVnf(context, resp, vnfmId);
+ assertNotNull(res);
+ }
+
@Test
- public void addVnfTest() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void addVnfTestSucce() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
String vnfJsonStr = "{}";
return (T)JSONObject.fromObject(vnfJsonStr);
}
};
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject addVnf(JSONObject vnfObject, String vnfmId) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", 1);
+ JSONObject data = new JSONObject();
+ data.put("result", "success");
+ result.put("data", data);
+ return result;
+ }
+ };
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
String res = roa.addVnf(context, resp, vnfmId);
assertNotNull(res);
}
+
@Test
- public void delVnfTestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void delVnfTestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
}
};
- new MockUp<VnfMgr>(){
+ new MockUp<VnfMgr>() {
+
@Mock
- private JujuVnfmInfo findByVnfId(String vnfId){
+ private JujuVnfmInfo findByVnfId(String vnfId) {
JujuVnfmInfo info = new JujuVnfmInfo();
info.setVnfmId("1234");
return info;
@@ -92,48 +134,108 @@ public class VnfRoaTest {
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.delVnf("vnfmId", resp, "vnfInstanceId",context);
+ String res = roa.delVnf("vnfmId", resp, "vnfInstanceId", context);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void delVnf2TestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
+ return null;
+ }
+ };
+ HttpServletRequest context = null;
+ HttpServletResponse resp = new MockHttpServletResponse();
+ String vnfmId = "1234";
+ String res = roa.delVnf(null, resp, "vnfInstanceId", context);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void delVnf3TestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
+ return null;
+ }
+ };
+ HttpServletRequest context = null;
+ HttpServletResponse resp = new MockHttpServletResponse();
+ String vnfmId = "1234";
+ String res = roa.delVnf(vnfmId, resp, null, context);
assertNotNull(res);
}
+
@Test
- public void delVnf2TestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void delVnfSuccess() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
}
};
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", 1);
+ JSONObject data = new JSONObject();
+ data.put("result", "success");
+ result.put("data", data);
+ return result;
+ }
+ };
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.delVnf(null, resp, "vnfInstanceId",context);
+ String res = roa.delVnf(vnfmId, resp, "vnfInstanceId", context);
assertNotNull(res);
}
+
@Test
- public void delVnf3TestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void delVnfFail() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
}
};
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject deleteVnf(String vnfId, String vnfmId, JSONObject vnfObject) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", -1);
+ return result;
+ }
+ };
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.delVnf(vnfmId, resp, null,context);
+ String res = roa.delVnf(null, resp, "vnfInstanceId", context);
assertNotNull(res);
}
+
@Test
- public void getVnf1TestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void getVnf1TestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
}
};
- new MockUp<VnfMgr>(){
+ new MockUp<VnfMgr>() {
+
@Mock
- private JujuVnfmInfo findByVnfId(String vnfId){
+ private JujuVnfmInfo findByVnfId(String vnfId) {
JujuVnfmInfo info = new JujuVnfmInfo();
info.setVnfmId("1234");
return info;
@@ -142,12 +244,67 @@ public class VnfRoaTest {
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.getVnf(vnfmId, resp, "vnfInstanceId",context);
+ String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void getVnfSuccess() throws ServiceException {
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
+ return null;
+ }
+ };
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getVnf(String vnfId, String vnfmId) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", 1);
+ JSONObject data = new JSONObject();
+ data.put("result", "success");
+ result.put("data", data);
+ return result;
+ }
+ };
+ HttpServletRequest context = null;
+ HttpServletResponse resp = new MockHttpServletResponse();
+ String vnfmId = "1234";
+ String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
+ assertNotNull(res);
+ }
+
+ @Test
+ public void getVnfFail() throws ServiceException {
+ new MockUp<StringUtil>() {
+
+ @Mock
+ public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
+ return null;
+ }
+ };
+ new MockUp<VnfMgr>() {
+
+ @Mock
+ public JSONObject getVnf(String vnfId, String vnfmId) {
+ JSONObject result = new JSONObject();
+ result.put("retCode", -1);
+ return result;
+ }
+ };
+ HttpServletRequest context = null;
+ HttpServletResponse resp = new MockHttpServletResponse();
+ String vnfmId = "1234";
+ String res = roa.getVnf(vnfmId, resp, "vnfInstanceId", context);
assertNotNull(res);
}
+
@Test
- public void getVnf2TestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void getVnf2TestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
@@ -156,12 +313,14 @@ public class VnfRoaTest {
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.getVnf(null, resp, "vnfInstanceId",context);
+ String res = roa.getVnf(null, resp, "vnfInstanceId", context);
assertNotNull(res);
}
+
@Test
- public void getVnf3TestNull() throws ServiceException{
- new MockUp<StringUtil>(){
+ public void getVnf3TestNull() throws ServiceException {
+ new MockUp<StringUtil>() {
+
@Mock
public <T> T getJsonFromContexts(HttpServletRequest vnfReq) {
return null;
@@ -170,31 +329,35 @@ public class VnfRoaTest {
HttpServletRequest context = null;
HttpServletResponse resp = new MockHttpServletResponse();
String vnfmId = "1234";
- String res = roa.getVnf(vnfmId, resp, null,context);
+ String res = roa.getVnf(vnfmId, resp, null, context);
assertNotNull(res);
}
+
@Test
- public void getJobTestNull() throws ServiceException{
+ public void getJobTestNull() throws ServiceException {
HttpServletResponse resp = new MockHttpServletResponse();
- String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
+ String res = roa.getJob("jobId", "vnfmId", resp, "responseId");
assertNotNull(res);
}
+
@Test
- public void getJobTest2Null() throws ServiceException{
+ public void getJobTest2Null() throws ServiceException {
HttpServletResponse resp = new MockHttpServletResponse();
- String res = roa.getJob(null, "vnfmId", resp,"responseId");
+ String res = roa.getJob(null, "vnfmId", resp, "responseId");
assertNotNull(res);
}
+
@Test
- public void getJobTest3Null() throws ServiceException{
+ public void getJobTest3Null() throws ServiceException {
HttpServletResponse resp = new MockHttpServletResponse();
- String res = roa.getJob("jobId", null, resp,"responseId");
+ String res = roa.getJob("jobId", null, resp, "responseId");
assertNotNull(res);
}
-
+
@Test
- public void getJobTestNormal() throws ServiceException{
- new MockUp<VnfMgr>(){
+ public void getJobTestNormal() throws ServiceException {
+ new MockUp<VnfMgr>() {
+
@Mock
public JSONObject getJob(String jobId, String vnfmId) {
JSONObject obj = new JSONObject();
@@ -205,12 +368,11 @@ public class VnfRoaTest {
obj.put("retCode", 1);
return obj;
}
-
+
};
HttpServletResponse resp = new MockHttpServletResponse();
- String res = roa.getJob("jobId", "vnfmId", resp,"responseId");
+ String res = roa.getJob("jobId", "vnfmId", resp, "responseId");
assertNotNull(res);
}
-
}