summaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>2018-02-23 06:05:28 +0000
committersubhash kumar singh <subhash.kumar.singh@huawei.com>2018-02-28 09:12:38 +0000
commit225400a393da49322bdf500a61ae423ec00efead (patch)
tree2d55acf0d8b7833bd8e595cb902e29a4c789d9bb /main
parent3903891dfe8f9e2488fc9d1bd0858fa4670cff0e (diff)
Make default value type object
Enhance default value type from String to Object so that it will directly support different type (BOOL, Array, Map). Issue-ID: CLI-74 Change-Id: Iaca438e58150c80047340acba92917ecae685242 Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
Diffstat (limited to 'main')
-rw-r--r--main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java20
-rw-r--r--main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java19
2 files changed, 22 insertions, 17 deletions
diff --git a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
index fdf6d5b8..16d6a285 100644
--- a/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
+++ b/main/src/main/java/org/onap/cli/main/utils/OnapCliArgsParser.java
@@ -105,7 +105,7 @@ public class OnapCliArgsParser {
// end of the list or if its option rather than a value
if ((i + 1) == args.size() || args.get(i + 1).startsWith("-")) {
if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.BOOL)) {
- paramMap.get(paramName).setValue("true");
+ paramMap.get(paramName).setValue(true);
continue;
}
throw new OnapCliArgumentValueMissing(args.get(i));
@@ -124,13 +124,8 @@ public class OnapCliArgsParser {
} else if (paramMap.get(paramName).getParameterType()
.equals(OnapCommandParameterType.ARRAY)) {
Object value = paramMap.get(paramName).getValue();
- List<String> list;
- if (value == "") {
- list = new ArrayList<>();
- } else {
- list = convertJsonToListString(paramMap.get(paramName).getName(),
- value.toString());
- }
+ List<String> list = (List<String>) value;
+
list.add(args.get(i + 1));
paramMap.get(paramName).setValue(list);
i++;
@@ -138,14 +133,7 @@ public class OnapCliArgsParser {
} else if (paramMap.get(paramName).getParameterType().equals(OnapCommandParameterType.MAP)) {
Object value = paramMap.get(paramName).getValue();
- Map<String, String> map;
-
- if (value == "") {
- map = new HashMap<>();
- } else {
- map = convertJsonToMapString(paramMap.get(paramName).getName(),
- value.toString());
- }
+ Map<String, String> map = (Map<String, String>) value;
String arg = args.get(i + 1);
String[] argArr = arg.split("=");
diff --git a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java
index eb2ca294..c3627ca2 100644
--- a/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java
+++ b/main/src/test/java/org/onap/cli/main/utils/OnapCliUtilsTest.java
@@ -21,6 +21,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
+import java.util.Map;
+import java.util.Optional;
import java.util.Set;
import org.junit.Assert;
@@ -255,7 +257,7 @@ public class OnapCliUtilsTest {
OnapCliArgsParser.populateParams(paramslist,
Arrays.asList("show", "--map", "param1=value1", "--map", "param2=value2"));
- Assert.assertEquals("{\"param1\":\"value1\",\"param2\":\"value2\"}", paramslist.iterator().next().getValue().toString());
+ Assert.assertEquals("{param1=value1, param2=value2}", paramslist.iterator().next().getValue().toString());
}
@Test(expected = OnapCliInvalidArgument.class)
@@ -360,4 +362,19 @@ public class OnapCliUtilsTest {
Assert.assertEquals("--json-param", paramslist.iterator().next().getValue());
}
+
+ @Test
+ public void testArrayCommandArg() throws OnapCommandException {
+ OnapCommandParameter arrParam = new OnapCommandParameter();
+ arrParam.setShortOption("q");
+ arrParam.setParameterType(OnapCommandParameterType.ARRAY);
+ arrParam.setName("array-param");
+ Set<OnapCommandParameter> paramslist = new HashSet<>();
+ paramslist.add(arrParam);
+ String[] args = new String[] { "sample-create", "-q", "test1", "-q", "test2" };
+
+ OnapCliArgsParser.populateParams(paramslist, Arrays.asList(args));
+ Assert.assertTrue(((List<String>) arrParam.getValue())
+ .containsAll(Arrays.asList("test1", "test2")));
+ }
} \ No newline at end of file