cd2ea6eb070c9b34bee0eeba806b64173bc6a1d7
[ccsdk/sli.git] /
1 package org.onap.ccsdk.sli.northbound.dmaapclient;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
5
6 import java.util.Properties;
7
8 import org.junit.Before;
9 import org.junit.Test;
10
11 import com.fasterxml.jackson.databind.JsonNode;
12 import com.fasterxml.jackson.databind.ObjectMapper;
13
14 public class TestOofPciPocDmaapConsumers {
15
16         private static final String pciChangesFromPolicyToSDNRInput = "{\n" + 
17                 "       \"body\": {\n" + 
18                 "               \"input\": {\n" + 
19                 "                       \"CommonHeader\": {\n" + 
20                 "                               \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
21                 "                               \"APIVer\": \"1.0\",\n" + 
22                 "                               \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
23                 "                               \"SubRequestID\": \"1\",\n" + 
24                 "                               \"RequestTrack\": {},\n" + 
25                 "                               \"Flags\": {}\n" + 
26                 "                       },\n" + 
27                 "                       \"Action\": \"ModifyConfig\",\n" + 
28                 "                       \"Payload\": \"{\\\"Configurations\\\":[{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0330\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":6,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0330\\\"}}}}}}},{\\\"data\\\":{\\\"FAPService\\\":{\\\"alias\\\":\\\"Chn0331\\\",\\\"X0005b9Lte\\\":{\\\"phyCellIdInUse\\\":7,\\\"pnfName\\\":\\\"ncserver23\\\"},\\\"CellConfig\\\":{\\\"LTE\\\":{\\\"RAN\\\":{\\\"Common\\\":{\\\"CellIdentity\\\":\\\"Chn0331\\\"}}}}}}}]}\"\n" + 
29                 "               }\n" + 
30                 "       },\n" + 
31                 "       \"version\": \"1.0\",\n" + 
32                 "       \"rpc-name\": \"modifyconfig\",\n" + 
33                 "       \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
34                 "       \"type\": \"request\"\n" + 
35                 "}";
36         
37         private static final String anrChangesFromPolicyToSDNRInput = "{\n" +
38             "  \"body\": {\n" +
39             "    \"input\": {\n" +
40             "      \"CommonHeader\": {\n" +
41             "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
42             "        \"APIVer\": \"1.0\",\n" +
43             "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
44             "        \"SubRequestID\": \"1\",\n" +
45             "        \"RequestTrack\": {},\n" +
46             "        \"Flags\": {}\n" +
47             "      },\n" +
48             "\"Action\": \"ModifyConfigANR\",\n" +
49             "      \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" +
50             "    }\n" +
51             "  },\n" +
52             "  \"version\": \"1.0\",\n" +
53             "  \"rpc-name\": \"modifyconfiganr\",\n" +
54             "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
55             "  \"type\": \"request\"\n" +
56             "}\n" +
57             "";
58
59         @Before
60         public void setUp() throws Exception {
61         }
62         
63         /* ---------- PCI Changes DMAAP messages test cases ------------------- */
64         
65         @Test
66         public void testPCIChangesDmaapRPCMessageBodyResponse() throws Exception {
67                 Properties props = new Properties();
68                 
69                 ObjectMapper oMapper = new ObjectMapper();
70                 JsonNode pciChangesRootNode = oMapper.readTree(pciChangesFromPolicyToSDNRInput);
71                 JsonNode body = pciChangesRootNode.get("body");
72                 JsonNode input = body.get("input");
73                 JsonNode payload = input.get("Payload");
74                 String payloadText = payload.asText();
75                 JsonNode configurationsJsonNode = oMapper.readTree(payloadText);
76  
77             String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode, true, false);
78         
79         JsonNode rootNode;
80         try {
81                 rootNode = oMapper.readTree(rpcMsgbody);
82         } catch (Exception e) {
83             throw new InvalidMessageException("Cannot parse json object", e);
84         }       
85
86         assertTrue(rootNode.get("input").get("module-name") != null); 
87         assertTrue(rootNode.get("input").get("rpc-name") != null); 
88         assertTrue(rootNode.get("input").get("mode") != null); 
89         assertTrue(rootNode.get("input").get("sli-parameter") != null); 
90         
91         }
92         
93         @Test(expected = InvalidMessageException.class)
94         public void testPCIChangesDmaapProcessMsgNullMessage() throws Exception {
95                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
96                 consumer.processMsg(null);
97         }
98
99         @Test(expected = InvalidMessageException.class)
100         public void testPCIChangesDmaapProcessMsgInvalidMessage() throws Exception {
101                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
102                 consumer.processMsg("test");
103         }
104
105         @Test
106         public void testPCIChangesDmaapProcessMsgMissingActionHeader() throws Exception {
107                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
108                 consumer.processMsg("{\n" + 
109                                 "       \"body\": {\n" + 
110                                 "               \"input\": {\n" + 
111                                 "                       \"CommonHeader\": {\n" + 
112                                 "                               \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
113                                 "                               \"APIVer\": \"1.0\",\n" + 
114                                 "                               \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
115                                 "                               \"SubRequestID\": \"1\",\n" + 
116                                 "                               \"RequestTrack\": {},\n" + 
117                                 "                               \"Flags\": {}\n" + 
118                                 "                       },\n" + 
119                                 "                       \"RenamedAction\": \"ModifyConfig\",\n" + 
120                                 "                       \"Payload\": {\n" + 
121                                 "                               \"Configurations \": {\n" + 
122                                 "                                       \"data \": {\n" + 
123                                 "                                               \"FAPService \": {\n" + 
124                                 "                                                       \"alias\": \"Chn0330\",\n" + 
125                                 "                                                       \"X0005b9Lte\": {\n" + 
126                                 "                                                               \"phyCellIdInUse\": 6,\n" + 
127                                 "                                                               \"pnfName\": \"ncserver23\"\n" + 
128                                 "                                                       },\n" + 
129                                 "                                                       \"CellConfig\": {\n" + 
130                                 "                                                               \"LTE\": {\n" + 
131                                 "                                                                       \"RAN\": {\n" + 
132                                 "                                                                               \"Common\": {\n" + 
133                                 "                                                                                       \"CellIdentity\": \"Chn0330\"\n" + 
134                                 "                                                                               }\n" + 
135                                 "                                                                       }\n" + 
136                                 "                                                               }\n" + 
137                                 "                                                       }\n" + 
138                                 "                                               }\n" + 
139                                 "                                       }\n" + 
140                                 "                               }\n" + 
141                                 "\n" + 
142                                 "                       }\n" + 
143                                 "               }\n" + 
144                                 "       },\n" + 
145                                 "       \"version\": \"1.0\",\n" + 
146                                 "       \"rpc-name\": \"modifyconfig\",\n" + 
147                                 "       \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
148                                 "       \"type\": \"request\"\n" + 
149                                 "}");
150         }
151
152         @Test
153         public void testPCIChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
154                 String msg = "{\n" + 
155                                 "       \"body\": {\n" + 
156                                 "               \"input\": {\n" + 
157                                 "                       \"CommonHeader\": {\n" + 
158                                 "                               \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
159                                 "                               \"APIVer\": \"1.0\",\n" + 
160                                 "                               \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
161                                 "                               \"SubRequestID\": \"1\",\n" + 
162                                 "                               \"RequestTrack\": {},\n" + 
163                                 "                               \"Flags\": {}\n" + 
164                                 "                       },\n" + 
165                                 "                       \"Action\": \"ModifyConfig\",\n" + 
166                                 "                       \"Payload\": {\n" + 
167                                 "                               \"Configurations \": {\n" + 
168                                 "                                       \"data \": {\n" + 
169                                 "                                               \"FAPService \": {\n" + 
170                                 "                                                       \"alias\": \"Chn0330\",\n" + 
171                                 "                                                       \"X0005b9Lte\": {\n" + 
172                                 "                                                               \"phyCellIdInUse\": 6,\n" + 
173                                 "                                                               \"pnfName\": \"ncserver23\"\n" + 
174                                 "                                                       },\n" + 
175                                 "                                                       \"CellConfig\": {\n" + 
176                                 "                                                               \"LTE\": {\n" + 
177                                 "                                                                       \"RAN\": {\n" + 
178                                 "                                                                               \"Common\": {\n" + 
179                                 "                                                                                       \"CellIdentity\": \"Chn0330\"\n" + 
180                                 "                                                                               }\n" + 
181                                 "                                                                       }\n" + 
182                                 "                                                               }\n" + 
183                                 "                                                       }\n" + 
184                                 "                                               }\n" + 
185                                 "                                       }\n" + 
186                                 "                               }\n" + 
187                                 "\n" + 
188                                 "                       }\n" + 
189                                 "               }\n" + 
190                                 "       },\n" + 
191                                 "       \"version\": \"1.0\",\n" + 
192                                 "       \"rpc-name\": \"modifyconfig\",\n" + 
193                                 "       \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
194                                 "       \"type\": \"request\"\n" + 
195                                 "}";
196                 
197                 try {
198                         OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
199                         consumer.processMsg(msg);
200
201                 } catch (final InvalidMessageException e) {
202                         final String errorMsg = "Configurations is not of Type Array. Could not read configuration changes";
203                         assertEquals(errorMsg, e.getMessage());
204                 }
205         }
206         
207         /* ---------- PCI Changes DMAAP messages test cases ------------------- */
208         
209         /* ---------- ANR Changes DMAAP messages test cases ------------------- */
210         
211         @Test
212         public void testANRChangesDmaapRPCMessageBodyResponse() throws Exception {
213                 Properties props = new Properties();
214                 
215                 ObjectMapper oMapper = new ObjectMapper();
216                 JsonNode anrChangesRootNode = oMapper.readTree(anrChangesFromPolicyToSDNRInput);
217                 JsonNode body = anrChangesRootNode.get("body");
218                 JsonNode input = body.get("input");
219                 JsonNode payload = input.get("Payload");
220                 String payloadText = payload.asText();
221                 JsonNode configurationsJsonNode = oMapper.readTree(payloadText);
222                 JsonNode configurations = configurationsJsonNode.get("Configurations");
223                 
224                 for(JsonNode dataNode:configurations) {
225                         String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", anrChangesFromPolicyToSDNRInput,dataNode, false, true);
226                 
227                 JsonNode rootNode;
228                 try {
229                         rootNode = oMapper.readTree(rpcMsgbody);
230                 } catch (Exception e) {
231                     throw new InvalidMessageException("Cannot parse json object", e);
232                 }       
233
234                 assertTrue(rootNode.get("input").get("module-name") != null); 
235                 assertTrue(rootNode.get("input").get("rpc-name") != null); 
236                 assertTrue(rootNode.get("input").get("mode") != null); 
237                 assertTrue(rootNode.get("input").get("sli-parameter") != null); 
238                 }
239         }
240         
241         @Test(expected = InvalidMessageException.class)
242         public void testANRChangesDmaapProcessMsgNullMessage() throws Exception {
243                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
244                 consumer.processMsg(null);
245         }
246
247         @Test(expected = InvalidMessageException.class)
248         public void testANRChangesDmaapProcessMsgInvalidMessage() throws Exception {
249                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
250                 consumer.processMsg("test");
251         }
252
253         @Test
254         public void testANRChangesDmaapProcessMsgMissingActionHeader() throws Exception {
255                 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
256                 consumer.processMsg("{\n" +
257                     "  \"body\": {\n" +
258                     "    \"input\": {\n" +
259                     "      \"CommonHeader\": {\n" +
260                     "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
261                     "        \"APIVer\": \"1.0\",\n" +
262                     "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
263                     "        \"SubRequestID\": \"1\",\n" +
264                     "        \"RequestTrack\": {},\n" +
265                     "        \"Flags\": {}\n" +
266                     "      },\n" +
267                     "\"NoAction\": \"ModifyConfigANR\",\n" +
268                     "      \"Payload\": \"{ \\\"Configurations\\\":[ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}] } } } } } } } ] }\"\n" +
269                     "    }\n" +
270                     "  },\n" +
271                     "  \"version\": \"1.0\",\n" +
272                     "  \"rpc-name\": \"modifyconfiganr\",\n" +
273                     "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
274                     "  \"type\": \"request\"\n" +
275                     "}\n" +
276                     "");
277         }
278
279         @Test
280         public void testANRChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
281                 String msg = "{\n" +
282                     "  \"body\": {\n" +
283                     "    \"input\": {\n" +
284                     "      \"CommonHeader\": {\n" +
285                     "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
286                     "        \"APIVer\": \"1.0\",\n" +
287                     "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
288                     "        \"SubRequestID\": \"1\",\n" +
289                     "        \"RequestTrack\": {},\n" +
290                     "        \"Flags\": {}\n" +
291                     "      },\n" +
292                     "\"Action\": \"ModifyConfigANR\",\n" +
293                     "      \"Payload\": \"{ \\\"Configurations\\\":{ { \\\"data\\\":{ \\\"FAPService\\\":{ \\\"alias\\\":\\\"Cell1\\\", \\\"CellConfig\\\":{ \\\"LTE\\\":{ \\\"RAN\\\":{ \\\"Common\\\":{ \\\"CellIdentity\\\":\\\"1\\\" }, \\\"NeighborListInUse\\\" : { \\\"LTECellNumberOfEntries\\\" : \\\"1\\\" , \\\"LTECell\\\" : [{ \\\"PLMNID\\\" :\\\"plmnid1\\\", \\\"CID\\\":\\\"Chn0001\\\", \\\"PhyCellID\\\":\\\"3\\\", \\\"PNFName\\\":\\\"ncserver01\\\", \\\"Blacklisted\\\":\\\"false\\\"}} } } } } } } } ] }\"\n" +
294                     "    }\n" +
295                     "  },\n" +
296                     "  \"version\": \"1.0\",\n" +
297                     "  \"rpc-name\": \"modifyconfiganr\",\n" +
298                     "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
299                     "  \"type\": \"request\"\n" +
300                     "}\n" +
301                     "";
302                 
303                 try {
304                         OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
305                         consumer.processMsg(msg);
306
307                 } catch (final InvalidMessageException e) {
308                         final String errorMsg = "Cannot parse payload value";
309                         assertEquals(errorMsg, e.getMessage());
310                 }
311         }
312         
313         /* ---------- ANR Changes DMAAP messages test cases ------------------- */
314 }