Merge "CCSDK PropNode can read JSON and put to ctx"
[ccsdk/sli/plugins.git] / properties-node / provider / src / test / java / jtest / org / onap / ccsdk / sli / plugins / prop / TestPropertiesNode.java
1 package jtest.org.onap.ccsdk.sli.plugins.prop;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.junit.Test;
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;
13
14 public class TestPropertiesNode {
15
16     private static final Logger log = LoggerFactory.getLogger(TestPropertiesNode.class);
17     
18     @Test
19     public void testJSONFileParsing() throws SvcLogicException {
20         SvcLogicContext ctx = new SvcLogicContext();
21
22         Map<String, String> p = new HashMap<String, String>();
23         p.put("fileName", "src/test/resources/test.json");
24         p.put("contextPrefix", "test-json");
25
26         PropertiesNode rcn = new PropertiesNode();
27         rcn.readProperties(p, ctx);
28
29         assertEquals(ctx.getAttribute("test-json.message"),"The provisioned access " +
30                 "bandwidth is at or exceeds 50% of the total server capacity.");
31     }
32
33     @Test
34     public void testJSONFileArrayParsing() throws SvcLogicException {
35         SvcLogicContext ctx = new SvcLogicContext();
36
37         Map<String, String> p = new HashMap<String, String>();
38         p.put("fileName", "src/test/resources/test.json");
39         p.put("contextPrefix", "test-json");
40
41         PropertiesNode rcn = new PropertiesNode();
42         rcn.readProperties(p, ctx);
43
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");
48     }
49
50     @Test
51     public void testJSONFileParsingPrefixCheck() throws SvcLogicException {
52         SvcLogicContext ctx = new SvcLogicContext();
53
54         Map<String, String> p = new HashMap<String, String>();
55         p.put("fileName", "src/test/resources/test.json");
56         p.put("contextPrefix", "");
57
58         PropertiesNode rcn = new PropertiesNode();
59         rcn.readProperties(p, ctx);
60
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");
67     }
68
69     @Test
70     public void testJSONFileParsingNoPrefix() throws SvcLogicException {
71         SvcLogicContext ctx = new SvcLogicContext();
72
73         Map<String, String> p = new HashMap<String, String>();
74         p.put("fileName", "src/test/resources/test.json");
75
76         PropertiesNode rcn = new PropertiesNode();
77         rcn.readProperties(p, ctx);
78
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");
85     }
86
87     @Test
88     public void testJSONFileParsingCtxCheck() throws SvcLogicException {
89         SvcLogicContext ctx = new SvcLogicContext();
90         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
91
92         Map<String, String> p = new HashMap<String, String>();
93         p.put("fileName", "src/test/resources/test.json");
94
95         PropertiesNode rcn = new PropertiesNode();
96         rcn.readProperties(p, ctx);
97
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");
105     }
106
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");
111
112         Map<String, String> p = new HashMap<String, String>();
113         p.put("fileName", "src/test/resources/test-invalid.json");
114         p.put("contextPrefix", "invalid");
115
116         PropertiesNode rcn = new PropertiesNode();
117         rcn.readProperties(p, ctx);
118
119         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
120     }
121
122     @Test
123     public void testTXTFileParsing() throws SvcLogicException {
124         SvcLogicContext ctx = new SvcLogicContext();
125
126         Map<String, String> p = new HashMap<String, String>();
127         p.put("fileName", "src/test/resources/test.txt");
128         p.put("contextPrefix", "test-txt");
129
130         PropertiesNode rcn = new PropertiesNode();
131         rcn.readProperties(p, ctx);
132
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");
141     }
142
143     @Test
144     public void testTXTFileParsingPrefixCheck() throws SvcLogicException {
145         SvcLogicContext ctx = new SvcLogicContext();
146
147         Map<String, String> p = new HashMap<String, String>();
148         p.put("fileName", "src/test/resources/test.txt");
149         p.put("contextPrefix", "");
150
151         PropertiesNode rcn = new PropertiesNode();
152         rcn.readProperties(p, ctx);
153
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");
162     }
163
164     @Test
165     public void testTXTFileParsingNoPrefix() throws SvcLogicException {
166         SvcLogicContext ctx = new SvcLogicContext();
167
168         Map<String, String> p = new HashMap<String, String>();
169         p.put("fileName", "src/test/resources/test.txt");
170
171         PropertiesNode rcn = new PropertiesNode();
172         rcn.readProperties(p, ctx);
173
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");
182     }
183
184     @Test
185     public void testTXTFileParsingCtxCheck() throws SvcLogicException {
186         SvcLogicContext ctx = new SvcLogicContext();
187         ctx.setAttribute("tmp.sdn-circuit-req-row_length", "1");
188
189         Map<String, String> p = new HashMap<String, String>();
190         p.put("fileName", "src/test/resources/test.txt");
191
192         PropertiesNode rcn = new PropertiesNode();
193         rcn.readProperties(p, ctx);
194
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");
204     }
205
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");
210
211         Map<String, String> p = new HashMap<String, String>();
212         p.put("responsePrefix", "response");
213         p.put("skipSending", "true");
214
215         PropertiesNode rcn = new PropertiesNode();
216         rcn.readProperties(p, ctx);
217
218         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
219     }
220
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");
225
226         Map<String, String> p = new HashMap<String, String>();
227
228         PropertiesNode rcn = new PropertiesNode();
229         rcn.readProperties(p, ctx);
230
231         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
232     }
233
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");
238
239         Map<String, String> p = new HashMap<String, String>();
240         p.put("fileName", "src/tests/resources/test.txt");
241
242         PropertiesNode rcn = new PropertiesNode();
243         rcn.readProperties(p, ctx);
244
245         assertEquals(ctx.getAttribute("tmp.sdn-circuit-req-row_length"),"1");
246     }
247 }