1 package jtest.org.onap.ccsdk.sli.plugins.prop;
 
   3 import java.util.HashMap;
 
   7 import static org.junit.Assert.assertEquals;
 
   8 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
   9 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  10 import org.onap.ccsdk.sli.plugins.prop.PropertiesNode;
 
  11 import org.slf4j.Logger;
 
  12 import org.slf4j.LoggerFactory;
 
  14 public class TestPropertiesNode {
 
  16     private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class);
 
  19     public void testJSONFileParsing() throws SvcLogicException {
 
  20         SvcLogicContext ctx = new SvcLogicContext();
 
  22         Map<String, String> p = new HashMap<String, String>();
 
  23         p.put("fileName", "src/test/resources/test.json");
 
  24         p.put("contextPrefix", "test-json");
 
  26         PropertiesNode rcn = new PropertiesNode();
 
  27         rcn.readProperties(p, ctx);
 
  29         assertEquals(ctx.getAttribute("test-json.message"),"The provisioned access " +
 
  30                 "bandwidth is at or exceeds 50% of the total server capacity.");
 
  34     public void testJSONFileArrayParsing() throws SvcLogicException {
 
  35         SvcLogicContext ctx = new SvcLogicContext();
 
  37         Map<String, String> p = new HashMap<String, String>();
 
  38         p.put("fileName", "src/test/resources/test.json");
 
  39         p.put("contextPrefix", "test-json");
 
  41         PropertiesNode rcn = new PropertiesNode();
 
  42         rcn.readProperties(p, ctx);
 
  44         assertEquals(ctx.getAttribute("test-json.equipment-data[0].max-server-speed"),"1600000");
 
  45         assertEquals(ctx.getAttribute("test-json.resource-state.used"),"1605000");
 
  46         assertEquals(ctx.getAttribute("test-json.resource-rule.service-model"),"DUMMY");
 
  47         assertEquals(ctx.getAttribute("test-json.resource-rule.endpoint-position"),"VCE-Cust");
 
  51     public void testJSONFileParsingPrefixCheck() throws SvcLogicException {
 
  52         SvcLogicContext ctx = new SvcLogicContext();
 
  54         Map<String, String> p = new HashMap<String, String>();
 
  55         p.put("fileName", "src/test/resources/test.json");
 
  56         p.put("contextPrefix", "");
 
  58         PropertiesNode rcn = new PropertiesNode();
 
  59         rcn.readProperties(p, ctx);
 
  61         assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
 
  62         assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
 
  63         assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
 
  64         assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
 
  65         assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
 
  66                 "speed * number-primary-servers");
 
  70     public void testJSONFileParsingNoPrefix() throws SvcLogicException {
 
  71         SvcLogicContext ctx = new SvcLogicContext();
 
  73         Map<String, String> p = new HashMap<String, String>();
 
  74         p.put("fileName", "src/test/resources/test.json");
 
  76         PropertiesNode rcn = new PropertiesNode();
 
  77         rcn.readProperties(p, ctx);
 
  79         assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
 
  80         assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
 
  81         assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
 
  82         assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
 
  83         assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
 
  84                 "speed * number-primary-servers");
 
  88     public void testJSONFileParsingCtxCheck() throws SvcLogicException {
 
  89         SvcLogicContext ctx = new SvcLogicContext();
 
  90         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
  92         Map<String, String> p = new HashMap<String, String>();
 
  93         p.put("fileName", "src/test/resources/test.json");
 
  95         PropertiesNode rcn = new PropertiesNode();
 
  96         rcn.readProperties(p, ctx);
 
  98         assertEquals(ctx.getAttribute("equipment-data[0].max-server-speed"),"1600000");
 
  99         assertEquals(ctx.getAttribute("resource-state.used"),"1605000");
 
 100         assertEquals(ctx.getAttribute("resource-rule.service-model"),"DUMMY");
 
 101         assertEquals(ctx.getAttribute("resource-rule.endpoint-position"),"VCE-Cust");
 
 102         assertEquals(ctx.getAttribute("resource-rule.hard-limit-expression"),"max-server-" +
 
 103                 "speed * number-primary-servers");
 
 104         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
 
 107     @Test(expected = SvcLogicException.class)
 
 108     public void testToPropertiesInvalidJson() throws SvcLogicException {
 
 109         SvcLogicContext ctx = new SvcLogicContext();
 
 110         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 112         Map<String, String> p = new HashMap<String, String>();
 
 113         p.put("fileName", "src/test/resources/test-invalid.json");
 
 114         p.put("contextPrefix", "invalid");
 
 116         PropertiesNode rcn = new PropertiesNode();
 
 117         rcn.readProperties(p, ctx);
 
 119         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
 
 123     public void testTXTFileParsing() throws SvcLogicException {
 
 124         SvcLogicContext ctx = new SvcLogicContext();
 
 126         Map<String, String> p = new HashMap<String, String>();
 
 127         p.put("fileName", "src/test/resources/test.txt");
 
 128         p.put("contextPrefix", "test-txt");
 
 130         PropertiesNode rcn = new PropertiesNode();
 
 131         rcn.readProperties(p, ctx);
 
 133         assertEquals(ctx.getAttribute("test-txt.service-data.service-information.service-type"),"AVPN");
 
 134         assertEquals(ctx.getAttribute("test-txt.service-configuration-notification-input.response-code"),"0");
 
 135         assertEquals(ctx.getAttribute("test-txt.operational-data.avpn-ip-port-information.port-" +
 
 136                                               "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
 
 137         assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" +
 
 138                                               "access-information.l1-customer-handoff"),"_1000BASELX");
 
 139         assertEquals(ctx.getAttribute("test-txt.service-data.avpn-ip-port-information.avpn-" +
 
 140                                               "access-information.vlan-tag-control"),"_1Q");
 
 144     public void testTXTFileParsingPrefixCheck() throws SvcLogicException {
 
 145         SvcLogicContext ctx = new SvcLogicContext();
 
 147         Map<String, String> p = new HashMap<String, String>();
 
 148         p.put("fileName", "src/test/resources/test.txt");
 
 149         p.put("contextPrefix", "");
 
 151         PropertiesNode rcn = new PropertiesNode();
 
 152         rcn.readProperties(p, ctx);
 
 154         assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
 
 155         assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
 
 156         assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
 
 157                                               "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
 
 158         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 159                                               "access-information.l1-customer-handoff"),"_1000BASELX");
 
 160         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 161                                               "access-information.vlan-tag-control"),"_1Q");
 
 165     public void testTXTFileParsingNoPrefix() throws SvcLogicException {
 
 166         SvcLogicContext ctx = new SvcLogicContext();
 
 168         Map<String, String> p = new HashMap<String, String>();
 
 169         p.put("fileName", "src/test/resources/test.txt");
 
 171         PropertiesNode rcn = new PropertiesNode();
 
 172         rcn.readProperties(p, ctx);
 
 174         assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
 
 175         assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
 
 176         assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
 
 177                                               "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
 
 178         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 179                                               "access-information.l1-customer-handoff"),"_1000BASELX");
 
 180         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 181                                               "access-information.vlan-tag-control"),"_1Q");
 
 185     public void testTXTFileParsingCtxCheck() throws SvcLogicException {
 
 186         SvcLogicContext ctx = new SvcLogicContext();
 
 187         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 189         Map<String, String> p = new HashMap<String, String>();
 
 190         p.put("fileName", "src/test/resources/test.txt");
 
 192         PropertiesNode rcn = new PropertiesNode();
 
 193         rcn.readProperties(p, ctx);
 
 195         assertEquals(ctx.getAttribute("service-data.service-information.service-type"),"AVPN");
 
 196         assertEquals(ctx.getAttribute("service-configuration-notification-input.response-code"),"0");
 
 197         assertEquals(ctx.getAttribute("operational-data.avpn-ip-port-information.port-" +
 
 198                                               "level-cos.queueing.pe-per-class-queueing-behaviors.cos3-queueing"),"WRED");
 
 199         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 200                                               "access-information.l1-customer-handoff"),"_1000BASELX");
 
 201         assertEquals(ctx.getAttribute("service-data.avpn-ip-port-information.avpn-" +
 
 202                                               "access-information.vlan-tag-control"),"_1Q");
 
 203         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
 
 206     @Test(expected = SvcLogicException.class)
 
 207     public void testToPropertiesInvalidParam() throws SvcLogicException {
 
 208         SvcLogicContext ctx = new SvcLogicContext();
 
 209         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 211         Map<String, String> p = new HashMap<String, String>();
 
 212         p.put("responsePrefix", "response");
 
 213         p.put("skipSending", "true");
 
 215         PropertiesNode rcn = new PropertiesNode();
 
 216         rcn.readProperties(p, ctx);
 
 218         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
 
 221     @Test(expected = SvcLogicException.class)
 
 222     public void testToPropertiesNoParam() throws SvcLogicException {
 
 223         SvcLogicContext ctx = new SvcLogicContext();
 
 224         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 226         Map<String, String> p = new HashMap<String, String>();
 
 228         PropertiesNode rcn = new PropertiesNode();
 
 229         rcn.readProperties(p, ctx);
 
 231         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
 
 234     @Test(expected = SvcLogicException.class)
 
 235     public void testToPropertiesFilePathError() throws SvcLogicException {
 
 236         SvcLogicContext ctx = new SvcLogicContext();
 
 237         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
 
 239         Map<String, String> p = new HashMap<String, String>();
 
 240         p.put("fileName", "src/tests/resources/test.txt");
 
 242         PropertiesNode rcn = new PropertiesNode();
 
 243         rcn.readProperties(p, ctx);
 
 245         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");