Add support for context parameter 59/32659/4
authorsubhash kumar singh <subhash.kumar.singh@huawei.com>
Fri, 23 Feb 2018 06:23:15 +0000 (06:23 +0000)
committersubhash kumar singh <subhash.kumar.singh@huawei.com>
Wed, 28 Feb 2018 09:20:29 +0000 (09:20 +0000)
Add support for context parameter, which can be used to communicate
data from framework to profile.

Change-Id: Idf77f3c225e7e65be2660f687782b37dc3da76c3
Issue-ID: CLI-74
Signed-off-by: subhash kumar singh <subhash.kumar.singh@huawei.com>
framework/src/main/resources/open-cli-schema/default_input_parameters.yaml
framework/src/test/java/org/onap/cli/fw/utils/OnapCommandUtilsTest.java
profiles/http/src/test/java/org/onap/cli/fw/http/utils/OnapCommandUtilsTest.java

index bb35ac2..1dbeedb 100644 (file)
@@ -42,4 +42,11 @@ parameters:
     short_option: t
     long_option: no-title
     default_value: false
-    is_default_param: true
\ No newline at end of file
+    is_default_param: true
+  - name: context
+    type: map
+    description: command context
+    short_option: D
+    long_option: context
+    is_default_param: true
+    is_optional: true
\ No newline at end of file
index 11f9707..6b465c0 100644 (file)
@@ -46,6 +46,7 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
@@ -182,7 +183,45 @@ public class OnapCommandUtilsTest {
         }
 
         Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
-        assertTrue(map.size() == 16);
+        assertTrue(map.size() == 17);
+    }
+
+    @Test
+    public void contextParameterTest() throws OnapCommandException {
+        OnapCommand cmd = new OnapCommandSample();
+        OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+        Optional<OnapCommandParameter> contextOpt = cmd.getParameters().stream()
+                .filter(e -> e.getName().equals("context"))
+                .findFirst();
+
+        if (contextOpt.isPresent()) {
+            OnapCommandParameter context = contextOpt.get();
+            assertTrue(context.getDefaultValue() instanceof HashMap);
+        } else {
+            fail("context parameter is not available");
+        }
+    }
+
+    @Test
+    public void contextParameterSetAndGetTest() throws OnapCommandException {
+        OnapCommand cmd = new OnapCommandSample();
+        OnapCommandSchemaLoader.loadSchema(cmd, "sample-test-schema.yaml", true, false);
+        Optional<OnapCommandParameter> contextOpt = cmd.getParameters().stream()
+                .filter(e -> e.getName().equals("context"))
+                .findFirst();
+
+        if (contextOpt.isPresent()) {
+            OnapCommandParameter context = contextOpt.get();
+            HashMap<String, String> map = new HashMap();
+            map.put("a", "b");
+            context.setValue(map);
+
+            map = (HashMap<String, String>) context.getValue();
+            assertTrue(map.keySet().contains("a"));
+            assertTrue(map.values().contains("b"));
+        } else {
+            fail("context parameter is not available");
+        }
     }
 
     @Test
index 1292051..67956a8 100644 (file)
@@ -93,7 +93,7 @@ public class OnapCommandUtilsTest {
         assertTrue("sample-test".equals(cmd.getName()));
 
         Map<String, OnapCommandParameter> map = OnapCommandUtils.getInputMap(cmd.getParameters());
-        assertTrue(map.size() == 7);
+        assertTrue(map.size() == 8);
     }
 
     @Test(expected = OnapCommandHttpHeaderNotFound.class)