1 package org.onap.ccsdk.sli.plugins.template;
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertTrue;
6 import java.util.HashMap;
10 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
12 public class HideNullJsonTest {
15 public void testSampleTemplate() throws Exception {
16 TemplateNode t = new MockTemplateNode();
18 Map<String, String> params = new HashMap<String, String>();
19 params.put(TemplateNode.PREFIX_KEY, "output");
20 params.put(TemplateNode.OUTPUT_PATH_KEY, "mycontainer");
21 params.put(TemplateNode.TEMPLATE_PATH, "src/test/resources/HideNullJson.vtl");
23 //Setup sample data to feed into the directive
24 params.put("service-type", "\"VPN\""); //the value is quoted to test an override
25 params.put("svc-request-id", "REQ001");
26 params.put("svc-action", "CREATE");
27 params.put("service-instance-id", "SVC001");
28 params.put("customerNameTag", "customer-name");
29 params.put("customer-name", "TestCust");
30 params.put("siidTag", "\"service-instance-id\""); //the value is quoted to test an override
32 SvcLogicContext ctx = new SvcLogicContext();
33 t.evaluateTemplate(params, ctx);
34 String result = ctx.getAttribute("output.mycontainer");
35 assertTrue(result.contains("\"svc-request-id\":\"REQ001\","));
36 assertTrue(result.contains("\"svc-action\":\"CREATE\""));
37 assertFalse(result.contains("\"svc-action\":\"CREATE\",")); // there should be no trailing comma
38 assertTrue(result.contains("\"service-type\":\"VPN\","));
39 assertTrue(result.contains("\"customer-name\":\"TestCust\","));
40 assertTrue(result.contains("\"service-instance-id\":\"SVC001\""));
41 assertFalse(result.contains("\"service-instance-id\":\"SVC001\",")); // there should be no trailing comma
42 //This should be hidden by the directive because the parameter was never populated
43 assertFalse(result.contains("customer-phone-number"));