From 44a21ae0bb0e6d26e4bb986764cd6edd1e8e05b5 Mon Sep 17 00:00:00 2001 From: subhash kumar singh Date: Fri, 23 Feb 2018 06:23:15 +0000 Subject: Add support for context parameter 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 --- .../onap/cli/fw/utils/OnapCommandUtilsTest.java | 41 +++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'framework/src/test/java/org') 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 11f97070..6b465c09 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 @@ -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 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 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 contextOpt = cmd.getParameters().stream() + .filter(e -> e.getName().equals("context")) + .findFirst(); + + if (contextOpt.isPresent()) { + OnapCommandParameter context = contextOpt.get(); + HashMap map = new HashMap(); + map.put("a", "b"); + context.setValue(map); + + map = (HashMap) context.getValue(); + assertTrue(map.keySet().contains("a")); + assertTrue(map.values().contains("b")); + } else { + fail("context parameter is not available"); + } } @Test -- cgit 1.2.3-korg