diff options
author | abhishek.c92 <abhishek.c92@samsung.com> | 2022-04-28 17:57:41 +0530 |
---|---|---|
committer | Abhishek Chakrabartti <abhishek.c92@samsung.com> | 2022-05-09 11:59:28 +0000 |
commit | f3bea1cd0fd251b1d8b4bfde0ec8d88a486df9de (patch) | |
tree | 1752115171fd3906ab156d726d50619b1f13afff /main | |
parent | 82af57b3b997c975ac436b9ab2e6ba5b3cf90ea3 (diff) |
Sonar violation fixes for Parameterized tests and Lambda Expressions
Violations : Parameterized tests for OnapCommandprintTest
Use lambda expression for OnapCommandSchemaCmdLoader
Refactor method in OnapCli
Signed-off-by: abhishek.c92 <abhishek.c92@samsung.com>
Issue-ID: CLI-446
Change-Id: I8e8337d2b5993983d8ea105b2d1882952a3783a3
Diffstat (limited to 'main')
-rw-r--r-- | main/src/main/java/org/onap/cli/main/OnapCli.java | 68 |
1 files changed, 36 insertions, 32 deletions
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 08ef640f..6d6e4ff3 100644 --- a/main/src/main/java/org/onap/cli/main/OnapCli.java +++ b/main/src/main/java/org/onap/cli/main/OnapCli.java @@ -241,38 +241,7 @@ public class OnapCli { public void handleBatchCommand() { try { //NOSONAR if (this.paramFile != null) { - //Read YAML and loop thru it - // one - // - param-long-option-1: value - // - param-long-option-1: value - // - positional-arg1 - // - positional-arg2 - // two - // - param-long-option-1: value - // - param-long-option-1: value - // - positional-arg1 - // - positional-arg2 - try { - Map<String, Object> values = OnapCommandDiscoveryUtils.loadYaml(this.paramFile); - - for (Entry<String, Object> cmdsParam: values.entrySet()) { - for (Object param: (List)cmdsParam.getValue()) { - if (param instanceof Map) { //optional args - Map <String, String> paramMap = (Map<String, String>) param; - String paramName = paramMap.keySet().iterator().next(); - Object paramValue = paramMap.get(paramName); - argsParamFile.add(this.getLongOption(paramName)); - argsParamFile.add(paramValue.toString()); - } else { //positional args - argsParamFile.add(param.toString()); - } - } - } - - } catch (Exception e) { // NOSONAR - this.print("Failed to read param file " + this.paramFile); - this.print(e); - } + handleBatchCommandUtil(); } } catch (Exception e) { this.print(e); @@ -280,6 +249,41 @@ public class OnapCli { } } + private void handleBatchCommandUtil() { + //Read YAML and loop thru it + // one + // - param-long-option-1: value + // - param-long-option-1: value + // - positional-arg1 + // - positional-arg2 + // two + // - param-long-option-1: value + // - param-long-option-1: value + // - positional-arg1 + // - positional-arg2 + try { + Map<String, Object> values = OnapCommandDiscoveryUtils.loadYaml(this.paramFile); + + for (Entry<String, Object> cmdsParam: values.entrySet()) { + for (Object param: (List)cmdsParam.getValue()) { + if (param instanceof Map) { //optional args + Map <String, String> paramMap = (Map<String, String>) param; + String paramName = paramMap.keySet().iterator().next(); + Object paramValue = paramMap.get(paramName); + argsParamFile.add(this.getLongOption(paramName)); + argsParamFile.add(paramValue.toString()); + } else { //positional args + argsParamFile.add(param.toString()); + } + } + } + + } catch (Exception e) { // NOSONAR + this.print("Failed to read param file " + this.paramFile); + this.print(e); + } + } + public void verifyCommand(OnapCommand cmd) throws OnapCommandException { OnapCliArgsParser.populateParams(cmd.getParameters(), args); |