From 9478fb474be09b01d088a4831e207e24b769d164 Mon Sep 17 00:00:00 2001 From: Murali-P Date: Wed, 5 Apr 2017 16:34:33 +0530 Subject: Clear static checks Resolved:VNFSDK-21 Change-Id: I814c5391682d18a965bebb7f276e95e63d3b05b3 Signed-off-by: Murali-P --- .../org/openo/vnfsdk/functest/TaskExecution.java | 73 +++++++++++----------- .../functest/constants/ApplicationConstants.java | 37 +++++++++++ .../externalservice/entity/Environment.java | 24 +++---- .../externalservice/entity/OperationStatus.java | 7 +-- .../entity/OperationStatusHandler.java | 4 +- .../vnfsdk/functest/resource/CommonManager.java | 20 +++--- .../functest/responsehandler/TestResultParser.java | 26 ++++---- 7 files changed, 115 insertions(+), 76 deletions(-) create mode 100644 vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java (limited to 'vnf-sdk-function-test/src/main/java') diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java index 0865d03..f5d4711 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/TaskExecution.java @@ -25,6 +25,7 @@ import java.util.Map.Entry; import java.util.UUID; import org.apache.commons.lang3.SystemUtils; +import org.openo.vnfsdk.functest.constants.ApplicationConstants; import org.openo.vnfsdk.functest.externalservice.entity.Environment; import org.openo.vnfsdk.functest.externalservice.entity.EnvironmentMap; import org.openo.vnfsdk.functest.externalservice.entity.OperationStatus; @@ -42,18 +43,18 @@ public class TaskExecution { public void executeScript(String dirPath, UUID uniqueKey) { String nl = File.separator; - String curDir = System.getProperty("user.dir"); - String confDir = curDir + nl + "conf" + nl + "robot" + nl; + String curDir = System.getProperty(ApplicationConstants.USER_DIR); + String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl; // Read the MetaData from the VNF package ObjectMapper mapper = new ObjectMapper(); Map mapValues = null; try { - mapValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class); + mapValues = mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class); } catch(IOException e) { - LOGGER.error("Reading Json Meta data file failed or file do not exist", e); + LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e); return; } @@ -65,12 +66,12 @@ public class TaskExecution { String remoteScriptResult = remoteScriptDir + "/" + "output "; mapValues.put("DIR_REMOTE_RESULT", remoteScriptResult); - String dirResult = mapValues.get("DIR_RESULT") + uniqueKey; - mapValues.put("DIR_RESULT", dirResult); + String dirResult = mapValues.get(ApplicationConstants.DIR_RESULT) + uniqueKey; + mapValues.put(ApplicationConstants.DIR_RESULT, dirResult); String remoteScriptFile = remoteScriptDir + "/" + mapValues.get("MAIN_SCRIPT"); String remoteArgs = "--argumentfile " + remoteScriptDir + "/" + "config.args "; - String remoteCommand = "robot " + "-d " + remoteScriptResult + remoteArgs + remoteScriptFile; + String remoteCommand = ApplicationConstants.ROBOT_SPACE + "-d " + remoteScriptResult + remoteArgs + remoteScriptFile; mapValues.put("REMOTE_COMMAND", "\"" + remoteCommand + "\""); String robotvariables = ""; @@ -83,9 +84,9 @@ public class TaskExecution { String argumentFilePath = confDir + "config.args "; String robotScript = confDir + "RemoteConnection.robot"; - String shellcommand = "cmd.exe /c "; + String shellcommand = ApplicationConstants.SHELL_COMMAND; if(SystemUtils.IS_OS_LINUX) { - shellcommand = "bash "; + shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; } Process process = null; @@ -97,28 +98,28 @@ public class TaskExecution { process = Runtime.getRuntime().exec(command); inputStream = process.getInputStream(); while((ch = inputStream.read()) != -1) { - LOGGER.info("character ..." + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } } catch(Exception e) { - LOGGER.error("TaskExecution ... executeScript() ... [Exception] ...", e); + LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e); } } - public void executeRobotScript(UUID envId, UUID uploadId, UUID executeId, String frameworktype) { + public void executeRobotScript(UUID envId, UUID executeId, String frameworktype) { String nl = File.separator; - String curDir = System.getProperty("user.dir"); - String confDir = curDir + nl + "conf" + nl + "robot" + nl; + String curDir = System.getProperty(ApplicationConstants.USER_DIR); + String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl; // Read the MetaData from the VNF package ObjectMapper mapper = new ObjectMapper(); Map mapValues = null; try { - mapValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class); + mapValues = mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON), Map.class); } catch(IOException e) { - LOGGER.error("Reading Json Meta data file failed or file do not exist", e); + LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e); return; } @@ -128,7 +129,7 @@ public class TaskExecution { String remoteDir = functestEnv.getPath() + mapValues.get("SCRIPT_NAME"); String remoteScriptFile = remoteDir + "/" + mapValues.get("MAIN_SCRIPT"); String remoteScriptResult = remoteDir + "/" + "output "; - String dirResult = mapValues.get("DIR_RESULT") + executeId; + String dirResult = mapValues.get(ApplicationConstants.DIR_RESULT) + executeId; // set the argument parameters String remoteArgs = ""; @@ -136,33 +137,33 @@ public class TaskExecution { remoteArgs = remoteArgs + " -v " + "NODE_USERNAME" + ":" + functestEnv.getUserName() + " "; remoteArgs = remoteArgs + " -v " + "NODE_PASSWORD" + ":" + functestEnv.getPassword() + " "; - String remoteCommand = "robot " + "-d " + remoteScriptResult + remoteArgs + remoteScriptFile; + String remoteCommand = ApplicationConstants.ROBOT_SPACE + "-d " + remoteScriptResult + remoteArgs + remoteScriptFile; // set the parameters required by the execute script remoteCommand = "\"" + remoteCommand + "\""; remoteArgs = remoteArgs + " -v " + "REMOTE_COMMAND" + ":" + remoteCommand + " "; - remoteArgs = remoteArgs + " -v " + "DIR_RESULT" + ":" + dirResult + " "; + remoteArgs = remoteArgs + " -v " + ApplicationConstants.DIR_RESULT + ":" + dirResult + " "; remoteArgs = remoteArgs + " -v " + "DIR_REMOTE_RESULT" + ":" + remoteScriptResult + " "; // Execute script directory String robotScript = confDir + "execute.robot"; - String shellcommand = "cmd.exe /c "; + String shellcommand = ApplicationConstants.SHELL_COMMAND; if(SystemUtils.IS_OS_LINUX) { - shellcommand = "bash "; + shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; } Process process = null; InputStream inputStream = null; int ch; try { - String command = shellcommand + "robot" + remoteArgs + robotScript; + String command = shellcommand + ApplicationConstants.ROBOT + remoteArgs + robotScript; process = Runtime.getRuntime().exec(command); inputStream = process.getInputStream(); while((ch = inputStream.read()) != -1) { - LOGGER.info("character ..." + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } } catch(Exception e) { - LOGGER.error("TaskExecution ... executeScript() ... [Exception] ...", e); + LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e); } OperationStatus operstatus = new OperationStatus(); @@ -172,11 +173,11 @@ public class TaskExecution { OperationStatusHandler.getInstance().setOperStatusMap(executeId, operstatus); } - public void uploadScript(String dirPath, UUID UUIDEnv, UUID UUIDUpload) { + public void uploadScript(String dirPath, UUID uuidEnv, UUID uuidUpload) { String nl = File.separator; - String curDir = System.getProperty("user.dir"); - String confDir = curDir + nl + "conf" + nl + "robot" + nl; + String curDir = System.getProperty(ApplicationConstants.USER_DIR); + String confDir = curDir + nl + ApplicationConstants.CONF + nl + ApplicationConstants.ROBOT + nl; // Read the MetaData from the VNF package ObjectMapper mapper = new ObjectMapper(); @@ -184,10 +185,10 @@ public class TaskExecution { Map mapValues = null; try { - mapValues = mapper.readValue(new FileInputStream(confDir + "robotMetaData.json"), Map.class); + mapValues = mapper.readValue(new FileInputStream(confDir + ApplicationConstants.ROBOTMETADATA_JSON ), Map.class); } catch(Exception e) { - LOGGER.error("Reading Json Meta data file failed or file do not exist", e); + LOGGER.error(ApplicationConstants.JSON_METADATA_FILE_FAILED, e); return; } @@ -202,7 +203,7 @@ public class TaskExecution { } // Append the Func test environment variables - Environment functestEnv = EnvironmentMap.getInstance().getEnv(UUIDEnv); + Environment functestEnv = EnvironmentMap.getInstance().getEnv(uuidEnv); robotvariables = robotvariables + " -v " + "NODE_IP" + ":" + functestEnv.getRemoteIp() + " "; robotvariables = robotvariables + " -v " + "NODE_USERNAME" + ":" + functestEnv.getUserName() + " "; robotvariables = robotvariables + " -v " + "NODE_PASSWORD" + ":" + functestEnv.getPassword() + " "; @@ -211,31 +212,31 @@ public class TaskExecution { // Execute the command String robotScript = confDir + "upload.robot"; - String shellcommand = "cmd.exe /c "; + String shellcommand = ApplicationConstants.SHELL_COMMAND; if(SystemUtils.IS_OS_LINUX) { - shellcommand = "bash "; + shellcommand = ApplicationConstants.SHELL_COMMAND_BASH; } Process process = null; InputStream inputStream = null; int ch; try { - String command = shellcommand + "robot " + robotvariables + robotScript; + String command = shellcommand + ApplicationConstants.ROBOT_SPACE + robotvariables + robotScript; process = Runtime.getRuntime().exec(command); inputStream = process.getInputStream(); while((ch = inputStream.read()) != -1) { - LOGGER.info("character ..." + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); } } catch(Exception e) { - LOGGER.error("TaskExecution ... executeScript() ... [Exception] ...", e); + LOGGER.error(ApplicationConstants.TASKEXE_EXESCRIPT_EXCEPTION, e); } OperationStatus operstatus = new OperationStatus(); operstatus.setoResultCode(operResultCode.SUCCESS); operstatus.setOperResultMessage(""); operstatus.setOperFinished(true); - OperationStatusHandler.getInstance().setOperStatusMap(UUIDUpload, operstatus); + OperationStatusHandler.getInstance().setOperStatusMap(uuidUpload, operstatus); } diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java new file mode 100644 index 0000000..6db2ba3 --- /dev/null +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/constants/ApplicationConstants.java @@ -0,0 +1,37 @@ +/* + * Copyright 2017 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.openo.vnfsdk.functest.constants; + +public class ApplicationConstants { + + public static final String USER_DIR = "user.dir"; + public static final String ROBOT = "robot"; + public static final String ROBOT_SPACE = "robot "; + public static final String CONF = "conf"; + public static final String ROBOTMETADATA_JSON = "robotMetaData.json"; + public static final String JSON_METADATA_FILE_FAILED = "Reading Json Meta data file failed or file do not exist"; + public static final String DIR_RESULT = "DIR_RESULT"; + public static final String SCRIPT_DIR = "SCRIPT_DIR"; + public static final String DIR_REMOTE = "DIR_REMOTE"; + public static final String DIR_REMOTE_RESULT = "DIR_REMOTE_RESULT"; + public static final String MAIN_SCRIPT = "MAIN_SCRIPT"; + public static final String SHELL_COMMAND = "cmd.exe /c "; + public static final String SHELL_COMMAND_BASH = "bash "; + public static final String CHARACTER = "character ..."; + public static final String TASKEXE_EXESCRIPT_EXCEPTION = "TaskExecution ... executeScript() ... [Exception] ..."; + public static final String RUN_SCRIPT_EXECUTE_CMD = "Upload the script and execute the script and run command"; +} diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java index aba3fc8..52113b6 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/Environment.java @@ -19,6 +19,18 @@ package org.openo.vnfsdk.functest.externalservice.entity; import com.fasterxml.jackson.annotation.JsonProperty; public class Environment { + + @JsonProperty("RemoteIp") + private String RemoteIp; + + @JsonProperty("UserName") + private String UserName; + + @JsonProperty("Password") + private String Password; + + @JsonProperty("Path") + private String Path; public String getRemoteIp() { return RemoteIp; @@ -52,16 +64,6 @@ public class Environment { Path = path; } - @JsonProperty("RemoteIp") - private String RemoteIp; - - @JsonProperty("UserName") - private String UserName; - - @JsonProperty("Password") - private String Password; - - @JsonProperty("Path") - private String Path; + } diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java index 96b43af..7856563 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatus.java @@ -19,7 +19,8 @@ package org.openo.vnfsdk.functest.externalservice.entity; public class OperationStatus { private boolean operFinished = false; - + private String operResultMessage; + public enum operResultCode { SUCCESS, FAILURE, NOTFOUND }; @@ -32,9 +33,7 @@ public class OperationStatus { public void setoResultCode(operResultCode oResultCode) { this.oResultCode = oResultCode; - } - - private String operResultMessage; + } public String getOperResultMessage() { return operResultMessage; diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java index fa57c3c..7cadec4 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java @@ -46,8 +46,8 @@ public class OperationStatusHandler { return operStatusMap; } - public synchronized void setOperStatusMap(UUID uuid, OperationStatus InputOperStatusMap) { - operStatusMap.put(uuid, InputOperStatusMap); + public synchronized void setOperStatusMap(UUID uuid, OperationStatus inputOperStatusMap) { + operStatusMap.put(uuid, inputOperStatusMap); } public Response getOperationStatus(UUID uuid) { diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java index 6ab0bba..25f4072 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/resource/CommonManager.java @@ -40,6 +40,7 @@ import javax.ws.rs.core.Response; import org.eclipse.jetty.http.HttpStatus; import org.openo.vnfsdk.functest.FileUtil; import org.openo.vnfsdk.functest.TaskExecution; +import org.openo.vnfsdk.functest.constants.ApplicationConstants; import org.openo.vnfsdk.functest.externalservice.entity.Environment; import org.openo.vnfsdk.functest.externalservice.entity.EnvironmentMap; import org.openo.vnfsdk.functest.externalservice.entity.OperationStatusHandler; @@ -118,7 +119,6 @@ public class CommonManager { // Unzip the folder String tempDir = System.getProperty("user.dir") + nl + "temp"; - List list = FileUtil.unzip(filePath, tempDir); LOGGER.info("File path=" + filePath); String[] directories = FileUtil.getDirectory(tempDir); @@ -127,9 +127,9 @@ public class CommonManager { } // convert uuid string to UUID - final UUID UuidEnv = UUID.fromString(functestEnvId); + final UUID uuidEnv = UUID.fromString(functestEnvId); // generate UUID for the upload - final UUID UuidUpload = UUID.randomUUID(); + final UUID uuidUpload = UUID.randomUUID(); final String finalPath = filePath; ExecutorService es = Executors.newFixedThreadPool(3); @@ -138,16 +138,16 @@ public class CommonManager { @Override public Integer call() throws Exception { - new TaskExecution().uploadScript(finalPath, UuidEnv, UuidUpload); + new TaskExecution().uploadScript(finalPath, uuidEnv, uuidUpload); return 0; } }); // Send REST response - return RestResponseUtil.getSuccessResponse(UuidUpload); + return RestResponseUtil.getSuccessResponse(uuidUpload); } catch(IOException e) { - LOGGER.error("Upload the script and execute the script and run command", e); + LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e); } return null; @@ -168,7 +168,7 @@ public class CommonManager { try { - final UUID EnvUUID = UUID.fromString(functestEnvId); + final UUID envUUID = UUID.fromString(functestEnvId); final UUID uploadUUID = UUID.fromString(uploadId); // generate UUID for execute @@ -180,7 +180,7 @@ public class CommonManager { @Override public Integer call() throws Exception { - new TaskExecution().executeRobotScript(EnvUUID, uploadUUID, executeUUID, frameworktype); + new TaskExecution().executeRobotScript(envUUID, executeUUID, frameworktype); return 0; } }); @@ -189,7 +189,7 @@ public class CommonManager { return RestResponseUtil.getSuccessResponse(executeUUID); } catch(Exception e) { - LOGGER.error("Upload the script and execute the script and run command", e); + LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e); } return null; @@ -240,7 +240,7 @@ public class CommonManager { return RestResponseUtil.getSuccessResponse(uniqueKey.toString()); } catch(IOException e) { - LOGGER.error("Upload the script and execute the script and run command", e); + LOGGER.error(ApplicationConstants.RUN_SCRIPT_EXECUTE_CMD, e); } return null; diff --git a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java index 40a781a..7de2461 100644 --- a/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java +++ b/vnf-sdk-function-test/src/main/java/org/openo/vnfsdk/functest/responsehandler/TestResultParser.java @@ -37,17 +37,17 @@ import org.xml.sax.SAXException; public class TestResultParser { - private static final String statusPass = "PASS"; + private static final String STATUSPASS = "PASS"; - private static final String ResultTag = "test"; + private static final String RESULTTAG = "test"; - private static final String NameTag = "name"; + private static final String NAMETAG = "name"; - private static final String StatusTag = "status"; + private static final String STATUSTAG = "status"; - private static final String KwTag = "kw"; + private static final String KWTAG = "kw"; - private static final String DocTag = "doc"; + private static final String DOCTAG = "doc"; private static final Logger logger = LoggerFactory.getLogger(TestResultParser.class); @@ -64,7 +64,7 @@ public class TestResultParser { private void parseResultData(String xmlFile, List resultData) { try { Document doc = createDocument(xmlFile); - NodeList list = doc.getElementsByTagName(ResultTag); + NodeList list = doc.getElementsByTagName(RESULTTAG); for(int i = 0; i < list.getLength(); i++) { Node node = list.item(i); if(node.getNodeType() != Node.ELEMENT_NODE) { @@ -76,13 +76,13 @@ public class TestResultParser { continue; } - String nameAttr = getNodeValue(attr.getNamedItem(NameTag)); + String nameAttr = getNodeValue(attr.getNamedItem(NAMETAG)); if(null == nameAttr) { continue; } String descriptionAttr = nameAttr; - String statusAttr = statusPass; + String statusAttr = STATUSPASS; NodeList childlist = node.getChildNodes(); for(int j = 0; j < childlist.getLength(); j++) { Node childNode = childlist.item(j); @@ -90,7 +90,7 @@ public class TestResultParser { continue; } - if(KwTag == childNode.getNodeName()) { + if(KWTAG == childNode.getNodeName()) { NodeList kwNodeList = childNode.getChildNodes(); for(int k = 0; k < kwNodeList.getLength(); k++) { Node descNode = kwNodeList.item(k); @@ -98,7 +98,7 @@ public class TestResultParser { continue; } - if(DocTag == descNode.getNodeName()) { + if(DOCTAG == descNode.getNodeName()) { if(null != descNode.getTextContent()) { descriptionAttr = descNode.getTextContent(); break; @@ -107,10 +107,10 @@ public class TestResultParser { } } - if(StatusTag == childNode.getNodeName()) { + if(STATUSTAG == childNode.getNodeName()) { NamedNodeMap statusAttrMap = childNode.getAttributes(); if(null != statusAttrMap) { - statusAttr = getNodeValue(statusAttrMap.getNamedItem(StatusTag)); + statusAttr = getNodeValue(statusAttrMap.getNamedItem(STATUSTAG)); } } } -- cgit 1.2.3-korg