From f86960874497f005079c9e595b5e9e2eb0a815d1 Mon Sep 17 00:00:00 2001 From: Seshu-Kumar-M Date: Wed, 11 Oct 2017 20:39:35 +0800 Subject: Imp Modules refactored for the readthedocs Signed-off-by: Seshu-Kumar-M IssueId: SO-209 Change-Id: Ie1b553863f824497fbe7381f66bc1581310702af --- .../openecomp/mso/adapters/vfc/VfcAdapterTest.java | 381 ++++++++++----------- .../src/test/resources/logback-test.xml | 83 ++--- 2 files changed, 224 insertions(+), 240 deletions(-) (limited to 'adapters/mso-vfc-adapter/src/test') 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 4dc8fffdc6..84991d77c8 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 @@ -43,8 +43,7 @@ import mockit.Mock; import mockit.MockUp; /** - * VF-C adapter UT - *
+ * VF-C adapter UT
*

*

* @@ -53,200 +52,194 @@ 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 - *
- * - * @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.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 - *
- * - * @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 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.
- * - * @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()); + private VfcAdapterRest vfcAdapter = new VfcAdapterRest(); + + /** + * File path + */ + private static final String FILE_PATH = "src/test/resources/json/"; + + /** + * 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.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; } - return json; + } + }; + } + + /** + * 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 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.
+ * + * @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 ""; } - /** - * 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; + 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
+ * + * @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; + } } diff --git a/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml b/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml index 26a86877bd..61d9c45543 100644 --- a/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml +++ b/adapters/mso-vfc-adapter/src/test/resources/logback-test.xml @@ -1,48 +1,39 @@ - - - - - - - - %d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n - - - - - - - - - - - - - - - - - - - - + + + + + + + + %d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}||%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}||%X{Timer}|%msg%n + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg