Merge "Sonar fix: TemplateNode.java"
[ccsdk/sli/plugins.git] / template-node / provider / src / test / java / org / onap / ccsdk / sli / plugins / template / HideNullJsonTest.java
1 package org.onap.ccsdk.sli.plugins.template;
2
3 import static org.junit.Assert.assertFalse;
4 import static org.junit.Assert.assertTrue;
5
6 import java.util.HashMap;
7 import java.util.Map;
8
9 import org.junit.Test;
10 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
11
12 public class HideNullJsonTest {
13
14     @Test
15     public void testSampleTemplate() throws Exception {
16         TemplateNode t = new MockTemplateNode();
17
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");
22         
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
31
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"));
44     }
45
46 }