summaryrefslogtreecommitdiffstats
path: root/vnf-sdk-function-test/src/main/java/org
diff options
context:
space:
mode:
authorMurali-P <murali.p@huawei.com>2017-02-14 18:58:53 +0530
committerMurali-P <murali.p@huawei.com>2017-02-14 18:58:53 +0530
commitbbab5870d20823e69f8ec7afe613b54024bbeef2 (patch)
tree47caf012bf59c9cb134e2223f5a12a580c216dfe /vnf-sdk-function-test/src/main/java/org
parentd469ce9749074ceaa8d815947cb3f87a4817869e (diff)
Update UT Test cases
Resolved:VNFSDK-21 Function test base code Change-Id: I5183351c63d11924e576c51cb748c6c14a32bfdb Signed-off-by: Murali-P <murali.p@huawei.com>
Diffstat (limited to 'vnf-sdk-function-test/src/main/java/org')
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/FileUtil.java20
-rw-r--r--vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/VnfFuncTestResponseHandler.java63
2 files changed, 68 insertions, 15 deletions
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
+ * <br/>
+ *
+ * @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<String, String> 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;
+ }
}
}