summaryrefslogtreecommitdiffstats
path: root/profiles
diff options
context:
space:
mode:
authorjitendra007 <jitendra.sharma1@huawei.com>2020-06-18 16:25:39 +0530
committerpriyanka.akhade <priyanka.akhade@huawei.com>2020-07-09 13:06:31 +0530
commit5f23e02caa5ab128a4c01866dec91eaea8dc7cee (patch)
treeca3c4f31dc56ce64aa9c0165b8cac4dab8e70b7c /profiles
parentc3391bef9e04c2ad38ed96bd28a5c43ab6d961de (diff)
Fixed sonarcloud issues
Issue-ID: CLI-270 Signed-off-by: jitendra007 <jitendra.sharma1@huawei.com> Change-Id: Ibb52afb2fe8fe7c9be4299d1a1cb1e3d32ab0eca
Diffstat (limited to 'profiles')
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/cmd/OpenCommandShellCmd.java16
-rw-r--r--profiles/command/src/main/java/org/onap/cli/fw/cmd/schema/OnapCommandSchemaCmdLoader.java1
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java16
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java6
-rw-r--r--profiles/http/src/test/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoaderTest.java32
-rw-r--r--profiles/http/src/test/resources/sample-test-schema-http.yaml2
-rw-r--r--profiles/snmp/src/main/java/org/onap/cli/fw/snmp/cmd/OnapSnmpCommand.java8
-rw-r--r--profiles/snmp/src/main/java/org/onap/cli/fw/snmp/schema/OnapCommandSchemaSnmpLoader.java6
8 files changed, 59 insertions, 28 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 dd2c26cd..3bb2606a 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
@@ -163,32 +163,32 @@ public class OpenCommandShellCmd extends OnapCommand {
//Process command
String []cmd = commandLine.toArray(new String []{});
String cwd = this.getWd();
- List <String> envs = new ArrayList<>();
+ List <String> envList = new ArrayList<>();
//add current process environments to sub process
for (Map.Entry<String, String> env: System.getenv().entrySet()) { //NOSONAR
- envs.add(env.getKey() + "=" + env.getValue());
+ envList.add(env.getKey() + "=" + env.getValue());
}
//add oclip specific environment variables
if (this.getExecutionContext() != null) {
- envs.add("OPEN_CLI_REQUEST_ID=" + this.getExecutionContext().getRequestId());
+ envList.add("OPEN_CLI_REQUEST_ID=" + this.getExecutionContext().getRequestId());
if (this.getExecutionContext().getProfile() != null) {
- envs.add("OPEN_CLI_PROFILE=" + this.getExecutionContext().getProfile());
+ envList.add("OPEN_CLI_PROFILE=" + this.getExecutionContext().getProfile());
}
if (OnapCommandRegistrar.getRegistrar().getHost() != null) {
- envs.add("OPEN_CLI_RPC_HOST=" + OnapCommandRegistrar.getRegistrar().getHost());
- envs.add("OPEN_CLI_RPC_PORT=" + OnapCommandRegistrar.getRegistrar().getPort());
+ envList.add("OPEN_CLI_RPC_HOST=" + OnapCommandRegistrar.getRegistrar().getHost());
+ envList.add("OPEN_CLI_RPC_PORT=" + OnapCommandRegistrar.getRegistrar().getPort());
}
}
for (String env: this.getEnvs().keySet()) {
- envs.add(env + "=" + this.getEnvs().get(env));
+ envList.add(env + "=" + this.getEnvs().get(env));
}
ProcessRunner pr = new ProcessRunner(
cmd,
- (!envs.isEmpty()) ? envs.toArray(new String []{}) : null,
+ (!envList.isEmpty()) ? envList.toArray(new String []{}) : null,
cwd);
FileOutputStream stdoutStream = null;
FileOutputStream stderrStream = null;
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 1eeadecc..2d408065 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
@@ -98,6 +98,7 @@ public class OnapCommandSchemaCmdLoader {
case OnapCommandCmdConstants.PASS_CODE:
cmd.setPassCodes((ArrayList) valMap.get(key1));
break;
+ default : // Do nothing
}
}
}
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 d064547e..e7a643ad 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
@@ -68,8 +68,8 @@ public class OnapCommandSchemaHttpLoader {
errors.addAll(OnapCommandSchemaLoader.parseSchema(cmd, defaultParameterMap, validateSchema));
}
- Map<String, List<Map<String, String>>> commandYamlMap =
- (Map<String, List<Map<String, String>>>) OnapCommandSchemaLoader.validateSchemaVersion(schemaName, cmd.getSchemaVersion());
+ Map<String, ?> commandYamlMap =
+ OnapCommandSchemaLoader.validateSchemaVersion(schemaName, cmd.getSchemaVersion());
errors.addAll(parseHttpSchema(cmd, commandYamlMap, validateSchema));
@@ -162,20 +162,18 @@ public class OnapCommandSchemaHttpLoader {
Map<String, Object> context = (Map<String, Object>) map.get(key2);
for (String key: context.keySet()) {
- switch (key) {
- case OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES:
+ if (OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES.equals(key)) {
Boolean flag = Boolean.valueOf(context.get(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES).toString());
cmd.getInput().getContext().put(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, flag.toString());
- break;
}
}
-
break;
case OnapCommandHttpConstants.MULTIPART_ENTITY_NAME:
Object multipartEntityName = map.get(key2);
cmd.getInput().setMultipartEntityName(multipartEntityName.toString());
break;
+ default : // Do nothing
}
}catch (Exception ex) {
OnapCommandUtils.throwOrCollect(new OnapCommandInvalidSchema(cmd.getSchemaName(), ex), errorList, validate);
@@ -235,6 +233,7 @@ public class OnapCommandSchemaHttpLoader {
Object mode = serviceMap.get(key);
srv.setMode(mode.toString());
break;
+ default : // Do nothing
}
}
@@ -260,6 +259,7 @@ public class OnapCommandSchemaHttpLoader {
case OnapCommandHttpConstants.SAMPLE_RESPONSE:
// (mrkanag) implement sample response handling
break;
+ default : // Do nothing
}
}
}
@@ -353,10 +353,8 @@ public class OnapCommandSchemaHttpLoader {
for (Object successCode : requestSuccessCodes) {
Integer code = Integer.valueOf(String.valueOf(successCode));
- if (code < 200 || code >= 300) {
- if ( code != 404) {
+ if ((code < 200 || code >= 300) && code != 404) {
errorList.add(OnapCommandHttpConstants.HTTP_SUCCESS_CODE_INVALID);
- }
}
}
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 ec2f572a..dcc3082d 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
@@ -52,9 +52,11 @@ import net.minidev.json.JSONArray;
public class OnapCommandHttpUtils {
- static Logger LOG = LoggerFactory.getLogger(OnapCommandHttpUtils.class);
+ static Logger log = LoggerFactory.getLogger(OnapCommandHttpUtils.class);
private static Gson gson = new GsonBuilder().serializeNulls().create();
-
+ private OnapCommandHttpUtils() {
+ throw new IllegalStateException("Utility class");
+ }
/**
* Set argument to param value.
*
diff --git a/profiles/http/src/test/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoaderTest.java b/profiles/http/src/test/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoaderTest.java
new file mode 100644
index 00000000..a6fbe9ab
--- /dev/null
+++ b/profiles/http/src/test/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoaderTest.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 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.onap.cli.fw.http.schema;
+
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class OnapCommandSchemaHttpLoaderTest {
+ @Test
+ public void validateHttpSccessCodesTest(){
+ List<String> errorList= new ArrayList<>();
+ List<Object> requestSuccessCodes=new ArrayList<>();
+ requestSuccessCodes.add("101");
+ OnapCommandSchemaHttpLoader.validateHttpSccessCodes(errorList,requestSuccessCodes);
+ }
+}
diff --git a/profiles/http/src/test/resources/sample-test-schema-http.yaml b/profiles/http/src/test/resources/sample-test-schema-http.yaml
index c78dcea4..ad25c155 100644
--- a/profiles/http/src/test/resources/sample-test-schema-http.yaml
+++ b/profiles/http/src/test/resources/sample-test-schema-http.yaml
@@ -89,6 +89,8 @@ http:
method: POST
body: '{"serviceName":"${service-name}","version":"${service-version}","url":"${service-url}","protocol":"REST","visualRange":"1","lb_policy":"hash","nodes":[{"ip":"${node-ip}","port":"${node-port}","ttl":0}]}'
headers:
+ context:
+ remove_empty_node: true
queries:
createOrUpdate: ${create-or-update}
success_codes:
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 3e841e76..4fc47538 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
@@ -116,9 +116,7 @@ public class OnapSnmpCommand extends OnapCommand {
String[] oidStrArr = oids.toArray(new String[oids.size()]);
- switch (this.command) {
-
- case OnapCommandSnmpConstants.SNMP_CMD_GET:
+ if (OnapCommandSnmpConstants.SNMP_CMD_GET.equals(this.command)) {
ResponseEvent responseEvent = snmp.send(getPDU(PDU.GET, oidStrArr), getTarget(), null);
if ( responseEvent != null) {
if (responseEvent.getResponse().getErrorStatus() == PDU.noError) {
@@ -138,10 +136,6 @@ public class OnapSnmpCommand extends OnapCommand {
} else {
throw new OnapSnmpErrorResponse("Failed to send SNMP GET command");
}
- break;
-
- default:
- break;
}
snmp.close();
} catch (IOException ex) {
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 ca3f44e0..0d708202 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
@@ -27,7 +27,9 @@ import org.onap.cli.fw.snmp.conf.OnapCommandSnmpConstants;
import org.onap.cli.fw.utils.OnapCommandUtils;
public class OnapCommandSchemaSnmpLoader {
-
+ private OnapCommandSchemaSnmpLoader() {
+ throw new IllegalStateException("Utility class");
+ }
private static List<String> validateSnmpSchemaSection(Map<String, Object> values) {
ArrayList<String> errorList = new ArrayList<>();
@@ -61,7 +63,7 @@ public class OnapCommandSchemaSnmpLoader {
case OnapCommandSnmpConstants.SNMP_COMMAND:
cmd.setCommand((String) entry.getValue());
-
+ break;
default:
break;
}