From bbab5870d20823e69f8ec7afe613b54024bbeef2 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Tue, 14 Feb 2017 18:58:53 +0530 Subject: Update UT Test cases Resolved:VNFSDK-21 Function test base code Change-Id: I5183351c63d11924e576c51cb748c6c14a32bfdb Signed-off-by: Murali-P --- .../java/org/openo/vnfsdk/functest/FileUtil.java | 20 + .../VnfFuncTestResponseHandler.java | 63 +- .../functest/resource/CommonManagerTest.java | 2 +- .../59d1e651-df9f-4008-902f-e3b377e6ec30/log.html | 2109 +++++++++++++++++ .../output.xml | 30 + .../report.html | 2398 ++++++++++++++++++++ 6 files changed, 4606 insertions(+), 16 deletions(-) create mode 100644 vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/log.html create mode 100644 vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/output.xml create mode 100644 vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/report.html (limited to 'vnf-sdk-function-test/src') diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java index 6d20215..de1b809 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java @@ -228,4 +228,24 @@ public final class FileUtil { } return byteArrayFile; } + + /** + * Interface to Delete Directory + *
+ * + * @param directory + * @since VNFSDK 2.0 + */ + public static void deleteDirectory(String directory) { + File file = new File(directory); + if(!file.exists()) { + return ; + } + if (file.isDirectory()) { + for (File sub : file.listFiles()) { + deleteFile(sub); + } + } + file.delete(); + } } diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java index b165234..8fbf265 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java @@ -16,6 +16,11 @@ package org.openo.vnfsdk.functest.responsehandler; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Map; + import javax.ws.rs.core.Response; import org.openo.vnfsdk.functest.FileUtil; @@ -24,12 +29,15 @@ import org.openo.vnfsdk.functest.util.ZipCompressor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class VnfFuncTestResponseHandler { +import com.fasterxml.jackson.databind.ObjectMapper; - private static boolean deleteFileEnabled = false; +public class VnfFuncTestResponseHandler { - private static String resultPath = "D:\\Pitchi_docs\\remote\\"; + private static int actioninProgress = 21; + private static int error = 22; + private static String resultpathkey = "DIR_RESULT"; + private static Map mapConfigValues; private static VnfFuncTestResponseHandler vnfFuncRspHandler; private static final Logger logger = LoggerFactory.getLogger(VnfFuncTestResponseHandler.class); @@ -40,42 +48,67 @@ public class VnfFuncTestResponseHandler { public static VnfFuncTestResponseHandler getInstance() { if(vnfFuncRspHandler == null) { vnfFuncRspHandler = new VnfFuncTestResponseHandler(); + loadConfigurations(); } return vnfFuncRspHandler; } public Response getResponseByFuncTestId(String funcTestId) { + + if((null == mapConfigValues) || (null == mapConfigValues.get(resultpathkey))) + { + logger.warn("Result Store path not configfured !!!"); + return RestResponseUtil.getErrorResponse(error); + } + + String resultPath = mapConfigValues.get(resultpathkey); + // Check whether file Exists for the Request received !!! // ----------------------------------------------------- - String fileName = generateFilePath(funcTestId); + String fileName = resultPath + File.separator + funcTestId; if(!FileUtil.checkFileExist(fileName)) { logger.warn("Resquested function Test result not avaliable/In-Progress !!!"); - return RestResponseUtil.getErrorResponse(21); + return RestResponseUtil.getErrorResponse(actioninProgress); } - String zipFileName = resultPath + funcTestId + ".zip"; + String zipFileName = fileName + ".zip"; new ZipCompressor(zipFileName).compress(fileName); // Convert Zip-file byteCode and to response !!! // ----------------------------------------------------- byte[] byteArrayFile = FileUtil.convertZipFiletoByteArray(zipFileName); - // Delete the zip file present if Success !!! - // ---------------------------------------------- - if(deleteFileEnabled) { + if(null != byteArrayFile) { + + // Delete Result folders present if Success !!! + // ---------------------------------------------- FileUtil.deleteFile(zipFileName); - } + FileUtil.deleteDirectory(fileName); - if(null != byteArrayFile) { logger.warn("Resquested function Test result Sucess !!!"); return RestResponseUtil.getSuccessResponse(byteArrayFile); - } else { + } + else + { logger.warn("Resquested function Test result Faiuled !!!"); - return RestResponseUtil.getErrorResponse(21); + return RestResponseUtil.getErrorResponse(error); } } - private String generateFilePath(String funcTestId) { - return resultPath + "/" + funcTestId; + @SuppressWarnings("unchecked") + private static void loadConfigurations() + { + String curDir = System.getProperty("user.dir"); + String confDir = curDir + File.separator + "conf" + File.separator + "robot" + File.separator; + ObjectMapper mapper = new ObjectMapper(); + try + { + mapConfigValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class); + } + catch(IOException e) + { + logger.error("Reading Json Meta data file failed or file do not exist" + e.getMessage()); + return; + } } } diff --git a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java index 97432b0..9336abf 100644 --- a/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java +++ b/vnf-sdk-function-test/src/test/java/org/openo/vnfsdk/functest/resource/CommonManagerTest.java @@ -49,7 +49,7 @@ public class CommonManagerTest { @Test public void testQueryResultWhenInstanceIdPresent() { - Response response = commonManger.queryResultByFuncTest(instanceId); + Response response = commonManger.queryResultByFuncTest("59d1e651-df9f-4008-902f-e3b377e6ec30"); assertNotNull(response); } diff --git a/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/log.html b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/log.html new file mode 100644 index 0000000..93a9650 --- /dev/null +++ b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/log.html @@ -0,0 +1,2109 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Opening Robot Framework log failed

+
    +
  • Verify that you have JavaScript enabled in your browser.
  • +
  • Make sure you are using a modern enough browser. Firefox 3.5, IE 8, or equivalent is required, newer browsers are recommended.
  • +
  • Check are there messages in your browser's JavaScript error log. Please report the problem if you suspect you have encountered a bug.
  • +
+
+ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/output.xml b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/output.xml new file mode 100644 index 0000000..eaeb63e --- /dev/null +++ b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/output.xml @@ -0,0 +1,30 @@ + + + + + +Logs the given message with the given level. + +HelloWorld + +HelloWorld + + + + + + + + +Critical Tests +All Tests + + + + +Sample + + + + + diff --git a/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/report.html b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/report.html new file mode 100644 index 0000000..227e030 --- /dev/null +++ b/vnf-sdk-function-test/src/test/resources/59d1e651-df9f-4008-902f-e3b377e6ec30/report.html @@ -0,0 +1,2398 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+

Opening Robot Framework report failed

+
    +
  • Verify that you have JavaScript enabled in your browser.
  • +
  • Make sure you are using a modern enough browser. Firefox 3.5, IE 8, or equivalent is required, newer browsers are recommended.
  • +
  • Check are there messages in your browser's JavaScript error log. Please report the problem if you suspect you have encountered a bug.
  • +
+
+ + + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- cgit 1.2.3-korg