diff options
author | c00149107 <chenchuanyu@huawei.com> | 2017-10-18 11:48:21 +0800 |
---|---|---|
committer | c00149107 <chenchuanyu@huawei.com> | 2017-10-19 14:12:16 +0800 |
commit | a13d6f4c3dd6d4c38d1f9cd97ac9fd377f580a4b (patch) | |
tree | a370ad9261b9cde7455a1cc3bf80444a58ecf5ce /adapters/mso-vfc-adapter/src/test/java | |
parent | 61354fab1e3c8783fd6a2ff5fcf7d1997fd999b5 (diff) |
Deal With Error Response from Vfc
Deal With Error Response from Vfc
Change-Id: Id5ce999d561099581b49524969c901ac6dac3f90
Issue-ID:SO-233
Signed-off-by: c00149107 <chenchuanyu@huawei.com>
Diffstat (limited to 'adapters/mso-vfc-adapter/src/test/java')
-rw-r--r-- | adapters/mso-vfc-adapter/src/test/java/org/openecomp/mso/adapters/vfc/VfcAdapterTest.java | 369 |
1 files changed, 182 insertions, 187 deletions
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 84991d77c8..95d3bf610f 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 @@ -24,8 +24,6 @@ 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; @@ -52,194 +50,191 @@ import mockit.MockUp; */ public class VfcAdapterTest { - private VfcAdapterRest vfcAdapter = new VfcAdapterRest(); - - /** - * File path - */ - private static final String FILE_PATH = "src/test/resources/json/"; - - /** - * Mock the request body form a file <br> - * - * @param fileName - * @since ONAP Amsterdam Release - */ - private void mockRestfulUtil(String fileName) { - new MockUp<RestfulUtil>() { - - /** - * mock get request body <br> - * - * @param request - * @return - * @since ONAP Amsterdam Release - */ - @Mock - public String getRequestBody(HttpServletRequest request) { + private VfcAdapterRest vfcAdapter = new VfcAdapterRest(); + + /** + * File path + */ + private static final String FILE_PATH = "src/test/resources/json/"; + + /** + * mock get request body <br> + * + * @param request + * @return + * @since ONAP Amsterdam Release + */ + public String getRequestBody(String fileName) { return getJsonString(fileName); - } - - /** - * mock get send method <br> - * - * @param url - * @param methodType - * @param content - * @return - * @since ONAP Amsterdam Release - */ - @Mock - public RestfulResponse send(String url, String methodType, String content) { - if (url.equals(CommonConstant.NFVO_CREATE_URL) - && methodType.equals(CommonConstant.MethodType.POST)) { - return getResponse("createNsRsp.json"); - } else if (url.contains("instantiate") - && methodType.equals(CommonConstant.MethodType.POST)) { - return getResponse("instantiateNsRsp.json"); - } else if (methodType.equals(CommonConstant.MethodType.DELETE)) { - return getResponse(null); - } else if (url.contains("terminate") && methodType.equals(CommonConstant.MethodType.POST)) { - return getResponse("terminateNsRsp.json"); - } else if (url.contains("/api/nslcm/v1/jobs") - && methodType.equals(CommonConstant.MethodType.GET)) { - return getResponse("queryJobRsp.json"); - } else { - return null; - } - } - }; - } - - /** - * Mock the request body form a file <br> - * - * @param fileName - * @since ONAP Amsterdam Release - */ - private void mockRequestDatabase() { - new MockUp<RequestsDatabase>() { - - /** - * mock get resource operation status <br> - * - * @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 <br> - * - * @param operStatus - * @since ONAP Amsterdam Release - */ - @Mock - public void updateResOperStatus(ResourceOperationStatus operStatus) { - - } - }; - } - - /** - * Before executing UT, start mock requst database <br> - * - * @since ONAP Amsterdam Release - */ - @Before - public void start() { - mockRequestDatabase(); - } - - /** - * After executing UT, close session<br/> - * - * @since ONAP Amsterdam Release - */ - @After - public void stop() { - - } - - @Test - public void createTest() { - // get request - mockRestfulUtil(FILE_PATH + "createNsReq.json"); - vfcAdapter.createNfvoNs(null); - } - - @Test - public void deleteTest() { - // get request - mockRestfulUtil(FILE_PATH + "deleteNsReq.json"); - vfcAdapter.deleteNfvoNs(null, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); - } - - @Test - public void instantiateTest() { - // get request - mockRestfulUtil(FILE_PATH + "instantiateNsReq.json"); - vfcAdapter.instantiateNfvoNs(null, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); - } - - @Test - public void terminateTest() { - mockRestfulUtil(FILE_PATH + "terminateNsReq.json"); - vfcAdapter.terminateNfvoNs(null, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); - } - - @Test - public void queryJobTest() { - mockRestfulUtil(FILE_PATH + "queryJobReq.json"); - vfcAdapter.queryNfvoJobStatus(null, "1"); - } - - /** - * Get json string from file.<br/> - * - * @param file the path of file - * @return json string - * @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()); + /** + * Mock the request body form a file <br> + * + * @param fileName + * @since ONAP Amsterdam Release + */ + private void mockRestfulUtil() { + new MockUp<RestfulUtil>() { + + /** + * mock get send method <br> + * + * @param url + * @param methodType + * @param content + * @return + * @since ONAP Amsterdam Release + */ + @Mock + public RestfulResponse send(String url, String methodType, String content) { + if(url.equals(CommonConstant.NFVO_CREATE_URL) && methodType.equals(CommonConstant.MethodType.POST)) { + return getResponse("createNsRsp.json"); + } else if(url.contains("instantiate") && methodType.equals(CommonConstant.MethodType.POST)) { + return getResponse("instantiateNsRsp.json"); + } else if(methodType.equals(CommonConstant.MethodType.DELETE)) { + return getResponse(null); + } else if(url.contains("terminate") && methodType.equals(CommonConstant.MethodType.POST)) { + return getResponse("terminateNsRsp.json"); + } else if(url.contains("/api/nslcm/v1/jobs") && methodType.equals(CommonConstant.MethodType.GET)) { + return getResponse("queryJobRsp.json"); + } else { + return null; + } + } + }; + } + + /** + * Mock the request body form a file <br> + * + * @param fileName + * @since ONAP Amsterdam Release + */ + private void mockRequestDatabase() { + new MockUp<RequestsDatabase>() { + + /** + * mock get resource operation status <br> + * + * @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 <br> + * + * @param operStatus + * @since ONAP Amsterdam Release + */ + @Mock + public void updateResOperStatus(ResourceOperationStatus operStatus) { + + } + }; + } + + /** + * Before executing UT, start mock requst database <br> + * + * @since ONAP Amsterdam Release + */ + @Before + public void start() { + mockRequestDatabase(); + mockRestfulUtil(); + } + + /** + * After executing UT, close session<br/> + * + * @since ONAP Amsterdam Release + */ + @After + public void stop() { + + } + + @Test + public void createTest() { + // get request + String createReq = getRequestBody(FILE_PATH + "createNsReq.json"); + vfcAdapter.createNfvoNs(createReq); + } + + @Test + public void deleteTest() { + // get request + String req = getRequestBody(FILE_PATH + "deleteNsReq.json"); + vfcAdapter.deleteNfvoNs(req, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); } - return json; - } - - /** - * get the response from file <br> - * - * @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); + + @Test + public void instantiateTest() { + // get request + String req = getRequestBody(FILE_PATH + "instantiateNsReq.json"); + vfcAdapter.instantiateNfvoNs(req, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); + } + + @Test + public void terminateTest() { + String req = getRequestBody(FILE_PATH + "terminateNsReq.json"); + vfcAdapter.deleteNfvoNs(req, "9b9f02c0-298b-458a-bc9c-be3692e4f354"); + } + + @Test + public void queryJobTest() { + String req = getRequestBody(FILE_PATH + "queryJobReq.json"); + vfcAdapter.queryNfvoJobStatus(req, "1"); + } + + /** + * Get json string from file.<br/> + * + * @param file the path of file + * @return json string + * @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()); + } + return json; + } + + /** + * get the response from file <br> + * + * @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; } - return responseSuccess; - } } |