summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKanagaraj Manickam <kanagaraj.manickam@huawei.com>2020-07-01 04:48:14 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-01 04:48:14 +0000
commit022ee4b8daa1b852d72c1083658d1efb254f9dd5 (patch)
tree3acfd05d04321b7684579b0259c2f9303f35868c
parent29308f5f904e6bfd92204137357fe350d40cf083 (diff)
parent268be523fb1142138a3f710642b5773453841eeb (diff)
Merge "code improvements"
-rw-r--r--framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommand.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java4
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java14
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java161
-rw-r--r--framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java2
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java20
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java41
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java32
-rw-r--r--framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java10
-rw-r--r--framework/src/test/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommandTest.java23
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java14
-rw-r--r--grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java10
-rw-r--r--grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java8
-rw-r--r--main/src/main/java/org/onap/cli/main/OnapCli.java2
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java20
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java4
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java30
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java31
-rw-r--r--profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java2
-rw-r--r--profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java2
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java2
-rw-r--r--validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java2
26 files changed, 268 insertions, 208 deletions
diff --git a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommand.java b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommand.java
index 8d29c03f..d77c021a 100644
--- a/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommand.java
+++ b/framework/src/main/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommand.java
@@ -60,27 +60,27 @@ public class OnapCommandExceutionShowCommand extends OnapCommand {
}
- public String printExecution(List<OnapCommandExecutionStore.Execution> executions) throws OnapCommandExecutionNotFound {
- String msg = "<oclip-execution-list>\n";
+ public String printExecution(List<OnapCommandExecutionStore.Execution> executions) throws OnapCommandExecutionNotFound { //NOSONAR
+ StringBuilder msg = new StringBuilder("<oclip-execution-list>\n");
for (OnapCommandExecutionStore.Execution e: executions) {
- msg += "<oclip-execution>\n";
+ msg.append("<oclip-execution>\n");
if ( e.getId() != null)
- msg += "<oclip-request-id>\n" + e.getId() + "</oclip-request-id>\n";
- msg += "<oclip-request-product>\n" + e.getProduct() + "</oclip-request-product>\n";
- msg += "<oclip-request-service>\n" + e.getService() + "</oclip-request-service>\n";
- msg += "<oclip-request-command>\n" + e.getCommand() + "</oclip-request-command>\n";
+ msg.append("<oclip-request-id>\n" + e.getId() + "</oclip-request-id>\n");
+ msg.append("<oclip-request-product>\n" + e.getProduct() + "</oclip-request-product>\n");
+ msg.append("<oclip-request-service>\n" + e.getService() + "</oclip-request-service>\n");
+ msg.append("<oclip-request-command>\n" + e.getCommand() + "</oclip-request-command>\n");
if ( e.getProfile() != null)
- msg += "<oclip-request-profile>\n" + e.getProfile() + "</oclip-request-profile>\n";
- msg += "<oclip-request-input>\n" + e.getInput() + "</oclip-request-input>\n";
+ msg.append("<oclip-request-profile>\n" + e.getProfile() + "</oclip-request-profile>\n");
+ msg.append("<oclip-request-input>\n" + e.getInput() + "</oclip-request-input>\n");
if ( e.getOutput() != null)
- msg += "<oclip-request-output>\n" + e.getOutput() + "</oclip-request-output>\n";
- msg += "<oclip-request-start-time>\n" + e.getStartTime() + "</oclip-request-start-time>\n";
- msg += "<oclip-request-end-time>\n" + e.getEndTime() + "</oclip-request-end-time>\n";
- msg += "<oclip-request-status>\n" + e.getStatus() + "</oclip-request-status>\n";
- msg += "</oclip-execution>";
+ msg.append("<oclip-request-output>\n" + e.getOutput() + "</oclip-request-output>\n");
+ msg.append("<oclip-request-start-time>\n" + e.getStartTime() + "</oclip-request-start-time>\n");
+ msg.append("<oclip-request-end-time>\n" + e.getEndTime() + "</oclip-request-end-time>\n");
+ msg.append("<oclip-request-status>\n" + e.getStatus() + "</oclip-request-status>\n");
+ msg.append("</oclip-execution>");
}
- msg += "</oclip-execution-list>";
+ msg.append("</oclip-execution-list>");
- return msg;
+ return msg.toString();
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
index 6771bfee..c23ed2bc 100644
--- a/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
+++ b/framework/src/main/java/org/onap/cli/fw/registrar/OnapCommandRegistrar.java
@@ -129,7 +129,7 @@ public class OnapCommandRegistrar {
}
this.registry.put(name + ":" + version, cmd);
- log.info("REGISITER : " + name + ":" + version + " = " + cmd.getCanonicalName());
+ log.info("REGISITER : {} : {} = {}", name, version, cmd.getCanonicalName());
this.availableProductVersions.add(version);
}
@@ -292,7 +292,7 @@ public class OnapCommandRegistrar {
for (OnapCommandSchemaInfo schema : schemas) {
if (schema.isIgnore()) {
- log.info("Ignoring schema " + schema.getSchemaURI());
+ log.info("Ignoring schema {}", schema.getSchemaURI());
continue;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
index d87f4ef9..14032ef5 100644
--- a/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
+++ b/framework/src/main/java/org/onap/cli/fw/schema/OnapCommandSchemaInfo.java
@@ -47,7 +47,7 @@ public class OnapCommandSchemaInfo implements Comparable<OnapCommandSchemaInfo>
private String product;
- private List<String> sampleFiles = new ArrayList();
+ private List<String> sampleFiles = new ArrayList<>();
/**
* OCS version
@@ -71,7 +71,7 @@ public class OnapCommandSchemaInfo implements Comparable<OnapCommandSchemaInfo>
private List<Object> outputs = new ArrayList<>();
- private Map<String, String> metadata = new HashMap();
+ private Map<String, String> metadata = new HashMap<>();
private String description;
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
index fa1d50fc..5938a11d 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandArtifactStore.java
@@ -164,7 +164,7 @@ public class OnapCommandArtifactStore {
return DatatypeConverter.printHexBinary(hash);
}
- public Artifact createArtifact(Artifact artifact) throws OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist, OnapCommandArtifactContentChecksumNotMatch {
+ public Artifact createArtifact(Artifact artifact) throws OnapCommandArtifactContentNotExist, OnapCommandArtifactAlreadyExist, OnapCommandArtifactContentChecksumNotMatch { //NOSONAR
if (!new File(artifact.getPath()).exists()) {
throw new OnapCommandArtifactContentNotExist(artifact.getPath());
}
@@ -187,7 +187,7 @@ public class OnapCommandArtifactStore {
FileUtils.writeStringToFile(new File(storePath), gson.toJson(artifact));
} catch (Exception e) { // NOSONAR
//It is expected that this never occurs
- log.error("Failed to store the artifact at " + storePath);
+ log.error("Failed to store the artifact at {}", storePath);
}
return artifact;
@@ -204,13 +204,13 @@ public class OnapCommandArtifactStore {
return gson.fromJson(FileUtils.readFileToString(aFile), Artifact.class);
} catch (Exception e) { // NOSONAR
//It is expected that this never occurs
- log.error("Failed to retrieve the artifact at " + storePath);
+ log.error("Failed to retrieve the artifact at {}", storePath);
}
return null;
}
- public List<Artifact> listArtifact(String category, String namePattern) throws OnapCommandArtifactNotFound {
+ public List<Artifact> listArtifact(String category, String namePattern) throws OnapCommandArtifactNotFound { //NOSONAR
List<Artifact> artifacts = new ArrayList<>();
String searchPattern = "";
@@ -242,7 +242,7 @@ public class OnapCommandArtifactStore {
artifacts.add(gson.fromJson(jsonReader, Artifact.class));
} catch (Exception e) { // NOSONAR
//It is expected that this never occurs
- log.error("While seraching Failed to retrieve the artifact at " + file.getAbsolutePath());
+ log.error("While seraching Failed to retrieve the artifact at {}", file.getAbsolutePath());
}
}
@@ -256,7 +256,7 @@ public class OnapCommandArtifactStore {
throw new OnapCommandArtifactNotFound(name, category);
}
if(!aFile.delete()){
- log.error("Failed to delete the artifact " + aFile.getAbsolutePath());
+ log.error("Failed to delete the artifact {}", aFile.getAbsolutePath());
}
}
@@ -316,7 +316,7 @@ public class OnapCommandArtifactStore {
}
} catch (Exception e) { // NOSONAR
//It is expected that this never occurs
- log.error("Failed to update the artifact at " + existingStorePath);
+ log.error("Failed to update the artifact at {}", existingStorePath);
}
return artifact;
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
index a22eb084..9e230ff3 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandExecutionStore.java
@@ -40,6 +40,19 @@ public class OnapCommandExecutionStore {
private static Logger log = LoggerFactory.getLogger(OnapCommandExecutionStore.class);
private static boolean storeReady = false;
+ private static String REQUEST_ID = "requestId";
+ private static String EXECUTION_ID = "executionId";
+ private static String INPUT = "input";
+ private static String STDOUT = "stdout";
+ private static String STDERR = "stderr";
+ private static String DEBUG = "debug";
+ private static String IN_PROGRESS = "in-progress";
+ private static String OUTPUT = "output";
+ private static String ERROR = "error";
+ private static String COMPLETED = "completed";
+ private static String FAILED = "failed";
+ private static String EXECUTIONID = "execution-id";
+ private static String REQUESTID = "request-id";
private SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS", Locale.US);
@@ -222,30 +235,30 @@ public class OnapCommandExecutionStore {
context.setStorePath(dir.getAbsolutePath());
if (product != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "product"), product);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OnapCommandConstants.INFO_PRODUCT), product);
if (service != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "service"), service);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OnapCommandConstants.INFO_SERVICE), service);
if (cmd != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "command"), cmd);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OnapCommandConstants.RPC_CMD), cmd);
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "requestId"), requestId);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + REQUEST_ID), requestId);
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "executionId"), executionId);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + EXECUTION_ID), executionId);
if (input != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "input"), input);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + INPUT), input);
if (profile != null) {
context.setProfile(profile);
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "profile"), profile);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OnapCommandConstants.RPC_PROFILE), profile);
}
- FileUtils.touch(new File(context.getStorePath() + File.separator + "stdout"));
- FileUtils.touch(new File(context.getStorePath() + File.separator + "stderr"));
- FileUtils.touch(new File(context.getStorePath() + File.separator + "debug"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + STDOUT));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + STDERR));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + DEBUG));
- FileUtils.touch(new File(context.getStorePath() + File.separator + "in-progress"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + IN_PROGRESS));
} catch (IOException e) {
- log.error("Failed to store the execution start details " + storePath);
+ log.error("Failed to store the execution start details {}", storePath);
}
return context;
@@ -257,21 +270,21 @@ public class OnapCommandExecutionStore {
try {
if (output != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OUTPUT), output);
if (error != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + ERROR), error);
if (debug != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + DEBUG), debug);
if (passed)
- FileUtils.touch(new File(context.getStorePath() + File.separator + "completed"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + COMPLETED));
else
- FileUtils.touch(new File(context.getStorePath() + File.separator + "failed"));
+ FileUtils.touch(new File(context.getStorePath() + File.separator + FAILED));
- if(!new File(context.getStorePath() + File.separator + "in-progress").delete()){
- log.error("Failed to delete "+ context.getStorePath() + File.separator + "in-progress");
+ if(!new File(context.getStorePath() + File.separator + IN_PROGRESS).delete()){
+ log.error("Failed to delete {}", context.getStorePath() + File.separator + IN_PROGRESS);
}
} catch (IOException e) {
- log.error("Failed to store the execution end details " + context.storePath);
+ log.error("Failed to store the execution end details {}", context.storePath);
}
}
@@ -281,13 +294,13 @@ public class OnapCommandExecutionStore {
try {
if (output != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OUTPUT), output);
if (error != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "error"), error);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + ERROR), error);
if (debug != null)
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + DEBUG), debug);
} catch (IOException e) {
- log.error("Failed to store the execution end details " + context.storePath);
+ log.error("Failed to store the execution end details {}", context.storePath);
}
}
@@ -297,10 +310,10 @@ public class OnapCommandExecutionStore {
try {
if (debug != null) {
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "debug"), debug);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + DEBUG), debug);
}
} catch (IOException e) {
- log.error("Failed to store the execution debug details " + context.storePath);
+ log.error("Failed to store the execution debug details {}", context.storePath);
}
}
@@ -310,10 +323,10 @@ public class OnapCommandExecutionStore {
try {
if (output != null) {
- FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + "output"), output);
+ FileUtils.writeStringToFile(new File(context.getStorePath() + File.separator + OUTPUT), output);
}
} catch (IOException e) {
- log.error("Failed to store the execution output details " + context.storePath);
+ log.error("Failed to store the execution output details {}", context.storePath);
}
}
public List<OnapCommandExecutionStore.Execution> listExecutions(Map<String, String> search) throws OnapCommandExecutionFailed {
@@ -323,15 +336,15 @@ public class OnapCommandExecutionStore {
List <String> dirs = new ArrayList<>();
if (System.getProperty("os.name").toLowerCase().startsWith("windows") || SEARCH_MODE.equals(SearchMode.file)) {
for (File f: new File(getBasePath()).listFiles()) {
- if(search.containsKey("execution-id")) {
- if (f.getName().startsWith(search.get("execution-id")))
+ if(search.containsKey(EXECUTIONID)) {
+ if (f.getName().startsWith(search.get(EXECUTIONID)))
dirs.add(f.getAbsolutePath());
continue;
}
- if(search.containsKey("request-id")) {
- if (f.getName().startsWith(search.get("request-id")))
+ if(search.containsKey(REQUESTID)) {
+ if (f.getName().startsWith(search.get(REQUESTID)))
dirs.add(f.getAbsolutePath());
continue;
@@ -344,42 +357,42 @@ public class OnapCommandExecutionStore {
//find results -type d -newermt '2019-02-11 10:00:00' ! -newermt '2019-02-11 15:10:00' -name "*__*__profile-list*"
//find 'results' -type d -newermt '2019-02-11T10:00:00.000' ! -newermt '2019-02-11T15:10:00.000' -name "*__*__profile*"
- String searchString = "find " + new File(getBasePath()).getAbsolutePath() + " -type d ";
+ StringBuilder searchString = new StringBuilder("find " + new File(getBasePath()).getAbsolutePath() + " -type d ");
String startTime = search.get("startTime");
if (startTime != null) {
- searchString += " -newermt " + startTime ;
+ searchString.append(" -newermt " + startTime);
}
String endTime = search.get("endTime");
if (endTime != null) {
- searchString += " ! -newermt " + endTime ;
+ searchString.append(" ! -newermt " + endTime);
}
- searchString += " -name \"";
+ searchString.append(" -name \"");
- if(search.containsKey("execution-id")) {
- searchString += search.get("execution-id");
- } else if(search.containsKey("request-id")) {
- searchString += search.get("request-id") + "*";
+ if(search.containsKey(EXECUTIONID)) {
+ searchString.append(search.get(EXECUTIONID));
+ } else if(search.containsKey(REQUESTID)) {
+ searchString.append(search.get(REQUESTID) + "*");
} else {
- searchString += "*";
+ searchString.append("*");
}
for (String term: Arrays.asList(new String []{"product", "service", "command", "profile"})) {
- searchString += "__";
+ searchString.append("__");
if (search.get(term) != null && !search.get(term).isEmpty()) {
- searchString += search.get(term);
+ searchString.append(search.get(term));
} else {
- searchString += "*";
+ searchString.append("*");
}
}
- if (!searchString.endsWith("*"))
- searchString += "*";
+ if (!searchString.toString().endsWith("*"))
+ searchString.append("*");
- searchString += "\"";
+ searchString.append("\"");
- ProcessRunner pr = new ProcessRunner(new String [] {searchString}, null, ".");
+ ProcessRunner pr = new ProcessRunner(new String [] {searchString.toString()}, null, ".");
pr.setTimeout(10000);
pr.overrideToUnix();
pr.run();
@@ -403,32 +416,32 @@ public class OnapCommandExecutionStore {
private Execution makeExecution(String executionStorePath) throws IOException {
OnapCommandExecutionStore.Execution exectuion = new OnapCommandExecutionStore.Execution();
- if (new File(executionStorePath + File.separator + "requestId").exists())
- exectuion.setRequestId(FileUtils.readFileToString(new File(executionStorePath + File.separator + "requestId")));
- if (new File(executionStorePath + File.separator + "executionId").exists())
- exectuion.setId(FileUtils.readFileToString(new File(executionStorePath + File.separator + "executionId")));
- exectuion.setProduct(FileUtils.readFileToString(new File(executionStorePath + File.separator + "product")));
- exectuion.setService(FileUtils.readFileToString(new File(executionStorePath + File.separator + "service")));
- exectuion.setCommand(FileUtils.readFileToString(new File(executionStorePath + File.separator + "command")));
- if (new File(executionStorePath + File.separator + "profile").exists())
- exectuion.setProfile(FileUtils.readFileToString(new File(executionStorePath + File.separator + "profile")));
-
- exectuion.setInput(FileUtils.readFileToString(new File(executionStorePath + File.separator + "input")));
- exectuion.setStartTime(dateFormatter.format(new File(executionStorePath + File.separator + "input").lastModified()));
-
- if (new File(executionStorePath + File.separator + "in-progress").exists()) {
- exectuion.setStatus("in-progress");
- } else if (new File(executionStorePath + File.separator + "completed").exists()) {
- exectuion.setStatus("completed");
- if (new File(executionStorePath + File.separator + "output").exists()) {
- exectuion.setOutput(FileUtils.readFileToString(new File(executionStorePath + File.separator + "output")));
- exectuion.setEndTime(dateFormatter.format(new File(executionStorePath + File.separator + "output").lastModified()));
+ if (new File(executionStorePath + File.separator + REQUEST_ID).exists())
+ exectuion.setRequestId(FileUtils.readFileToString(new File(executionStorePath + File.separator + REQUEST_ID)));
+ if (new File(executionStorePath + File.separator + EXECUTION_ID).exists())
+ exectuion.setId(FileUtils.readFileToString(new File(executionStorePath + File.separator + EXECUTION_ID)));
+ exectuion.setProduct(FileUtils.readFileToString(new File(executionStorePath + File.separator + OnapCommandConstants.INFO_PRODUCT)));
+ exectuion.setService(FileUtils.readFileToString(new File(executionStorePath + File.separator + OnapCommandConstants.INFO_SERVICE)));
+ exectuion.setCommand(FileUtils.readFileToString(new File(executionStorePath + File.separator + OnapCommandConstants.RPC_CMD)));
+ if (new File(executionStorePath + File.separator + OnapCommandConstants.RPC_PROFILE).exists())
+ exectuion.setProfile(FileUtils.readFileToString(new File(executionStorePath + File.separator + OnapCommandConstants.RPC_PROFILE)));
+
+ exectuion.setInput(FileUtils.readFileToString(new File(executionStorePath + File.separator + INPUT)));
+ exectuion.setStartTime(dateFormatter.format(new File(executionStorePath + File.separator + INPUT).lastModified()));
+
+ if (new File(executionStorePath + File.separator + IN_PROGRESS).exists()) {
+ exectuion.setStatus(IN_PROGRESS);
+ } else if (new File(executionStorePath + File.separator + COMPLETED).exists()) {
+ exectuion.setStatus(COMPLETED);
+ if (new File(executionStorePath + File.separator + OUTPUT).exists()) {
+ exectuion.setOutput(FileUtils.readFileToString(new File(executionStorePath + File.separator + OUTPUT)));
+ exectuion.setEndTime(dateFormatter.format(new File(executionStorePath + File.separator + OUTPUT).lastModified()));
}
- } else if (new File(executionStorePath + File.separator + "failed").exists()) {
- exectuion.setStatus("failed");
- if (new File(executionStorePath + File.separator + "error").exists()) {
- exectuion.setOutput(FileUtils.readFileToString(new File(executionStorePath + File.separator + "error")));
- exectuion.setEndTime(dateFormatter.format(new File(executionStorePath + File.separator + "error").lastModified()));
+ } else if (new File(executionStorePath + File.separator + FAILED).exists()) {
+ exectuion.setStatus(FAILED);
+ if (new File(executionStorePath + File.separator + ERROR).exists()) {
+ exectuion.setOutput(FileUtils.readFileToString(new File(executionStorePath + File.separator + ERROR)));
+ exectuion.setEndTime(dateFormatter.format(new File(executionStorePath + File.separator + ERROR).lastModified()));
}
}
@@ -470,7 +483,7 @@ public class OnapCommandExecutionStore {
public String showExecutionDebug(String executionId) throws OnapCommandExecutionNotFound {
try {
- return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + "debug"));
+ return FileUtils.readFileToString(new File (this.getExecutionDir(executionId).getAbsolutePath() + File.separator + DEBUG));
} catch (IOException e) {
return "";
}
diff --git a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
index 6455447e..139521e4 100644
--- a/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
+++ b/framework/src/main/java/org/onap/cli/fw/store/OnapCommandProfileStore.java
@@ -207,7 +207,7 @@ public class OnapCommandProfileStore {
File file = new File(dataDir + File.separator + profile + DATA_PATH_PROFILE_JSON);
if (file.exists()) {
if(!file.delete()){
- log.error("Failed to delete profile "+file.getAbsolutePath());
+ log.error("Failed to delete profile {}", file.getAbsolutePath());
}
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
index 23c825e2..7a4dc49f 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandDiscoveryUtils.java
@@ -176,7 +176,7 @@ public class OnapCommandDiscoveryUtils {
* @throws OnapCommandDiscoveryFailed
* exception
*/
- public static boolean isAlreadyDiscovered() throws OnapCommandDiscoveryFailed {
+ public static boolean isAlreadyDiscovered() throws OnapCommandDiscoveryFailed { //NOSONAR
String dataDir = OnapCommandDiscoveryUtils.getDataStorePath();
return new File(dataDir + File.separator + DISCOVERY_FILE).exists();
}
@@ -338,14 +338,14 @@ public class OnapCommandDiscoveryUtils {
Object obj = resourceMap.get(OPEN_CLI_SCHEMA_VERSION);
if (obj == null) {
- OnapCommandUtils.log.info("Invalid Schema yaml " + schema.getSchemaURI());
+ OnapCommandUtils.log.info("Invalid Schema yaml {}", schema.getSchemaURI());
continue;
}
schema.setVersion(obj.toString());
if (!schema.getVersion().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SCHEMA_VERSION_VALUE_1_0)) {
- OnapCommandUtils.log.info("Unsupported Schema version found " + schema.getSchemaURI());
+ OnapCommandUtils.log.info("Unsupported Schema version found {}", schema.getSchemaURI());
continue;
}
@@ -431,12 +431,12 @@ public class OnapCommandDiscoveryUtils {
Object sampleVersion = infoMap.get(OPEN_CLI_SAMPLE_VERSION);
if (sampleVersion == null) {
- OnapCommandUtils.log.info("Invalid Sample yaml " + sampleResourse.getURI().toString());
+ OnapCommandUtils.log.info("Invalid Sample yaml {}", sampleResourse.getURI());
return;
}
if (!sampleVersion.toString().equalsIgnoreCase(OnapCommandConstants.OPEN_CLI_SAMPLE_VERSION_VALUE_1_0)) {
- OnapCommandUtils.log.info("Unsupported Sample version found " + sampleResourse.getURI().toString());
+ OnapCommandUtils.log.info("Unsupported Sample version found {}", sampleResourse.getURI());
return;
}
@@ -485,12 +485,12 @@ public class OnapCommandDiscoveryUtils {
public static List<Map<String, ?>> createTestSuite(String cmd, String version) throws OnapCommandException {
- ArrayList<Map<String, ?>> testSamples = new ArrayList();
+ ArrayList<Map<String, ?>> testSamples = new ArrayList<>();
- List<Resource> resources = new ArrayList();
+ List<Resource> resources = new ArrayList<>();
OnapCommandSchemaInfo schemaInfo = getSchemaInfo(cmd, version);
- List<String> sampleFiles = new ArrayList();
+ List<String> sampleFiles = new ArrayList<>();
if (schemaInfo != null && !schemaInfo.getSampleFiles().isEmpty()) {
sampleFiles.addAll(schemaInfo.getSampleFiles());
}
@@ -515,13 +515,13 @@ public class OnapCommandDiscoveryUtils {
Map<String, String> sample = samples.get(sampleId);
- List<String> inputArgs = new ArrayList();
+ List<String> inputArgs = new ArrayList<>();
if (sample.get(OnapCommandConstants.VERIFY_INPUT) != null) {
inputArgs.addAll(Arrays.asList(sample.get(OnapCommandConstants.VERIFY_INPUT).trim().split(" ")));
}
inputArgs.add(OnapCommandConstants.VERIFY_LONG_OPTION);
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<>();
map.put(OnapCommandConstants.VERIFY_INPUT, inputArgs);
map.put(OnapCommandConstants.VERIFY_OUPUT, sample.get(OnapCommandConstants.VERIFY_OUPUT));
map.put(OnapCommandConstants.VERIFY_MOCO, sample.get(OnapCommandConstants.VERIFY_MOCO));
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
index 1387ea3d..323e9e76 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandHelperUtils.java
@@ -42,11 +42,8 @@ public class OnapCommandHelperUtils {
*/
public static String findLastBuildTime() {
String impBuildDate = "";
- JarFile jar = null;
- try
- {
- String path = OnapCommandUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
- jar = new JarFile(path);
+ String path = OnapCommandUtils.class.getProtectionDomain().getCodeSource().getLocation().getPath();
+ try(JarFile jar = new JarFile(path)){
Manifest manifest = jar.getManifest();
Attributes attributes = manifest.getMainAttributes();
@@ -56,14 +53,6 @@ public class OnapCommandHelperUtils {
catch (IOException e) // NOSONAR
{
//Ignore it as it will never occur
- } finally {
- if (jar != null) {
- try {
- jar.close();
- } catch (IOException e) { // NOSONAR
- //Ignore it as it will never occur
- }
- }
}
return impBuildDate;
@@ -80,18 +69,18 @@ public class OnapCommandHelperUtils {
*/
public static String help(OnapCommand cmd) throws OnapCommandHelpFailed {
- String help = "usage: oclip " + cmd.getName();
+ StringBuilder help = new StringBuilder("usage: oclip " + cmd.getName());
// Add description
- help += "\n\n" + cmd.getDescription();
+ help.append("\n\n" + cmd.getDescription());
// Add info
- help += "\n\nProduct: " + cmd.getInfo().getProduct();
- help += "\nService: " + cmd.getInfo().getService();
- help += "\nAuthor: " + cmd.getInfo().getAuthor();
+ help.append("\n\nProduct: " + cmd.getInfo().getProduct());
+ help.append("\nService: " + cmd.getInfo().getService());
+ help.append("\nAuthor: " + cmd.getInfo().getAuthor());
// Add whole command
- String commandOptions = "";
+ StringBuilder commandOptions = new StringBuilder();
// Add parameters
OnapCommandResult paramTable = new OnapCommandResult();
@@ -122,16 +111,16 @@ public class OnapCommandHelperUtils {
String optFirstCol;
if (newLineOptions == 3) {
newLineOptions = 0;
- commandOptions += "\n";
+ commandOptions.append("\n");
}
if (param.getShortOption() != null || param.getLongOption() != null) {
optFirstCol = OnapCommandParameter.printShortOption(param.getShortOption()) + " | "
+ OnapCommandParameter.printLongOption(param.getLongOption());
- commandOptions += " [" + optFirstCol + "]";
+ commandOptions.append(" [" + optFirstCol + "]");
} else {
optFirstCol = param.getName();
- commandOptions += " <" + optFirstCol + ">";
+ commandOptions.append(" <" + optFirstCol + ">");
}
newLineOptions++;
@@ -169,7 +158,7 @@ public class OnapCommandHelperUtils {
}
try {
- help += "\n\nOptions::\n\n" + commandOptions + "\n\nwhere::\n\n" + paramTable.print();
+ help.append("\n\nOptions::\n\n" + commandOptions.toString() + "\n\nwhere::\n\n" + paramTable.print());
} catch (OnapCommandException e) {
throw new OnapCommandHelpFailed(e);
}
@@ -196,15 +185,15 @@ public class OnapCommandHelperUtils {
if (cmd.getResult().getRecords().size() > 0) {
try {
- help += "\n\nResults::\n\n" + resultTable.print();
+ help.append("\n\nResults::\n\n" + resultTable.print());
} catch (OnapCommandException e) {
throw new OnapCommandHelpFailed(e);
}
}
// Error
- help += "\n\nError::\n\n On error, it prints <STATUS CODE>::<ERROR CODE>::<ERROR MESSAGE>\n";
- return help;
+ help.append("\n\nError::\n\n On error, it prints <STATUS CODE>::<ERROR CODE>::<ERROR MESSAGE>\n");
+ return help.toString();
}
}
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
index 2cd07ed8..814f5139 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/OnapCommandUtils.java
@@ -200,7 +200,7 @@ public class OnapCommandUtils {
* @return
*/
public static String replaceLineFromResults(String line, Map <String, String> values) {
- String resultLine = "";
+ StringBuilder resultLine = new StringBuilder();
if (!line.contains("$r{")) {
return line;
@@ -210,7 +210,7 @@ public class OnapCommandUtils {
while (currentIdx < line.length()) {
int idxS = line.indexOf("$r{", currentIdx);
if (idxS == -1) {
- resultLine += line.substring(currentIdx);
+ resultLine.append(line.substring(currentIdx));
break;
}
int idxE = line.indexOf("}", idxS);
@@ -225,15 +225,15 @@ public class OnapCommandUtils {
value = attr;
}
- resultLine += line.substring(currentIdx, idxS) + value;
+ resultLine.append(line.substring(currentIdx, idxS) + value);
currentIdx = idxE + 1;
}
- return resultLine;
+ return resultLine.toString();
}
public static String replaceLineForSpecialValues(String lineSpl, Map <String, String> values) {
- String resultSpl = "";
+ StringBuilder resultSpl = new StringBuilder();
if (!lineSpl.contains("$s{")) {
return lineSpl;
@@ -243,7 +243,7 @@ public class OnapCommandUtils {
while (currentIdx < lineSpl.length()) {
int idxS = lineSpl.indexOf("$s{", currentIdx);
if (idxS == -1) {
- resultSpl += lineSpl.substring(currentIdx);
+ resultSpl.append(lineSpl.substring(currentIdx));
break;
}
int idxE = lineSpl.indexOf("}", idxS);
@@ -297,16 +297,16 @@ public class OnapCommandUtils {
}
}
- resultSpl += lineSpl.substring(currentIdx, idxS) + value;
+ resultSpl.append(lineSpl.substring(currentIdx, idxS) + value);
currentIdx = idxE + 1;
}
- return resultSpl;
+ return resultSpl.toString();
}
public static String replaceLineFromInputParameters(String line, Map<String, OnapCommandParameter> params)
throws OnapCommandException {
- String result = "";
+ StringBuilder result = new StringBuilder();
if (!line.contains("${")) {
return line;
@@ -316,7 +316,7 @@ public class OnapCommandUtils {
while (currentIdx < line.length()) {
int idxS = line.indexOf("${", currentIdx);
if (idxS == -1) {
- result += line.substring(currentIdx);
+ result.append(line.substring(currentIdx));
break;
}
int idxE = line.indexOf("}", idxS);
@@ -333,17 +333,17 @@ public class OnapCommandUtils {
// ignore the front and back double quotes in json body
String va_ = params.get(paramName).getValue().toString();
if (idxS > 0)
- result += line.substring(currentIdx, idxS - 1) + va_;
+ result.append(line.substring(currentIdx, idxS - 1) + va_);
else
- result += va_;
+ result.append(va_);
currentIdx = idxE + 2;
} else if (OnapCommandParameterType.MAP.equals(param.getParameterType())) {
try {
String value = gson.toJson(params.get(paramName).getValue());
if ((idxS == 0) && (currentIdx == 0)) {
- result = value;
+ result.replace(0, result.length(), value);
} else {
- result += line.substring(currentIdx, idxS - 1) + value;
+ result.append(line.substring(currentIdx, idxS - 1) + value);
}
} catch (Exception e) { // NOSONAR
//never occur as map is coverted to json string here
@@ -351,12 +351,12 @@ public class OnapCommandUtils {
currentIdx = idxE + 2;
}else {
- result += line.substring(currentIdx, idxS) + params.get(paramName).getValue().toString();
+ result.append(line.substring(currentIdx, idxS) + params.get(paramName).getValue().toString());
currentIdx = idxE + 1;
}
}
- return result;
+ return result.toString();
}
/**
diff --git a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
index 69906aba..bb37c470 100644
--- a/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
+++ b/framework/src/main/java/org/onap/cli/fw/utils/ProcessRunner.java
@@ -99,7 +99,7 @@ public class ProcessRunner {
if (this.cmd.length == 1) {
p = Runtime.getRuntime().exec(this.shell + this.cmd[0], this.env, workingDirectory); //NOSONAR
} else {
- List list = new ArrayList(Arrays.asList(this.shell.split(" ")));
+ List<String> list = new ArrayList<>(Arrays.asList(this.shell.split(" ")));
list.addAll(Arrays.asList(this.cmd));
String []cmds = Arrays.copyOf(list.toArray(), list.size(), String[].class);
p = Runtime.getRuntime().exec(cmds, this.env, workingDirectory); //NOSONAR
@@ -160,12 +160,8 @@ public class ProcessRunner {
p.destroy();
- log.debug("CMD: " + Arrays.asList(this.cmd).toString() +
- "\nWORKING_DIR: " + this.cwd +
- "\nENV: " + ((this.env == null) ? this.env : Arrays.asList(this.env).toString()) +
- "\nOUTPUT: " + this.output +
- "\nERROR: " + this.error +
- "\nEXIT_CODE: " + this.exitCode);
+ log.debug("CMD: {} \nWORKING_DIR: {} \nENV: {} \nOUTPUT: {} \nERROR: {} \nEXIT_CODE: {}",
+ Arrays.asList(this.cmd), this.cwd, ((this.env == null) ? this.env : Arrays.asList(this.env)), this.output, this.error, this.exitCode);
if (!completed) {
throw new RuntimeException("TIMEOUT:: cmd:" + Arrays.asList(this.cmd).toString());
diff --git a/framework/src/test/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommandTest.java b/framework/src/test/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommandTest.java
index 5d83374c..741b53a1 100644
--- a/framework/src/test/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommandTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/cmd/execution/OnapCommandExceutionShowCommandTest.java
@@ -25,7 +25,10 @@ import org.onap.cli.fw.store.OnapCommandExecutionStoreTest;
import java.io.File;
import java.util.List;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
+import mockit.Mock;
+import mockit.MockUp;
+import org.onap.cli.fw.store.OnapCommandExecutionStore;
public class OnapCommandExceutionShowCommandTest {
@BeforeClass
@@ -46,7 +49,23 @@ public static void setUp() throws Exception {
assertTrue(oclipCommandResultAttributes.size() > 1);
}
-
+ @Test
+ public void runTestForStringBuilder() throws OnapCommandException {
+ new MockUp<OnapCommandExecutionStore.Execution>(){
+ @Mock
+ public String getOutput() {
+ return "oclip-request-output";
+ }
+ };
+ OnapCommandExceutionShowCommand cmd=new OnapCommandExceutionShowCommand();
+ cmd.initializeSchema("execution-show.yaml");
+ cmd.getParametersMap().get("execution-id").setValue("requestId");
+ cmd.getParametersMap().get("format").setValue("TEXT");
+ cmd.execute();
+ List<OnapCommandResultAttribute> oclipCommandResultAttributes = cmd.getResult()
+ .getRecords();
+ assertTrue(oclipCommandResultAttributes.size() > 1);
+ }
@AfterClass
public static void tearDown() throws Exception {
String dirPathForExecutions = System.getProperty("user.dir") + File.separator + "data/executions";
diff --git a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
index 9c31747b..e01c3878 100644
--- a/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
+++ b/framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
@@ -132,6 +132,20 @@ public class OnapCommandUtilsTest {
}
@Test
+ public void replaceLineFromResultsTest() {
+ String replacedLine = OnapCommandUtils.replaceLineFromResults("line", new HashMap<>());
+ assertEquals("line", replacedLine);
+ replacedLine = OnapCommandUtils.replaceLineFromResults("${}", new HashMap<>());
+ assertEquals("${}", replacedLine);
+ replacedLine = OnapCommandUtils.replaceLineFromResults("$r{}", new HashMap<>());
+ assertTrue( replacedLine.isEmpty());
+ HashMap<String, String> values = new HashMap<>();
+ values.put("This is test line","This is test line");
+ replacedLine = OnapCommandUtils.replaceLineFromResults("$r{This is test line}", values);
+ assertEquals("This is test line", replacedLine);
+ }
+
+ @Test
public void replaceLineForSpecialValues_replacingUuid() {
String replacedLine = OnapCommandUtils.replaceLineForSpecialValues("$s{uuid}");
diff --git a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java
index e32110de..efc941f9 100644
--- a/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java
+++ b/grpc/grpc-client/src/main/java/org/open/infc/grpc/client/OpenInterfaceGrpcClient.java
@@ -82,17 +82,17 @@ public class OpenInterfaceGrpcClient {
}
public Output invoke(Input input) throws OpenInterfaceGrpcTimeoutExecption {
- logger.info("Input " + input.toString());
+ logger.info("Input {}", input);
Output result = Output.newBuilder().build();
try {
result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).invoke(input);
} catch (StatusRuntimeException e) {
- logger.warn("RPC failed: {0}", e.getStatus());
+ logger.warn("RPC failed: {}", e.getStatus());
//Status{code=DEADLINE_EXCEEDED}
throw new OpenInterfaceGrpcTimeoutExecption(e.getMessage());
}
- logger.info("Output: " + result.toString());
+ logger.info("Output: {}", result);
return result;
}
@@ -103,12 +103,12 @@ public class OpenInterfaceGrpcClient {
try {
result = blockingStub.withDeadlineAfter(timeout, TimeUnit.MILLISECONDS).remoteCli(args);
} catch (StatusRuntimeException e) {
- logger.warn("RPC failed: {0}", e.getStatus());
+ logger.warn("RPC failed: {}", e.getStatus());
//Status{code=DEADLINE_EXCEEDED}
throw new OpenInterfaceGrpcTimeoutExecption(e.getMessage());
}
- logger.info("Result: " + result.toString());
+ logger.info("Result: {}", result);
return result;
}
}
diff --git a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
index d59416c7..9f236e5c 100644
--- a/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
+++ b/grpc/grpc-server/src/main/java/org/open/infc/grpc/server/OpenInterfaceGrpcServer.java
@@ -75,7 +75,7 @@ public class OpenInterfaceGrpcServer {
.addService(new OpenInterfaceGrpcImpl())
.build()
.start();
- logger.info("Server started, listening on " + port);
+ logger.info("Server started, listening on {}", port);
try {
OnapCommandRegistrar.getRegistrar().setHost(host);
@@ -140,7 +140,7 @@ public class OpenInterfaceGrpcServer {
@Override
public void invoke(Input req, StreamObserver<Output> responseObserver) {
Output output = null;
- logger.info(req.toString());
+ logger.info("{}", req);
String product = req.getOptionsMap().get(OnapCommandConstants.RPC_PRODUCT);
String format = req.getOptionsMap().getOrDefault(OnapCommandConstants.DEFAULT_PARAMETER_OUTPUT_FORMAT, OnapCommandResultType.JSON.name().toLowerCase());
@@ -252,7 +252,7 @@ public class OpenInterfaceGrpcServer {
}
output = reply.build();
- logger.info(output.toString());
+ logger.info("{}", output);
} else {
//Rpc command will set the output.
output = (Output) cmd.getResult().getOutput();
@@ -284,7 +284,7 @@ public class OpenInterfaceGrpcServer {
@Override
public void remoteCli(Args req, StreamObserver<Result> responseObserver) {
- logger.info(req.toString());
+ logger.info("{}", req);
List<String> args = new ArrayList<>();
if (req.getRequestId() != null) {
diff --git a/main/src/main/java/org/onap/cli/main/OnapCli.java b/main/src/main/java/org/onap/cli/main/OnapCli.java
index 21a0e4aa..4c12d7eb 100644
--- a/main/src/main/java/org/onap/cli/main/OnapCli.java
+++ b/main/src/main/java/org/onap/cli/main/OnapCli.java
@@ -327,7 +327,7 @@ public class OnapCli {
.findFirst();
if (contextOpt.isPresent()) {
- HashMap map = new HashMap();
+ HashMap<String, Object> map = new HashMap<>();
Object moco = sampleTest.get(OnapCommandConstants.VERIFY_MOCO);
if (moco == null) {
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
index 0ed930d1..eb7b808b 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java
@@ -83,7 +83,7 @@ public class OpenCommandShellCmd extends OnapCommand {
return successStatusCodes;
}
- public void setSuccessStatusCodes(ArrayList<Integer> successStatusCodes) {
+ public void setSuccessStatusCodes(List<Integer> successStatusCodes) {
this.successStatusCodes = successStatusCodes;
}
@@ -197,7 +197,7 @@ public class OpenCommandShellCmd extends OnapCommand {
FileOutputStream stderrStream = null;
String outputValue = "";
- try {
+ try { //NOSONAR
pr.setTimeout(timeout);
if (this.getExecutionContext() != null) {
@@ -370,7 +370,7 @@ public class OpenCommandShellCmd extends OnapCommand {
// Process jsonpath macros
List<Object> values = new ArrayList<>();
- String processedPattern = "";
+ StringBuilder processedPattern = new StringBuilder();
currentIdx = 0;
int maxRows = 1; // in normal case, only one row will be there
while (currentIdx < line.length()) {
@@ -378,7 +378,7 @@ public class OpenCommandShellCmd extends OnapCommand {
if (idxS == -1) {
idxS = line.indexOf("$e{", currentIdx); //check for error stream
if (idxS == -1) {
- processedPattern += line.substring(currentIdx);
+ processedPattern.append(line.substring(currentIdx));
break;
}
}
@@ -405,23 +405,23 @@ public class OpenCommandShellCmd extends OnapCommand {
maxRows = arr.size();
}
}
- processedPattern += line.substring(currentIdx, idxS) + "%s";
+ processedPattern.append(line.substring(currentIdx, idxS) + "%s");
values.add(value);
currentIdx = idxE + 1;
}
- if (processedPattern.isEmpty()) {
+ if (processedPattern.toString().isEmpty()) {
result.add(line);
return result;
} else {
for (int i = 0; i < maxRows; i++) {
currentIdx = 0;
- String bodyProcessedLine = "";
+ StringBuilder bodyProcessedLine = new StringBuilder();
int positionalIdx = 0; // %s positional idx
while (currentIdx < processedPattern.length()) {
int idxS = processedPattern.indexOf("%s", currentIdx);
if (idxS == -1) {
- bodyProcessedLine += processedPattern.substring(currentIdx);
+ bodyProcessedLine.append(processedPattern.substring(currentIdx));
break;
}
@@ -441,7 +441,7 @@ public class OpenCommandShellCmd extends OnapCommand {
}
}
- bodyProcessedLine += processedPattern.substring(currentIdx, idxS) + valStr;
+ bodyProcessedLine.append(processedPattern.substring(currentIdx, idxS) + valStr);
currentIdx = idxEnd;
positionalIdx++;
} catch (OnapCommandResultEmpty e) {
@@ -450,7 +450,7 @@ public class OpenCommandShellCmd extends OnapCommand {
throw new OnapCommandResultMapProcessingFailed(line, e);
}
}
- result.add(bodyProcessedLine);
+ result.add(bodyProcessedLine.toString());
}
return result;
diff --git a/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java b/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
index 965bd2b1..676aeb30 100644
--- a/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
+++ b/profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java
@@ -44,9 +44,9 @@ public class OnapCommandSchemaCmdLoader {
* @throws OnapCommandException
* on error
*/
- public static ArrayList<String> parseCmdSchema(OpenCommandShellCmd cmd,
+ public static List<String> parseCmdSchema(OpenCommandShellCmd cmd,
final Map<String, ?> values,
- boolean validate) throws OnapCommandException {
+ boolean validate) throws OnapCommandException { //NOSONAR
ArrayList<String> errorList = new ArrayList<>();
Map<String, ?> valMap = (Map<String, ?>) values.get(OnapCommandCmdConstants.CMD);
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
index 53a2d042..387ec3be 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/cmd/OnapHttpCommand.java
@@ -253,7 +253,7 @@ public class OnapHttpCommand extends OnapCommand {
this.resultMap.put(resultMapEntry.getKey(), value);
}
- Map<String, ArrayList<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
+ Map<String, List<String>> results = OnapCommandHttpUtils.populateOutputs(this.getResultMap(), output);
//results = OnapCommandUtils.populateOutputsFromInputParameters(results, this.getParametersMap());
for (OnapCommandResultAttribute attr : this.getResult().getRecords()) {
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
index a2e025a8..9c4185b7 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/mock/MocoServer.java
@@ -43,7 +43,7 @@ import java.io.InputStreamReader;
public class MocoServer {
private Runner runner;
- private Map<String, Object> mocoServerConfigs = new HashMap();
+ private Map<String, Object> mocoServerConfigs = new HashMap<>();
private static Gson gson = new GsonBuilder().serializeNulls().create();
public MocoServer(String mockFile) throws OnapCommandException {
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
index df9c84fc..33f58060 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
@@ -92,7 +92,7 @@ public class OnapCommandSchemaHttpLoader {
* @throws OnapCommandException
* on error
*/
- public static ArrayList<String> parseHttpSchema(OnapHttpCommand cmd,
+ public static List<String> parseHttpSchema(OnapHttpCommand cmd,
final Map<String, ?> values,
boolean validate) throws OnapCommandException {
ArrayList<String> errorList = new ArrayList<>();
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
index a592ac79..fcd25c24 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
@@ -145,9 +145,9 @@ public class OnapCommandHttpUtils {
* @throws OnapCommandResultMapProcessingFailed
* map processing failed exception
*/
- public static Map<String, ArrayList<String>> populateOutputs(Map<String, String> resultMap, HttpResult resultHttp)
+ public static Map<String, List<String>> populateOutputs(Map<String, String> resultMap, HttpResult resultHttp)
throws OnapCommandException {
- Map<String, ArrayList<String>> resultsProcessed = new HashMap<>();
+ Map<String, List<String>> resultsProcessed = new HashMap<>();
for (Entry<String, String> entry : resultMap.entrySet()) {
String key = entry.getKey();
@@ -161,10 +161,10 @@ public class OnapCommandHttpUtils {
return resultsProcessed;
}
- public static ArrayList<String> replaceLineFromOutputResults(String line, HttpResult resultHttp)
+ public static List<String> replaceLineFromOutputResults(String line, HttpResult resultHttp)
throws OnapCommandHttpHeaderNotFound, OnapCommandHttpInvalidResponseBody,
OnapCommandResultMapProcessingFailed, OnapCommandResultEmpty {
- String headerProcessedLine = "";
+ StringBuilder headerProcessedLine = new StringBuilder();
ArrayList<String> result = new ArrayList<>();
if (!line.contains("$b{") && !line.contains("$h{")) {
@@ -187,7 +187,7 @@ public class OnapCommandHttpUtils {
while (currentIdx < line.length()) {
int idxS = line.indexOf("$h{", currentIdx);
if (idxS == -1) {
- headerProcessedLine += line.substring(currentIdx);
+ headerProcessedLine.append(line.substring(currentIdx));
break;
}
int idxE = line.indexOf("}", idxS);
@@ -198,19 +198,19 @@ public class OnapCommandHttpUtils {
}
String value = resultHttp.getRespHeaders().get(headerName);
- headerProcessedLine += line.substring(currentIdx, idxS) + value;
+ headerProcessedLine.append(line.substring(currentIdx, idxS) + value);
currentIdx = idxE + 1;
}
// Process body jsonpath macros
List<Object> values = new ArrayList<>();
- String bodyProcessedPattern = "";
+ StringBuilder bodyProcessedPattern = new StringBuilder();
currentIdx = 0;
int maxRows = 1; // in normal case, only one row will be there
while (currentIdx < headerProcessedLine.length()) {
int idxS = headerProcessedLine.indexOf("$b{", currentIdx);
if (idxS == -1) {
- bodyProcessedPattern += headerProcessedLine.substring(currentIdx);
+ bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx));
break;
}
int idxE = headerProcessedLine.indexOf("}", idxS);
@@ -233,23 +233,23 @@ public class OnapCommandHttpUtils {
maxRows = arr.size();
}
}
- bodyProcessedPattern += headerProcessedLine.substring(currentIdx, idxS) + "%s";
+ bodyProcessedPattern.append(headerProcessedLine.substring(currentIdx, idxS) + "%s");
values.add(value);
currentIdx = idxE + 1;
}
- if (bodyProcessedPattern.isEmpty()) {
- result.add(headerProcessedLine);
+ if (bodyProcessedPattern.toString().isEmpty()) {
+ result.add(headerProcessedLine.toString());
return result;
} else {
for (int i = 0; i < maxRows; i++) {
currentIdx = 0;
- String bodyProcessedLine = "";
+ StringBuilder bodyProcessedLine = new StringBuilder();
int positionalIdx = 0; // %s positional idx
while (currentIdx < bodyProcessedPattern.length()) {
int idxS = bodyProcessedPattern.indexOf("%s", currentIdx);
if (idxS == -1) {
- bodyProcessedLine += bodyProcessedPattern.substring(currentIdx);
+ bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx));
break;
}
int idxE = idxS + 2; // %s
@@ -265,7 +265,7 @@ public class OnapCommandHttpUtils {
}
}
- bodyProcessedLine += bodyProcessedPattern.substring(currentIdx, idxS) + valueS;
+ bodyProcessedLine.append(bodyProcessedPattern.substring(currentIdx, idxS) + valueS);
currentIdx = idxE;
positionalIdx++;
} catch (OnapCommandResultEmpty e) {
@@ -274,7 +274,7 @@ public class OnapCommandHttpUtils {
throw new OnapCommandResultMapProcessingFailed(line, e);
}
}
- result.add(bodyProcessedLine);
+ result.add(bodyProcessedLine.toString());
}
return result;
diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
index 6e03e74b..37fc8461 100644
--- a/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
+++ b/profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java
@@ -49,6 +49,10 @@ import org.onap.cli.fw.input.OnapCommandParameter;
import org.onap.cli.fw.schema.OnapCommandSchema;
import org.onap.cli.fw.schema.OnapCommandSchemaLoader;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import java.util.List;
+import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
+import org.onap.cli.fw.error.OnapCommandResultEmpty;
+import static org.junit.Assert.assertFalse;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
@@ -116,7 +120,7 @@ public class OnapCommandUtilsTest {
params.put("body", "$b{$.serviceName}");
params.put("key", "value");
- Map<String, ArrayList<String>> input1 = OnapCommandHttpUtils.populateOutputs(params, output);
+ Map<String, List<String>> input1 = OnapCommandHttpUtils.populateOutputs(params, output);
assertEquals("{head=[value1], body=[test], key=[value]}", input1.toString());
params.put("body", "$b{{$.serviceName}");
@@ -135,6 +139,31 @@ public class OnapCommandUtilsTest {
input1 = OnapCommandHttpUtils.populateOutputs(params, output);
}
+ @Test
+ public void replaceLineFromOutputResultsTest() throws OnapCommandHttpHeaderNotFound, OnapCommandHttpInvalidResponseBody, OnapCommandResultMapProcessingFailed, OnapCommandResultEmpty {
+ HttpResult output = new HttpResult();
+
+ Map<String, String> mapHead = new HashMap<>();
+ mapHead.put("head1", "value1");
+ output.setRespHeaders(mapHead);
+ output.setStatus(0);
+ List<String> actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("", output);
+ assertTrue(actualResult.get(0).isEmpty());
+ output.setBody("");
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}$b{$.serviceName}", output);
+ assertTrue(actualResult.isEmpty());
+// assertTrue(actualResult.size() > 0);
+ output.setBody(
+ "{\"serviceName\":\"test\",\"version\":\"v1\",\"url\":\"/api/test/v1\",\"protocol\":\"REST\","
+ + "\"visualRange\":\"1\",\"lb_policy\":\"hash\",\"nodes\":[{\"ip\":\"127.0.0.1\",\"port\":\"8012\","
+ + "\"ttl\":0,\"nodeId\":\"test_127.0.0.1_8012\",\"expiration\":\"2017-02-10T05:33:25Z\","
+ + "\"created_at\":\"2017-02-10T05:33:25Z\",\"updated_at\":\"2017-02-10T05:33:25Z\"}],"
+ + "\"status\":\"1\"}");
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}${$.serviceName}", output);
+ assertTrue(actualResult.size()>0);
+ actualResult = OnapCommandHttpUtils.replaceLineFromOutputResults("$h{head1}$b{$.serviceName}", output);
+ assertFalse(actualResult.get(0).isEmpty());
+ }
@OnapCommandSchema(schema = "sample-test-schema-http.yaml")
class OnapHttpCommandSample extends OnapHttpCommand {
diff --git a/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java b/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java
index ed88b0c6..3e841e76 100644
--- a/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java
+++ b/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java
@@ -75,7 +75,7 @@ public class OnapSnmpCommand extends OnapCommand {
return pdu;
}
- private Target getTarget() throws OnapCommandException {
+ private Target getTarget() throws OnapCommandException { //NOSONAR
Address targetAddress = GenericAddress.parse(this.getAgent()); //udp:127.0.0.1/161
CommunityTarget target = new CommunityTarget();
target.setCommunity(new OctetString(OnapCommandSnmpConstants.SNMP_COMMNUNITY_STRING));
diff --git a/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java b/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java
index c132be26..ca3f44e0 100644
--- a/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java
+++ b/profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java
@@ -40,7 +40,7 @@ public class OnapCommandSchemaSnmpLoader {
public static List<String> parseSnmpSchema(OnapSnmpCommand cmd,
final Map<String, ?> values,
- boolean validate) throws OnapCommandException {
+ boolean validate) throws OnapCommandException { //NOSONAR
ArrayList<String> errorList = new ArrayList<>();
Map<String, ?> valMap = (Map<String, ?>) values.get(OnapCommandSnmpConstants.SNMP);
diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java
index 3bba8c21..7b3e5738 100644
--- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockRequest.java
@@ -58,7 +58,7 @@ public class MockRequest {
return json;
}
- public void setJson(String json) throws IOException {
+ public void setJson(String json) throws IOException { //NOSONAR
if (!json.isEmpty()) {
try {
JsonParser parser = new JsonParser();
diff --git a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
index 30f64f20..7f605c33 100644
--- a/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
+++ b/validate/sample-mock-generator/src/main/java/org/onap/cli/http/mock/MockResponse.java
@@ -36,7 +36,7 @@ public class MockResponse {
return json;
}
- public void setJson(String json) throws IOException {
+ public void setJson(String json) throws IOException { //NOSONAR
if (json != null && !json.isEmpty()) {
try {
JsonParser parser = new JsonParser();