From 4671cbb50f4520924696f0fea3fe8471f6fbe811 Mon Sep 17 00:00:00 2001
From: c00149107
Date: Fri, 15 Sep 2017 16:54:46 +0800
Subject: Add UT for create service
Create service UT implement
Change-Id: Ie9f1abbe730195b94796ca9cabb5e385c5dd0ea8
Issue-ID:SO-133
Signed-off-by: c00149107
---
adapters/mso-vfc-adapter/pom.xml | 24 ++-
.../openecomp/mso/adapters/vfc/VfcAdapterRest.java | 98 +++++----
.../org/openecomp/mso/adapters/vfc/VfcManager.java | 13 +-
.../vfc/exceptions/ApplicationException.java | 45 ++++-
.../openecomp/mso/adapters/vfc/util/JsonUtil.java | 19 +-
.../mso/adapters/vfc/util/ValidateUtil.java | 5 +-
.../openecomp/mso/adapters/vfc/VfcAdapterTest.java | 225 +++++++++++++++------
7 files changed, 301 insertions(+), 128 deletions(-)
(limited to 'adapters')
diff --git a/adapters/mso-vfc-adapter/pom.xml b/adapters/mso-vfc-adapter/pom.xml
index 4f049c350f..7cb8eeacec 100644
--- a/adapters/mso-vfc-adapter/pom.xml
+++ b/adapters/mso-vfc-adapter/pom.xml
@@ -33,13 +33,18 @@
-
+
+ javax.ws.rs
+ javax.ws.rs-api
+ 2.0
+
+
org.openecomp.so.adapters
mso-adapter-utils
${project.version}
@@ -83,6 +88,10 @@
mso-requests-db
${project.version}
+
+ commons-io
+ commons-io
+
org.jmockit
jmockit
@@ -101,5 +110,16 @@
1.19
test
+
+ org.glassfish.jersey.core
+ jersey-common
+ 2.22.2
+ test
+
+
+ javax.servlet
+ javax.servlet-api
+ 3.1.0
+
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
index 1be5bab1c3..438393bc35 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcAdapterRest.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.mso.adapters.vfc;
import javax.servlet.http.HttpServletRequest;
@@ -29,6 +30,7 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
+import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
import org.openecomp.mso.adapters.vfc.model.NSResourceInputParameter;
import org.openecomp.mso.adapters.vfc.model.NsOperationKey;
import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
@@ -44,7 +46,7 @@ import org.openecomp.mso.logger.MsoLogger;
*
*
* @author
- * @version ONAP Amsterdam Release 2017-08-28
+ * @version ONAP Amsterdam Release 2017-08-28
*/
@Path("/v1/vfcdrivers")
public class VfcAdapterRest {
@@ -53,6 +55,10 @@ public class VfcAdapterRest {
private final VfcManager driverMgr = new VfcManager();
+ public VfcAdapterRest() {
+
+ }
+
/**
* Create a NS
*
@@ -67,12 +73,16 @@ public class VfcAdapterRest {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response createNfvoNs(HttpServletRequest servletReq) {
// Step 1: get parameters from request for current node
- String body = RestfulUtil.getRequestBody(servletReq);
- ValidateUtil.assertObjectNotNull(body);
- LOGGER.debug("body from request is {}" + body);
- NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
- RestfulResponse rsp = driverMgr.createNs(nsInput);
- return buildResponse(rsp);
+ try {
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
+ RestfulResponse rsp = driverMgr.createNs(nsInput);
+ return buildResponse(rsp);
+ } catch(ApplicationException e) {
+ return e.buildErrorResponse();
+ }
}
/**
@@ -87,14 +97,17 @@ public class VfcAdapterRest {
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response deleteNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
- // Step 1: get parameters from request for current node
- String body = RestfulUtil.getRequestBody(servletReq);
- ValidateUtil.assertObjectNotNull(body);
- LOGGER.debug("body from request is {}" + body);
- NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
-
- RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
- return buildResponse(rsp);
+ try {
+ // Step 1: get parameters from request for current node
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+ RestfulResponse rsp = driverMgr.deleteNs(nsOperationKey, nsInstanceId);
+ return buildResponse(rsp);
+ } catch(ApplicationException e) {
+ return e.buildErrorResponse();
+ }
}
/**
@@ -102,7 +115,7 @@ public class VfcAdapterRest {
*
*
* @param servletReq The Http Request
- * @param jobId The job id
+ * @param jobId The job id
* @return
* @since ONAP Amsterdam Release
*/
@@ -111,15 +124,19 @@ public class VfcAdapterRest {
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response queryNfvoJobStatus(HttpServletRequest servletReq, @PathParam("jobId") String jobId) {
- ValidateUtil.assertObjectNotNull(jobId);
- String body = RestfulUtil.getRequestBody(servletReq);
- ValidateUtil.assertObjectNotNull(body);
- LOGGER.debug("body from request is {}" + body);
- NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
- RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
- return buildResponse(rsp);
- }
+ try {
+ ValidateUtil.assertObjectNotNull(jobId);
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+ RestfulResponse rsp = driverMgr.getNsProgress(nsOperationKey, jobId);
+ return buildResponse(rsp);
+ } catch(ApplicationException e) {
+ return e.buildErrorResponse();
+ }
+ }
/**
* Instantiate NS instance
@@ -136,11 +153,15 @@ public class VfcAdapterRest {
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response instantiateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
String body = RestfulUtil.getRequestBody(servletReq);
- ValidateUtil.assertObjectNotNull(body);
- LOGGER.debug("body from request is {}" + body);
- NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
- RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
- return buildResponse(rsp);
+ try {
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NSResourceInputParameter nsInput = JsonUtil.unMarshal(body, NSResourceInputParameter.class);
+ RestfulResponse rsp = driverMgr.instantiateNs(nsInstanceId, nsInput);
+ return buildResponse(rsp);
+ } catch(ApplicationException e) {
+ return e.buildErrorResponse();
+ }
}
/**
@@ -157,16 +178,19 @@ public class VfcAdapterRest {
@Consumes({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
public Response terminateNfvoNs(HttpServletRequest servletReq, @PathParam("nsInstanceId") String nsInstanceId) {
- ValidateUtil.assertObjectNotNull(nsInstanceId);
- String body = RestfulUtil.getRequestBody(servletReq);
- ValidateUtil.assertObjectNotNull(body);
- LOGGER.debug("body from request is {}" + body);
- NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
- RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
- return buildResponse(rsp);
+ try {
+ ValidateUtil.assertObjectNotNull(nsInstanceId);
+ String body = RestfulUtil.getRequestBody(servletReq);
+ ValidateUtil.assertObjectNotNull(body);
+ LOGGER.debug("body from request is {}" + body);
+ NsOperationKey nsOperationKey = JsonUtil.unMarshal(body, NsOperationKey.class);
+ RestfulResponse rsp = driverMgr.terminateNs(nsOperationKey, nsInstanceId);
+ return buildResponse(rsp);
+ } catch(ApplicationException e) {
+ return e.buildErrorResponse();
+ }
}
-
/**
* build response from restful response
*
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
index 171949aa8e..f463f5e344 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/VfcManager.java
@@ -71,6 +71,9 @@ public class VfcManager {
nfvoUrlMap.put(Step.QUERY, CommonConstant.NFVO_QUERY_URL);
}
+ public VfcManager(){
+
+ }
/**
* create network service
*
@@ -79,7 +82,7 @@ public class VfcManager {
* @return
* @since ONAP Amsterdam Release
*/
- public RestfulResponse createNs(NSResourceInputParameter segInput) {
+ public RestfulResponse createNs(NSResourceInputParameter segInput) throws ApplicationException {
// Step1: get service template by node type
String nsdId = segInput.getNsOperationKey().getNodeTemplateId();
@@ -143,7 +146,7 @@ public class VfcManager {
* @return
* @since ONAP Amsterdam Release
*/
- public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) {
+ public RestfulResponse deleteNs(NsOperationKey nsOperationKey, String nsInstanceId) throws ApplicationException{
LOGGER.info("delete ns -> begin");
// Step1: prepare url and methodType
String url = getUrl(nsInstanceId, CommonConstant.Step.DELETE);
@@ -190,7 +193,7 @@ public class VfcManager {
* @return
* @since ONAP Amsterdam Release
*/
- public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) {
+ public RestfulResponse instantiateNs(String nsInstanceId, NSResourceInputParameter segInput) throws ApplicationException{
// Call the NFVO or SDNO service to instantiate service
LOGGER.info("instantiate ns -> begin");
@@ -254,7 +257,7 @@ public class VfcManager {
* @return
* @since ONAP Amsterdam Release
*/
- public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) {
+ public RestfulResponse terminateNs(NsOperationKey nsOperationKey, String nsInstanceId) throws ApplicationException{
// Step1: save segment operation info for delete process
LOGGER.info("save segment operation for delete process");
ResourceOperationStatus nsOperInfo = (RequestsDatabase.getInstance()).getResourceOperationStatus(nsOperationKey.getServiceId(),
@@ -319,7 +322,7 @@ public class VfcManager {
* @return
* @since ONAP Amsterdam Release
*/
- public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) {
+ public RestfulResponse getNsProgress(NsOperationKey nsOperationKey, String jobId) throws ApplicationException{
ValidateUtil.assertObjectNotNull(jobId);
// Step 1: query the current resource operation status
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java
index 6a78d2e73e..61966d07f2 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/exceptions/ApplicationException.java
@@ -17,19 +17,22 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.mso.adapters.vfc.exceptions;
-import javax.ws.rs.WebApplicationException;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
+import javax.ws.rs.core.Response;;
-public class ApplicationException extends WebApplicationException {
+public class ApplicationException extends Exception {
/**
* Serial number.
*/
private static final long serialVersionUID = 1L;
+ private int errorCode;
+
+ private String errorMsg;
+
/**
* Constructor
*
@@ -37,9 +40,37 @@ public class ApplicationException extends WebApplicationException {
*
* @param errorCode error status
* @param errorDetail error detail
- * @since ONAP Amsterdam Release 2017-9-6
+ * @since ONAP Amsterdam Release 2017-9-6
+ */
+ public ApplicationException(int errorCode, String errorMsg) {
+ this.errorCode = errorCode;
+ this.errorMsg = errorMsg;
+ }
+
+ public int getErrorCode() {
+ return errorCode;
+ }
+
+ public void setErrorCode(int errorCode) {
+ this.errorCode = errorCode;
+ }
+
+ public String getErrorMsg() {
+ return errorMsg;
+ }
+
+ public void setErrorMsg(String errorMsg) {
+ this.errorMsg = errorMsg;
+ }
+
+ /**
+ * build error Response
+ *
+ *
+ * @return
+ * @since ONAP Amsterdam Release
*/
- public ApplicationException(int errorCode, Object errorDetail) {
- super(Response.status(errorCode).entity(errorDetail).type(MediaType.APPLICATION_JSON).build());
+ public Response buildErrorResponse() {
+ return Response.status(errorCode).entity(errorMsg).build();
}
}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java
index 34beb02c13..a9546d5c4c 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/JsonUtil.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.mso.adapters.vfc.util;
import java.io.IOException;
@@ -29,7 +30,6 @@ import org.openecomp.mso.adapters.vfc.exceptions.ApplicationException;
import org.openecomp.mso.logger.MessageEnum;
import org.openecomp.mso.logger.MsoLogger;
-
/**
* Interface for json analyzing.
*
@@ -43,7 +43,7 @@ public class JsonUtil {
/**
* Log service
*/
- private static final MsoLogger LOGGER = MsoLogger.getMsoLogger (MsoLogger.Catalog.RA);
+ private static final MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.RA);
/**
* Mapper.
@@ -75,11 +75,12 @@ public class JsonUtil {
* @return model object
* @since ONAP Amsterdam Release 2017-9-6
*/
- public static T unMarshal(String jsonstr, Class type) {
+ public static T unMarshal(String jsonstr, Class type) throws ApplicationException {
try {
return MAPPER.readValue(jsonstr, type);
} catch(IOException e) {
- LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to unMarshal json", e);
+ LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError,
+ "fail to unMarshal json", e);
throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json");
}
}
@@ -92,11 +93,12 @@ public class JsonUtil {
* @return model object
* @since ONAP Amsterdam Release 2017-9-6
*/
- public static T unMarshal(String jsonstr, TypeReference type) {
+ public static T unMarshal(String jsonstr, TypeReference type) throws ApplicationException {
try {
return MAPPER.readValue(jsonstr, type);
} catch(IOException e) {
- LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to unMarshal json", e);
+ LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError,
+ "fail to unMarshal json", e);
throw new ApplicationException(HttpCode.BAD_REQUEST, "fail to unMarshal json");
}
}
@@ -108,11 +110,12 @@ public class JsonUtil {
* @return json string
* @since ONAP Amsterdam Release 2017-9-6
*/
- public static String marshal(Object srcObj) {
+ public static String marshal(Object srcObj) throws ApplicationException {
try {
return MAPPER.writeValueAsString(srcObj);
} catch(IOException e) {
- LOGGER.error(MessageEnum.RA_NS_EXC, "","", MsoLogger.ErrorCode.BusinessProcesssError, "fail to marshal json", e);
+ LOGGER.error(MessageEnum.RA_NS_EXC, "", "", MsoLogger.ErrorCode.BusinessProcesssError,
+ "fail to marshal json", e);
throw new ApplicationException(HttpCode.BAD_REQUEST, "srcObj marshal failed!");
}
}
diff --git a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java
index 37228c805c..a6fa2d29e2 100644
--- a/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java
+++ b/adapters/mso-vfc-adapter/src/main/java/org/openecomp/mso/adapters/vfc/util/ValidateUtil.java
@@ -17,6 +17,7 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
+
package org.openecomp.mso.adapters.vfc.util;
import org.openecomp.mso.adapters.vfc.constant.HttpCode;
@@ -49,7 +50,7 @@ public class ValidateUtil {
* @param name of parameter
* @since ONAP Amsterdam Release 2017-9-6
*/
- public static void assertStringNotNull(String paramValue, String paramName) {
+ public static void assertStringNotNull(String paramValue, String paramName) throws ApplicationException {
if(null != paramValue && !paramValue.isEmpty()) {
return;
}
@@ -64,7 +65,7 @@ public class ValidateUtil {
* @param object data object
* @since ONAP Amsterdam Release 2017-9-6
*/
- public static void assertObjectNotNull(Object object) {
+ public static void assertObjectNotNull(Object object) throws ApplicationException {
if(null == object) {
LOGGER.error("Object is null.");
throw new ApplicationException(HttpCode.BAD_REQUEST, "Object is null.");
diff --git a/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java b/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java
index 46ab134bce..4c316f3196 100644
--- a/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java
+++ b/adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java
@@ -17,17 +17,29 @@
* limitations under the License.
* ============LICENSE_END=========================================================
*/
-package org.openecomp.mso.adapters.vfc;
+package org.openecomp.mso.adapters.vfc;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
-import org.mockito.Mock;
+import org.openecomp.mso.adapters.vfc.constant.CommonConstant;
+import org.openecomp.mso.adapters.vfc.constant.HttpCode;
+import org.openecomp.mso.adapters.vfc.model.RestfulResponse;
import org.openecomp.mso.adapters.vfc.util.RestfulUtil;
import org.openecomp.mso.adapters.vfc.util.ValidateUtil;
-import org.openecomp.mso.db.catalog.CatalogDatabase;
+import org.openecomp.mso.requestsdb.RequestsDatabase;
+import org.openecomp.mso.requestsdb.ResourceOperationStatus;
+import mockit.Mock;
import mockit.MockUp;
/**
@@ -37,89 +49,150 @@ import mockit.MockUp;
*
*
* @author
- * @version ONAP Amsterdam Release 2017-08-31
+ * @version ONAP Amsterdam Release 2017-08-31
*/
public class VfcAdapterTest {
- @Mock
- private static CatalogDatabase db;
+ private VfcAdapterRest vfcAdapter = new VfcAdapterRest();
/**
* File path
*/
private static final String FILE_PATH = "src/test/resources/json/";
- @Test
- public void createTest () {
-// // get request
-// mockGetRequestBody(FILE_PATH + "createNfvoNsReq.json");
-// // get service template
-// ServiceTemplate svcTmpl = new ServiceTemplate();
-// svcTmpl.setId("id");
-// svcTmpl.setServiceTemplateId("svcTmplId");
-// new MockUp() {
-// @Mock
-// public ServiceTemplate getSvcTmplByNodeType(String nodeType, String domainHost){
-// return svcTmpl;
-// }
-// };
-// // get response
-// RestfulResponse restRsp = new RestfulResponse();
-// restRsp.setStatus(HttpStatus.SC_OK);
-// restRsp.setResponseJson(getJsonString(FILE_PATH + "createNfvoNsRsp.json"));
-// mockGetRestfulRsp(restRsp);
-// // insert data
-// new MockUp() {
-// @Mock
-// public void insertSegment(ServiceSegmentModel serviceSegment) {
-// // do nothing
-// }
-// @Mock
-// public void insertSegmentOper(ServiceSegmentOperation svcSegmentOper) {
-// // do nothing
-// }
-// };
-// Response rsp = impl.createNfvoNs(servletReq);
-// JSONObject obj = JSONObject.fromObject(rsp.getEntity());
-// Assert.assertEquals(null, "1", obj.getString("nsInstanceId"));
+ /**
+ * Mock the request body form a file
+ *
+ *
+ * @param fileName
+ * @since ONAP Amsterdam Release
+ */
+ private void mockRestfulUtil(String fileName) {
+ new MockUp() {
+
+ /**
+ * mock get request body
+ *
+ *
+ * @param request
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Mock
+ public String getRequestBody(HttpServletRequest request) {
+ return getJsonString(fileName);
+ }
+
+ /**
+ * mock get send method
+ *
+ *
+ * @param url
+ * @param methodType
+ * @param content
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Mock
+ public RestfulResponse send(String url, String methodType, String content) {
+ if(url.contains(CommonConstant.NFVO_CREATE_URL) && methodType.equals(CommonConstant.MethodType.POST)) {
+ return getResponse("createNsRsp.json");
+ } else {
+ return null;
+ }
+ }
+ };
+ }
+
+ /**
+ * Mock the request body form a file
+ *
+ *
+ * @param fileName
+ * @since ONAP Amsterdam Release
+ */
+ private void mockRequestDatabase() {
+ new MockUp() {
+
+ /**
+ * mock get resource operation status
+ *
+ *
+ * @param request
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ @Mock
+ public ResourceOperationStatus getResourceOperationStatus(String serviceId, String operationId,
+ String resourceTemplateUUID) {
+ ResourceOperationStatus resStatus = new ResourceOperationStatus();
+ resStatus.setServiceId("111");
+ resStatus.setOperationId("111");
+ return resStatus;
+ }
+
+ /**
+ * Mock update Res Oper Status
+ *
+ *
+ * @param operStatus
+ * @since ONAP Amsterdam Release
+ */
+ @Mock
+ public void updateResOperStatus(ResourceOperationStatus operStatus) {
+
+ }
+ };
+ }
+
+ /**
+ * Before executing UT, start mock requst database
+ *
+ *
+ * @since ONAP Amsterdam Release
+ */
+ @Before
+ public void start() {
+ mockRequestDatabase();
+ }
+
+ /**
+ * After executing UT, close session
+ *
+ * @since ONAP Amsterdam Release
+ */
+ @After
+ public void stop() {
+
}
@Test
- public void deleteTest () {
-
+ public void createTest() {
+ // get request
+ mockRestfulUtil(FILE_PATH + "createNsReq.json");
+ vfcAdapter.createNfvoNs(null);
}
@Test
- public void instantiateTest () {
+ public void deleteTest() {
}
@Test
- public void terminateTest () {
-
+ public void instantiateTest() {
+
}
@Test
- public void queryJobTest () {
+ public void terminateTest() {
}
-
- /**
- * Mock to get request body.
- *
- * @param file json file path.
- * @since ONAP Amsterdam Release 2017-9-6
- */
- private void mockGetRequestBody(final String file) {
- new MockUp() {
-// @Mock
-// public String getRequestBody(HttpServletRequest request) {
-// return getJsonString(file);
-// }
- };
+ @Test
+ public void queryJobTest() {
+
}
-
+
/**
* Get json string from file.
*
@@ -128,19 +201,37 @@ public class VfcAdapterTest {
* @throws IOException when fail to read
* @since ONAP Amsterdam Release 2017-9-6
*/
+ @SuppressWarnings("deprecation")
private String getJsonString(final String file) {
if(ValidateUtil.isStrEmpty(file)) {
return "";
}
String json = null;
-// try {
-// FileInputStream fileStream = new FileInputStream(new File(file));
-// json = IOUtils.toString(fileStream);
-// } catch(Exception e) {
-// Assert.fail(e.getMessage());
-// }
-
+ try {
+ FileInputStream fileStream = new FileInputStream(new File(file));
+ json = IOUtils.toString(fileStream);
+ } catch(Exception e) {
+ Assert.fail(e.getMessage());
+ }
return json;
}
+
+ /**
+ * get the response from file
+ *
+ *
+ * @param fileName
+ * @return
+ * @since ONAP Amsterdam Release
+ */
+ private RestfulResponse getResponse(String fileName) {
+ RestfulResponse responseSuccess = new RestfulResponse();
+ responseSuccess.setStatus(HttpCode.RESPOND_OK);
+ if(null != fileName) {
+ String jsonStr = getJsonString(FILE_PATH + fileName);
+ responseSuccess.setResponseContent(jsonStr);
+ }
+ return responseSuccess;
+ }
}
--
cgit 1.2.3-korg