From a95b0a47c3dd4c1f6717022275a87699db80a661 Mon Sep 17 00:00:00 2001 From: Kailun Qin Date: Thu, 13 Sep 2018 22:33:29 +0800 Subject: Sonar: code clean up for functest Use built-in format specifiers instead of string concatenation. Change-Id: I4b4c2e41ce03401a753b290e4a6a90ae65127ed3 Issue-ID: VNFSDK-320 Signed-off-by: Kailun Qin --- .../src/main/java/org/onap/vnfsdk/functest/FileUtil.java | 16 ++++++++-------- .../java/org/onap/vnfsdk/functest/TaskExecution.java | 16 ++++++++-------- .../externalservice/entity/OperationStatusHandler.java | 4 ++-- .../functest/responsehandler/TestResultParser.java | 4 ++-- .../onap/vnfsdk/functest/scriptmgr/ScriptManager.java | 10 +++++----- .../org/onap/vnfsdk/functest/taskmgr/TaskManager.java | 4 ++-- .../org/onap/vnfsdk/functest/util/ZipCompressor.java | 4 ++-- 7 files changed, 29 insertions(+), 29 deletions(-) diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java index d10a7b9..ad3049c 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/FileUtil.java @@ -71,13 +71,13 @@ public final class FileUtil { boolean isFileExist = file.exists(); if (!isFileExist) { if (isFileDeleted) { - LOG.info("delete " + hintInfo + file.getAbsolutePath()); + LOG.info("delete {} {}", hintInfo, file.getAbsolutePath()); } else { isFileDeleted = true; - LOG.info("file not exist. no need delete " + hintInfo + file.getAbsolutePath()); + LOG.info("file not exist. no need delete {} {}", hintInfo, file.getAbsolutePath()); } } else { - LOG.info("fail to delete " + hintInfo + file.getAbsolutePath()); + LOG.info("fail to delete {} {}", hintInfo, file.getAbsolutePath()); } return isFileDeleted; } @@ -119,12 +119,12 @@ public final class FileUtil { } unzipFileNams.add(file.getAbsolutePath()); } catch (Exception ex) { - LOG.error("close InputStream error!: " + ex); - LOG.error("close OutputStream error!: " + ex); + LOG.error("close InputStream error!: {}", ex); + LOG.error("close OutputStream error!: {}", ex); } } } catch (Exception ex) { - LOG.error("close ZipFile error!: " + ex); + LOG.error("close ZipFile error!: ", ex); throw new IOException(ex); } return unzipFileNams; @@ -163,9 +163,9 @@ public final class FileUtil { byte[] byteArrayFile = new byte[(int) file.length()]; try (FileInputStream fileInputStream = new FileInputStream(filename)) { int value = fileInputStream.read(byteArrayFile); - LOG.debug("Number of bytes read from fileInputStream = " + value); + LOG.debug("Number of bytes read from fileInputStream = {}", value); } catch (Exception e) { - LOG.error("convertZipFiletoByteArray: " + e); + LOG.error("convertZipFiletoByteArray: {}", e); } return byteArrayFile; } diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java index 8796baa..344e458 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/TaskExecution.java @@ -88,7 +88,7 @@ public class TaskExecution { int ch; try { String command = "robot --argumentfile " + argumentFilePath + robotvariables + " " + robotScript; - LOGGER.info("Command execute to execute the script:" + command); + LOGGER.info("Command execute to execute the script: {}.", command); process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command}); if (process != null) { process.waitFor(); @@ -96,7 +96,7 @@ public class TaskExecution { } if (inputStream != null){ while ((ch = inputStream.read()) != -1) { - LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER, ch); } } } catch (Exception e) { @@ -134,14 +134,14 @@ public class TaskExecution { // Get environment of given UUID Environment functestEnv = EnvironmentMap.getInstance().getEnv(envId); if (null != functestEnv) { - LOGGER.info("Function Test Environment path,Path = " + functestEnv.getPath()); + LOGGER.info("Function Test Environment path,Path = {}", functestEnv.getPath()); remoteDir = functestEnv.getPath() + mapValues.get("SCRIPT_NAME"); // set the argument parameters remoteArgs = remoteArgs + " -v " + "NODE_IP" + ":" + functestEnv.getRemoteIp() + " "; remoteArgs = remoteArgs + " -v " + "NODE_USERNAME" + ":" + functestEnv.getUserName() + " "; remoteArgs = remoteArgs + " -v " + "NODE_PASSWORD" + ":" + functestEnv.getPassword() + " "; } else { - LOGGER.error("Function Test Environment details are empty,EnvID = " + envId); + LOGGER.error("Function Test Environment details are empty, EnvID = {}", envId); } String remoteConfigArgs = remoteDir + "/" + "config.args "; @@ -167,7 +167,7 @@ public class TaskExecution { int ch; try { String command = ApplicationConstants.ROBOT + remoteArgs + robotScript; - LOGGER.info("Command execute to execute the script:" + command); + LOGGER.info("Command execute to execute the script: {}", command); process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command}); if (process != null) { process.waitFor(); @@ -175,7 +175,7 @@ public class TaskExecution { } if (inputStream != null) { while ((ch = inputStream.read()) != -1) { - LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER, ch); } } } catch (Exception e) { @@ -238,7 +238,7 @@ public class TaskExecution { int ch; try { String command = ApplicationConstants.ROBOT_SPACE + robotvariables + robotScript; - LOGGER.info("Command execute to upload the script:" + command); + LOGGER.info("Command execute to upload the script: {}.", command); process = Runtime.getRuntime().exec(new String[]{getShellCommand(), getShellArg(), command}); if (process != null) { process.waitFor(); @@ -246,7 +246,7 @@ public class TaskExecution { } if (inputStream != null) { while ((ch = inputStream.read()) != -1) { - LOGGER.info(ApplicationConstants.CHARACTER + Integer.toString(ch)); + LOGGER.info(ApplicationConstants.CHARACTER, ch); } } } catch (Exception e) { diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java index 7ba71cb..af511be 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/externalservice/entity/OperationStatusHandler.java @@ -54,8 +54,8 @@ public class OperationStatusHandler { if (getOperStatusMap().containsKey(uuid)) { OperationStatus operstatus = getOperStatusMap().get(uuid); - LOGGER.info("Operation Finished?" + operstatus.isOperFinished()); - LOGGER.info("Operation Result Message" + operstatus.getOperResultMessage()); + LOGGER.info("Operation Finished? {}", operstatus.isOperFinished()); + LOGGER.info("Operation Result Message: {}.", operstatus.getOperResultMessage()); return RestResponseUtil.getSuccessResponse(operstatus); } else { diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java index f226695..feeb2ee 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/responsehandler/TestResultParser.java @@ -54,7 +54,7 @@ public class TestResultParser { public List populateResultList(String taskID, String xmlFile) { List resultData = new ArrayList<>(); if (!FileUtil.checkFileExist(xmlFile)) { - logger.error("File Not Found !!! :" + xmlFile); + logger.error("File Not Found !!! : {}", xmlFile); return resultData; } parseResultData(taskID, xmlFile, resultData); @@ -126,7 +126,7 @@ public class TestResultParser { TestResultMap.getInstance().setTestResultMap(UUID.fromString(taskID), resultData); } catch (ParserConfigurationException | SAXException | IOException e) { - logger.error("Exception while parsing file :" + xmlFile); + logger.error("Exception while parsing file : {}", xmlFile); logger.error("Exception while parsing file :", e); } } diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java index 8553110..534bb20 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/scriptmgr/ScriptManager.java @@ -66,7 +66,7 @@ public class ScriptManager { public static String storeChunkFileInLocal(String dirName, String fileName, InputStream uploadedInputStream) throws IOException { File tmpDir = new File(dirName); - LOGGER.info("tmpdir=" + dirName); + LOGGER.info("tmpdir={}", dirName); if (!tmpDir.exists()) { tmpDir.mkdirs(); } @@ -132,10 +132,10 @@ public class ScriptManager { // Unzip the folder String tempDir = System.getProperty("user.dir") + nl + "temp"; List list = FileUtil.unzip(filePath, tempDir); - LOGGER.info("File path=" + filePath); + LOGGER.info("File path={}", filePath); String[] directories = FileUtil.getDirectory(tempDir); - LOGGER.info("tempdir=" + tempDir); + LOGGER.info("tempdir={}", tempDir); if (null != directories && 0 != directories.length) { filePath = tempDir + File.separator + directories[0]; } else { @@ -192,13 +192,13 @@ public class ScriptManager { } public Response getOperationResult(UUID operID) { - LOGGER.info("[Script Manager] Query functest Status by ID." + operID); + LOGGER.info("[Script Manager] Query functest Status by ID: {}.", operID); return OperationStatusHandler.getInstance().getOperationStatus(operID); } public Response downloadResults(UUID taskID) { - LOGGER.info("[Script Manager] Download functest Result by ID: " + taskID); + LOGGER.info("[Script Manager] Download functest Result by ID: {}.", taskID); Response resp = VnfFuncTestResponseHandler.getInstance().downloadResults(taskID.toString()); diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java index 79e611b..fc5e36c 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/taskmgr/TaskManager.java @@ -111,7 +111,7 @@ public class TaskManager { @Timed @UnitOfWork public Response queryTestStatus(@ApiParam(value = "taskID") @PathParam("taskID") String taskID) { - LOGGER.info("[Task Manager] Query Function Test Status by ID: " + taskID); + LOGGER.info("[Task Manager] Query Function Test Status by ID: {}.", taskID); try { @@ -166,7 +166,7 @@ public class TaskManager { @Timed @UnitOfWork public Response collectTaskResult(@ApiParam(value = "taskID") @PathParam("taskID") String taskID) { - LOGGER.info("[Task Manager] Collect Function Test Result by ID." + taskID); + LOGGER.info("[Task Manager] Collect Function Test Result by ID: {}.", taskID); try { CaseRecord caseRecord = taskMgrCaseTblDAO.findByTaskID(taskID); diff --git a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java index 30fee60..6f866b8 100644 --- a/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java +++ b/vnf-sdk-function-test/src/main/java/org/onap/vnfsdk/functest/util/ZipCompressor.java @@ -60,10 +60,10 @@ public class ZipCompressor { private void compress(File file, ZipOutputStream out, String basedir) { if (file.isDirectory()) { - LOG.info("compress: " + basedir + file.getName()); + LOG.info("compress: {} {}", basedir, file.getName()); this.compressDirectory(file, out, basedir); } else { - LOG.info("compress: " + basedir + file.getName()); + LOG.info("compress: {} {}", basedir, file.getName()); this.compressFile(file, out, basedir); } } -- cgit 1.2.3-korg