diff options
author | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-02-23 06:05:28 +0000 |
---|---|---|
committer | subhash kumar singh <subhash.kumar.singh@huawei.com> | 2018-02-28 09:12:38 +0000 |
commit | 225400a393da49322bdf500a61ae423ec00efead (patch) | |
tree | 2d55acf0d8b7833bd8e595cb902e29a4c789d9bb /framework/src/test/java | |
parent | 3903891dfe8f9e2488fc9d1bd0858fa4670cff0e (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 'framework/src/test/java')
-rw-r--r-- | framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java | 26 | ||||
-rw-r--r-- | framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java | 68 |
2 files changed, 67 insertions, 27 deletions
diff --git a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java index 82781b43..5a6e6458 100644 --- a/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java +++ b/framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.junit.Test; @@ -49,8 +50,13 @@ public class OnapCommandParameterTest { assertTrue("value".equals(param.getValue())); param.setParameterType(OnapCommandParameterType.ARRAY); - param.setValue(Arrays.asList("1", "2", "3")); - assertTrue("[\"1\",\"2\",\"3\"]".equals(param.getValue())); + List<String> list = Arrays.asList("1", "2", "3"); + param.setValue(list); + assertTrue(((List)param.getValue()).containsAll(list)); + + param.setRawDefaultValue("[\"1\", \"2\", \"3\", \"4\"]"); + assertTrue(((List<String>)param.getDefaultValue()) + .containsAll(Arrays.asList("1", "2", "3", "4"))); param.setParameterType(OnapCommandParameterType.MAP); Map<String, String> map = new HashMap<>(); @@ -58,16 +64,20 @@ public class OnapCommandParameterTest { map.put("Two", "2"); map.put("Three", "3"); param.setValue(map); - assertTrue("{\"One\":\"1\",\"Two\":\"2\",\"Three\":\"3\"}".equals(param.getValue())); - - param.setDefaultValue("$s{env:defaultValue}"); - assertTrue("env:defaultValue".equals(param.getDefaultValue())); + HashMap<String, String> value = (HashMap<String, String>) param.getValue(); + assertTrue(value.keySet().containsAll(Arrays.asList("One", "Two", "Three"))); + assertTrue(value.values().containsAll(Arrays.asList("1", "2", "3"))); + + param.setRawDefaultValue("{\"key1\":\"$s{env:defaultValue}\"}"); + assertTrue(((Map<String, String>)param.getDefaultValue()).values().containsAll( + Arrays.asList("env:defaultValue") + )); } @Test - public void parameterEnvDefaultValueObjTest() { + public void parameterEnvDefaultValueObjTest() throws OnapCommandInvalidParameterValue { OnapCommandParameter param = new OnapCommandParameter(); - param.setDefaultValue("$s{env:DAFAULT_VALUE}"); + param.setRawDefaultValue("$s{env:DAFAULT_VALUE}"); boolean isDefaultValueAnEnv = param.isRawDefaultValueAnEnv(); assertTrue(isDefaultValueAnEnv); 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 317920f8..11f97070 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 @@ -17,18 +17,9 @@ package org.onap.cli.fw.utils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.io.IOException; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - +import mockit.Invocation; +import mockit.Mock; +import mockit.MockUp; import org.junit.FixMethodOrder; import org.junit.Ignore; import org.junit.Test; @@ -48,9 +39,18 @@ import org.onap.cli.fw.schema.OnapCommandSchema; import org.onap.cli.fw.schema.OnapCommandSchemaInfo; import org.onap.cli.fw.schema.OnapCommandSchemaLoader; -import mockit.Invocation; -import mockit.Mock; -import mockit.MockUp; +import java.io.IOException; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class OnapCommandUtilsTest { @@ -119,7 +119,7 @@ public class OnapCommandUtilsTest { public void loadOnapCommandSchemaWithOutDefaultTest() throws OnapCommandException { OnapCommand cmd = new OnapCommandSample(); OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", false, false); - assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() == 9); + assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() == 10); } @Test(expected = OnapCommandParameterNameConflict.class) @@ -147,14 +147,44 @@ public class OnapCommandUtilsTest { assertTrue("sample-test".equals(cmd.getName()) && cmd.getParameters().size() > 9); for (OnapCommandParameter com : cmd.getParameters()) { - com.setValue("value"); + switch (com.getParameterType()) { + case STRING: + com.setValue("value"); + break; + + case ARRAY: + com.setValue(Collections.EMPTY_LIST); + break; + + case MAP: + com.setValue(new HashMap<String, String>()); + break; + + case BOOL: + com.setValue(true); + break; + + case TEXT: + com.setValue("value"); + break; + + case URL: + com.setValue("http:localhost/test"); + break; + + case JSON: + com.setValue("json"); + break; + + default: + break; + } } Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 15); + assertTrue(map.size() == 16); } - @Test public void helpCommandTest() throws IOException, OnapCommandException { OnapCommand cmd = new OnapCommandSample(); |