1 package org.onap.ccsdk.sli.northbound.dmaapclient;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertTrue;
6 import java.util.Properties;
8 import org.junit.Before;
11 import com.fasterxml.jackson.databind.JsonNode;
12 import com.fasterxml.jackson.databind.ObjectMapper;
14 public class TestOofPciPocDmaapConsumers {
16 private static final String pciChangesFromPolicyToSDNRInput = "{\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" +
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" +
31 " \"version\": \"1.0\",\n" +
32 " \"rpc-name\": \"modifyconfig\",\n" +
33 " \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
34 " \"type\": \"request\"\n" +
37 private static final String anrChangesFromPolicyToSDNRInput = "{\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" +
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" +
52 " \"version\": \"1.0\",\n" +
53 " \"rpc-name\": \"modifyconfiganr\",\n" +
54 " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
55 " \"type\": \"request\"\n" +
60 public void setUp() throws Exception {
63 /* ---------- PCI Changes DMAAP messages test cases ------------------- */
66 public void testPCIChangesDmaapRPCMessageBodyResponse() throws Exception {
67 Properties props = new Properties();
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);
77 String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode, true, false);
81 rootNode = oMapper.readTree(rpcMsgbody);
82 } catch (Exception e) {
83 throw new InvalidMessageException("Cannot parse json object", e);
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);
93 @Test(expected = InvalidMessageException.class)
94 public void testPCIChangesDmaapProcessMsgNullMessage() throws Exception {
95 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
96 consumer.processMsg(null);
99 @Test(expected = InvalidMessageException.class)
100 public void testPCIChangesDmaapProcessMsgInvalidMessage() throws Exception {
101 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
102 consumer.processMsg("test");
106 public void testPCIChangesDmaapProcessMsgMissingActionHeader() throws Exception {
107 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
108 consumer.processMsg("{\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" +
119 " \"RenamedAction\": \"ModifyConfig\",\n" +
120 " \"Payload\": {\n" +
121 " \"Configurations \": {\n" +
123 " \"FAPService \": {\n" +
124 " \"alias\": \"Chn0330\",\n" +
125 " \"X0005b9Lte\": {\n" +
126 " \"phyCellIdInUse\": 6,\n" +
127 " \"pnfName\": \"ncserver23\"\n" +
129 " \"CellConfig\": {\n" +
133 " \"CellIdentity\": \"Chn0330\"\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" +
153 public void testPCIChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
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" +
165 " \"Action\": \"ModifyConfig\",\n" +
166 " \"Payload\": {\n" +
167 " \"Configurations \": {\n" +
169 " \"FAPService \": {\n" +
170 " \"alias\": \"Chn0330\",\n" +
171 " \"X0005b9Lte\": {\n" +
172 " \"phyCellIdInUse\": 6,\n" +
173 " \"pnfName\": \"ncserver23\"\n" +
175 " \"CellConfig\": {\n" +
179 " \"CellIdentity\": \"Chn0330\"\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" +
198 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
199 consumer.processMsg(msg);
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());
207 /* ---------- PCI Changes DMAAP messages test cases ------------------- */
209 /* ---------- ANR Changes DMAAP messages test cases ------------------- */
212 public void testANRChangesDmaapRPCMessageBodyResponse() throws Exception {
213 Properties props = new Properties();
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");
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);
229 rootNode = oMapper.readTree(rpcMsgbody);
230 } catch (Exception e) {
231 throw new InvalidMessageException("Cannot parse json object", e);
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);
241 @Test(expected = InvalidMessageException.class)
242 public void testANRChangesDmaapProcessMsgNullMessage() throws Exception {
243 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
244 consumer.processMsg(null);
247 @Test(expected = InvalidMessageException.class)
248 public void testANRChangesDmaapProcessMsgInvalidMessage() throws Exception {
249 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
250 consumer.processMsg("test");
254 public void testANRChangesDmaapProcessMsgMissingActionHeader() throws Exception {
255 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
256 consumer.processMsg("{\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" +
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" +
271 " \"version\": \"1.0\",\n" +
272 " \"rpc-name\": \"modifyconfiganr\",\n" +
273 " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
274 " \"type\": \"request\"\n" +
280 public void testANRChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
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" +
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" +
296 " \"version\": \"1.0\",\n" +
297 " \"rpc-name\": \"modifyconfiganr\",\n" +
298 " \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
299 " \"type\": \"request\"\n" +
304 OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
305 consumer.processMsg(msg);
307 } catch (final InvalidMessageException e) {
308 final String errorMsg = "Cannot parse payload value";
309 assertEquals(errorMsg, e.getMessage());
313 /* ---------- ANR Changes DMAAP messages test cases ------------------- */