diff options
author | Smokowski, Kevin (ks6305) <kevin.smokowski@att.com> | 2019-01-03 22:00:51 +0000 |
---|---|---|
committer | Kevin Smokowski <kevin.smokowski@att.com> | 2019-01-03 22:04:46 +0000 |
commit | 57fd31e090909d55a36f957e45a84d9295254d44 (patch) | |
tree | dd2d69f9285b060b850e868b4e2554b23605b037 /template-node/provider/src/test/java | |
parent | 62e62331a294052109f02686e4529fe613355990 (diff) |
create a directive for the template node
The directive is called hideNullJson, it hides json when it is null to deal with optional json attributes
Change-Id: I0b7a2c2f19e6f83e0d8c8c6f3552889c83dc997f
Issue-ID: CCSDK-903
Signed-off-by: Smokowski, Kevin (ks6305) <kevin.smokowski@att.com>
Diffstat (limited to 'template-node/provider/src/test/java')
-rwxr-xr-x | template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/HideNullJsonTest.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/HideNullJsonTest.java b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/HideNullJsonTest.java new file mode 100755 index 00000000..1fb1f676 --- /dev/null +++ b/template-node/provider/src/test/java/org/onap/ccsdk/sli/plugins/template/HideNullJsonTest.java @@ -0,0 +1,46 @@ +package org.onap.ccsdk.sli.plugins.template; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class HideNullJsonTest { + + @Test + public void testSampleTemplate() throws Exception { + TemplateNode t = new MockTemplateNode(); + + Map<String, String> params = new HashMap<String, String>(); + params.put(TemplateNode.PREFIX_KEY, "output"); + params.put(TemplateNode.OUTPUT_PATH_KEY, "mycontainer"); + params.put(TemplateNode.TEMPLATE_PATH, "src/test/resources/HideNullJson.vtl"); + + //Setup sample data to feed into the directive + params.put("service-type", "\"VPN\""); //the value is quoted to test an override + params.put("svc-request-id", "REQ001"); + params.put("svc-action", "CREATE"); + params.put("service-instance-id", "SVC001"); + params.put("customerNameTag", "customer-name"); + params.put("customer-name", "TestCust"); + params.put("siidTag", "\"service-instance-id\""); //the value is quoted to test an override + + SvcLogicContext ctx = new SvcLogicContext(); + t.evaluateTemplate(params, ctx); + String result = ctx.getAttribute("output.mycontainer"); + assertTrue(result.contains("\"svc-request-id\":\"REQ001\",")); + assertTrue(result.contains("\"svc-action\":\"CREATE\"")); + assertFalse(result.contains("\"svc-action\":\"CREATE\",")); // there should be no trailing comma + assertTrue(result.contains("\"service-type\":\"VPN\",")); + assertTrue(result.contains("\"customer-name\":\"TestCust\",")); + assertTrue(result.contains("\"service-instance-id\":\"SVC001\"")); + assertFalse(result.contains("\"service-instance-id\":\"SVC001\",")); // there should be no trailing comma + //This should be hidden by the directive because the parameter was never populated + assertFalse(result.contains("customer-phone-number")); + } + +}
\ No newline at end of file |