aboutsummaryrefslogtreecommitdiffstats
path: root/profiles
diff options
context:
space:
mode:
authorSravanKumarGunda <sravan.kumar1@huawei.com>2020-06-18 19:05:44 +0530
committerSravanKumarGunda <sravan.kumar1@huawei.com>2020-07-02 16:02:50 +0530
commitc3391bef9e04c2ad38ed96bd28a5c43ab6d961de (patch)
treefbb3c017de9d5e016a7d9de88b0ea1193b9d6265 /profiles
parent022ee4b8daa1b852d72c1083658d1efb254f9dd5 (diff)
Code Improvements-Sonar Issue Fixes
Signed-off-by: SravanKumarGunda <sravan.kumar1@huawei.com> Issue-ID: CLI-270 Change-Id: Iba00ddc8c471bc5990d87ba3729af373e2bd6711
Diffstat (limited to 'profiles')
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java17
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java6
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java2
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java3
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java1
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java4
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java4
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java20
8 files changed, 35 insertions, 22 deletions
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 eb7b808b..dd2c26cd 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
@@ -22,7 +22,6 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
@@ -46,12 +45,10 @@ import org.onap.cli.fw.store.OnapCommandExecutionStore;
import org.onap.cli.fw.utils.OnapCommandUtils;
import org.onap.cli.fw.utils.ProcessRunner;
-import com.google.gson.Gson;
import com.jayway.jsonpath.JsonPath;
import com.jayway.jsonpath.PathNotFoundException;
import net.minidev.json.JSONArray;
-import net.minidev.json.JSONObject;
/**
* Hello world.
@@ -191,7 +188,7 @@ public class OpenCommandShellCmd extends OnapCommand {
ProcessRunner pr = new ProcessRunner(
cmd,
- (envs.size() > 0) ? envs.toArray(new String []{}) : null,
+ (!envs.isEmpty()) ? envs.toArray(new String []{}) : null,
cwd);
FileOutputStream stdoutStream = null;
FileOutputStream stderrStream = null;
@@ -285,11 +282,7 @@ public class OpenCommandShellCmd extends OnapCommand {
}
//check for pass/failure
- if (!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())) {
- this.getResult().setPassed(false);
- } else {
- this.getResult().setPassed(true);
- }
+ this.getResult().setPassed(!(!this.passCodes.isEmpty() && !this.passCodes.contains(pr.getExitCode())));
}
public String getOutput() {
@@ -315,10 +308,10 @@ public class OpenCommandShellCmd extends OnapCommand {
break;
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String tmpName = line.substring(idxS + 7, idxE);
tmpName = tmpName.trim();
- String tmpTkns[] = tmpName.split(":");
+ String[] tmpTkns = tmpName.split(":");
String tmpFileName;
String paramName;
if (tmpTkns.length == 2) {
@@ -382,7 +375,7 @@ public class OpenCommandShellCmd extends OnapCommand {
break;
}
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String jsonPath = line.substring(idxS + 3, idxE);
jsonPath = jsonPath.trim();
Object value = new Object();
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 676aeb30..1eeadecc 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
@@ -26,6 +26,7 @@ import org.onap.cli.fw.cmd.conf.OnapCommandCmdConstants;
import org.onap.cli.fw.conf.OnapCommandConfig;
import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.utils.OnapCommandUtils;
+import java.util.stream.Collectors;
public class OnapCommandSchemaCmdLoader {
@@ -64,7 +65,7 @@ public class OnapCommandSchemaCmdLoader {
if (o instanceof List) {
cmd.setCommand((List<String>) o);
} else {
- cmd.setCommand(Arrays.asList(new String [] {(String) o}));
+ cmd.setCommand(Arrays.asList((String) o));
}
break;
@@ -90,7 +91,8 @@ public class OnapCommandSchemaCmdLoader {
break;
case OnapCommandCmdConstants.SUCCESS_EXIT_CODE:
- cmd.setSuccessStatusCodes((ArrayList) valMap.get(key1));
+ List<String> list = (ArrayList) valMap.get(key1);
+ cmd.setSuccessStatusCodes(list.stream().map(s -> Integer.parseInt(s)).collect(Collectors.toList()));
break;
case OnapCommandCmdConstants.PASS_CODE:
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
index 6a87ed13..7ab7928d 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/conf/OnapCommandHttpConstants.java
@@ -94,7 +94,7 @@ public class OnapCommandHttpConstants {
//context param
public static final String CONTEXT = "context";
public static final String CONTEXT_REMOVE_EMPTY_JSON_NODES = "remove_empty_node";
- public static final String __BODY__ = "__body__";
+ public static final String __BODY__ = "__body__"; //NOSONAR
// moco server const
public static final String VERIFY_MOCO_HOST = "cli.verify.host";
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
index 3533e92d..732e6c0a 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
@@ -365,11 +365,10 @@ public class OnapHttpConnection {
} else {
String fileTag = (!input.getMultipartEntityName().isEmpty()) ? input.getMultipartEntityName() : "file";
File file = new File(input.getBody().trim());
- HttpEntity multipartEntity = MultipartEntityBuilder
+ return MultipartEntityBuilder
.create()
.addBinaryBody(fileTag, file, ContentType.create("application/octet-stream"), file.getName())
.build();
- return multipartEntity;
}
}
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java b/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
index 9d6274ac..45da6f69 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/error/OnapCommandFailedMocoGenerate.java
@@ -16,7 +16,6 @@
package org.onap.cli.fw.http.error;
-import org.onap.cli.fw.error.OnapCommandException;
import org.onap.cli.fw.error.OnapCommandWarning;
/**
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 33f58060..d064547e 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
@@ -138,8 +138,8 @@ public class OnapCommandSchemaHttpLoader {
for (Object part: multiparts ) {
HttpInput.Part partO = new HttpInput.Part();
Map<String, String> partMap = (Map<String, String>) part;
- partO.setName((String) partMap.get("name"));
- partO.setContent((String)partMap.get("content"));
+ partO.setName(partMap.get("name"));
+ partO.setContent(partMap.get("content"));
if (partMap.get("type") != null && ((String)partMap.get("type")).equalsIgnoreCase("file")) {
partO.setBinary(true);
}
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 fcd25c24..ec2f572a 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
@@ -93,7 +93,7 @@ public class OnapCommandHttpUtils {
values.put(param.getKey(), param.getValue().getValue().toString());
}
- if (input.getMultiparts().size() > 0) {
+ if (!input.getMultiparts().isEmpty()) {
for (HttpInput.Part part: input.getMultiparts()) {
part.setContent(OnapCommandUtils.replaceLineForSpecialValues(part.getContent(), values));
part.setContent(OnapCommandUtils.replaceLineFromInputParameters(part.getContent(), params));
@@ -190,7 +190,7 @@ public class OnapCommandHttpUtils {
headerProcessedLine.append(line.substring(currentIdx));
break;
}
- int idxE = line.indexOf("}", idxS);
+ int idxE = line.indexOf('}', idxS);
String headerName = line.substring(idxS + 3, idxE);
headerName = headerName.trim();
if (!resultHttp.getRespHeaders().containsKey(headerName)) {
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 37fc8461..6807321e 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
@@ -53,6 +53,8 @@ import java.util.List;
import org.onap.cli.fw.error.OnapCommandResultMapProcessingFailed;
import org.onap.cli.fw.error.OnapCommandResultEmpty;
import static org.junit.Assert.assertFalse;
+import org.onap.cli.fw.http.connect.HttpInput;
+import org.onap.cli.fw.http.connect.HttpInput.Part;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OnapCommandUtilsTest {
@@ -205,4 +207,22 @@ public class OnapCommandUtilsTest {
+ "[\"3a2fb75b52a54e9c8093e7c154210f9e\"]}]}}}";
assertEquals(result, OnapCommandHttpUtils.normalizeJson(sample));
}
+
+ @Test
+ public void testPopulateParameters() throws OnapCommandException {
+ List <Part> multiparts = new ArrayList <HttpInput.Part> ();
+ Part part = new Part();
+ part.setContent("content");
+ multiparts.add(part);
+ Map <String, OnapCommandParameter> params = new HashMap <String, OnapCommandParameter> ();
+ OnapCommandParameter onapCommandParameter = new OnapCommandParameter();
+ onapCommandParameter.setName("CMD");
+ onapCommandParameter.setRawDefaultValue("value");
+ params.put("key", onapCommandParameter);
+ HttpInput httpInput = new HttpInput();
+ httpInput.setMultiparts(multiparts);
+ HttpInput input = OnapCommandHttpUtils.populateParameters(params, httpInput);
+ assertTrue(input != null);
+ }
+
}