summaryrefslogtreecommitdiffstats
path: root/framework/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'framework/src/test')
-rw-r--r--framework/src/test/java/org/onap/cli/fw/input/OnapCommandParameterTest.java26
-rw-r--r--framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java68
-rw-r--r--framework/src/test/resources/open-cli-schema/sample-test-schema.yaml6
3 files changed, 73 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();
diff --git a/framework/src/test/resources/open-cli-schema/sample-test-schema.yaml b/framework/src/test/resources/open-cli-schema/sample-test-schema.yaml
index 3c4ace83..f4894b3f 100644
--- a/framework/src/test/resources/open-cli-schema/sample-test-schema.yaml
+++ b/framework/src/test/resources/open-cli-schema/sample-test-schema.yaml
@@ -69,6 +69,12 @@ parameters:
description: Oclip positional args, if no short option and no long option given for it
is_optional: true
default_value: http://localhost:8082/file.txt
+ - name: array-param
+ type: array
+ description: list parameter
+ long_option: list-param
+ short_option: q
+ is_optional: true
results:
direction: portrait
attributes: