From 225400a393da49322bdf500a61ae423ec00efead Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Fri, 23 Feb 2018 06:05:28 +0000 Subject: 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 --- .../cli/fw/input/OnapCommandParameterTest.java | 26 ++++++--- .../onap/cli/fw/utils/OnapCommandUtilsTest.java | 68 ++++++++++++++++------ 2 files changed, 67 insertions(+), 27 deletions(-) (limited to 'framework/src/test/java/org') 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 list = Arrays.asList("1", "2", "3"); + param.setValue(list); + assertTrue(((List)param.getValue()).containsAll(list)); + + param.setRawDefaultValue("[\"1\", \"2\", \"3\", \"4\"]"); + assertTrue(((List)param.getDefaultValue()) + .containsAll(Arrays.asList("1", "2", "3", "4"))); param.setParameterType(OnapCommandParameterType.MAP); Map 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 value = (HashMap) 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)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()); + 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 map = OnapCommandUtils.getInputMap(cmd.getParameters()); - assertTrue(map.size() == 15); + assertTrue(map.size() == 16); } - @Test public void helpCommandTest() throws IOException, OnapCommandException { OnapCommand cmd = new OnapCommandSample(); -- cgit 1.2.3-korg