aboutsummaryrefslogtreecommitdiffstats
path: root/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestOofPciPocDmaapConsumers.java
blob: cd2ea6eb070c9b34bee0eeba806b64173bc6a1d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
package org.onap.ccsdk.sli.northbound.dmaapclient;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.util.Properties;

import org.junit.Before;
import org.junit.Test;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;

public class TestOofPciPocDmaapConsumers {

	private static final String pciChangesFromPolicyToSDNRInput = "{\n" + 
    		"	\"body\": {\n" + 
    		"		\"input\": {\n" + 
    		"			\"CommonHeader\": {\n" + 
    		"				\"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
    		"				\"APIVer\": \"1.0\",\n" + 
    		"				\"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
    		"				\"SubRequestID\": \"1\",\n" + 
    		"				\"RequestTrack\": {},\n" + 
    		"				\"Flags\": {}\n" + 
    		"			},\n" + 
    		"			\"Action\": \"ModifyConfig\",\n" + 
    		"			\"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" + 
    		"		}\n" + 
    		"	},\n" + 
    		"	\"version\": \"1.0\",\n" + 
    		"	\"rpc-name\": \"modifyconfig\",\n" + 
    		"	\"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
    		"	\"type\": \"request\"\n" + 
    		"}";
	
	private static final String anrChangesFromPolicyToSDNRInput = "{\n" +
            "  \"body\": {\n" +
            "    \"input\": {\n" +
            "      \"CommonHeader\": {\n" +
            "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
            "        \"APIVer\": \"1.0\",\n" +
            "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
            "        \"SubRequestID\": \"1\",\n" +
            "        \"RequestTrack\": {},\n" +
            "        \"Flags\": {}\n" +
            "      },\n" +
            "\"Action\": \"ModifyConfigANR\",\n" +
            "      \"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" +
            "    }\n" +
            "  },\n" +
            "  \"version\": \"1.0\",\n" +
            "  \"rpc-name\": \"modifyconfiganr\",\n" +
            "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
            "  \"type\": \"request\"\n" +
            "}\n" +
            "";

	@Before
	public void setUp() throws Exception {
	}
	
	/* ---------- PCI Changes DMAAP messages test cases ------------------- */
	
	@Test
	public void testPCIChangesDmaapRPCMessageBodyResponse() throws Exception {
		Properties props = new Properties();
		
		ObjectMapper oMapper = new ObjectMapper();
		JsonNode pciChangesRootNode = oMapper.readTree(pciChangesFromPolicyToSDNRInput);
		JsonNode body = pciChangesRootNode.get("body");
		JsonNode input = body.get("input");
		JsonNode payload = input.get("Payload");
		String payloadText = payload.asText();
		JsonNode configurationsJsonNode = oMapper.readTree(payloadText);
 
	    String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode, true, false);
        
        JsonNode rootNode;
        try {
        	rootNode = oMapper.readTree(rpcMsgbody);
        } catch (Exception e) {
            throw new InvalidMessageException("Cannot parse json object", e);
        }       

        assertTrue(rootNode.get("input").get("module-name") != null); 
        assertTrue(rootNode.get("input").get("rpc-name") != null); 
        assertTrue(rootNode.get("input").get("mode") != null); 
        assertTrue(rootNode.get("input").get("sli-parameter") != null); 
        
	}
	
	@Test(expected = InvalidMessageException.class)
	public void testPCIChangesDmaapProcessMsgNullMessage() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg(null);
	}

	@Test(expected = InvalidMessageException.class)
	public void testPCIChangesDmaapProcessMsgInvalidMessage() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg("test");
	}

	@Test
	public void testPCIChangesDmaapProcessMsgMissingActionHeader() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg("{\n" + 
				"	\"body\": {\n" + 
				"		\"input\": {\n" + 
				"			\"CommonHeader\": {\n" + 
				"				\"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
				"				\"APIVer\": \"1.0\",\n" + 
				"				\"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
				"				\"SubRequestID\": \"1\",\n" + 
				"				\"RequestTrack\": {},\n" + 
				"				\"Flags\": {}\n" + 
				"			},\n" + 
				"			\"RenamedAction\": \"ModifyConfig\",\n" + 
				"			\"Payload\": {\n" + 
				"				\"Configurations \": {\n" + 
				"					\"data \": {\n" + 
				"						\"FAPService \": {\n" + 
				"							\"alias\": \"Chn0330\",\n" + 
				"							\"X0005b9Lte\": {\n" + 
				"								\"phyCellIdInUse\": 6,\n" + 
				"								\"pnfName\": \"ncserver23\"\n" + 
				"							},\n" + 
				"							\"CellConfig\": {\n" + 
				"								\"LTE\": {\n" + 
				"									\"RAN\": {\n" + 
				"										\"Common\": {\n" + 
				"											\"CellIdentity\": \"Chn0330\"\n" + 
				"										}\n" + 
				"									}\n" + 
				"								}\n" + 
				"							}\n" + 
				"						}\n" + 
				"					}\n" + 
				"				}\n" + 
				"\n" + 
				"			}\n" + 
				"		}\n" + 
				"	},\n" + 
				"	\"version\": \"1.0\",\n" + 
				"	\"rpc-name\": \"modifyconfig\",\n" + 
				"	\"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
				"	\"type\": \"request\"\n" + 
				"}");
	}

	@Test
	public void testPCIChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
		String msg = "{\n" + 
				"	\"body\": {\n" + 
				"		\"input\": {\n" + 
				"			\"CommonHeader\": {\n" + 
				"				\"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" + 
				"				\"APIVer\": \"1.0\",\n" + 
				"				\"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" + 
				"				\"SubRequestID\": \"1\",\n" + 
				"				\"RequestTrack\": {},\n" + 
				"				\"Flags\": {}\n" + 
				"			},\n" + 
				"			\"Action\": \"ModifyConfig\",\n" + 
				"			\"Payload\": {\n" + 
				"				\"Configurations \": {\n" + 
				"					\"data \": {\n" + 
				"						\"FAPService \": {\n" + 
				"							\"alias\": \"Chn0330\",\n" + 
				"							\"X0005b9Lte\": {\n" + 
				"								\"phyCellIdInUse\": 6,\n" + 
				"								\"pnfName\": \"ncserver23\"\n" + 
				"							},\n" + 
				"							\"CellConfig\": {\n" + 
				"								\"LTE\": {\n" + 
				"									\"RAN\": {\n" + 
				"										\"Common\": {\n" + 
				"											\"CellIdentity\": \"Chn0330\"\n" + 
				"										}\n" + 
				"									}\n" + 
				"								}\n" + 
				"							}\n" + 
				"						}\n" + 
				"					}\n" + 
				"				}\n" + 
				"\n" + 
				"			}\n" + 
				"		}\n" + 
				"	},\n" + 
				"	\"version\": \"1.0\",\n" + 
				"	\"rpc-name\": \"modifyconfig\",\n" + 
				"	\"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" + 
				"	\"type\": \"request\"\n" + 
				"}";
		
		try {
			OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
			consumer.processMsg(msg);

		} catch (final InvalidMessageException e) {
			final String errorMsg = "Configurations is not of Type Array. Could not read configuration changes";
			assertEquals(errorMsg, e.getMessage());
		}
	}
	
	/* ---------- PCI Changes DMAAP messages test cases ------------------- */
	
	/* ---------- ANR Changes DMAAP messages test cases ------------------- */
	
	@Test
	public void testANRChangesDmaapRPCMessageBodyResponse() throws Exception {
		Properties props = new Properties();
		
		ObjectMapper oMapper = new ObjectMapper();
		JsonNode anrChangesRootNode = oMapper.readTree(anrChangesFromPolicyToSDNRInput);
		JsonNode body = anrChangesRootNode.get("body");
		JsonNode input = body.get("input");
		JsonNode payload = input.get("Payload");
		String payloadText = payload.asText();
		JsonNode configurationsJsonNode = oMapper.readTree(payloadText);
		JsonNode configurations = configurationsJsonNode.get("Configurations");
		
		for(JsonNode dataNode:configurations) {
			String rpcMsgbody = new OofPciPocDmaapConsumers(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", anrChangesFromPolicyToSDNRInput,dataNode, false, true);
	        
	        JsonNode rootNode;
	        try {
	        	rootNode = oMapper.readTree(rpcMsgbody);
	        } catch (Exception e) {
	            throw new InvalidMessageException("Cannot parse json object", e);
	        }       

	        assertTrue(rootNode.get("input").get("module-name") != null); 
	        assertTrue(rootNode.get("input").get("rpc-name") != null); 
	        assertTrue(rootNode.get("input").get("mode") != null); 
	        assertTrue(rootNode.get("input").get("sli-parameter") != null); 
		}
	}
	
	@Test(expected = InvalidMessageException.class)
	public void testANRChangesDmaapProcessMsgNullMessage() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg(null);
	}

	@Test(expected = InvalidMessageException.class)
	public void testANRChangesDmaapProcessMsgInvalidMessage() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg("test");
	}

	@Test
	public void testANRChangesDmaapProcessMsgMissingActionHeader() throws Exception {
		OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
		consumer.processMsg("{\n" +
	            "  \"body\": {\n" +
	            "    \"input\": {\n" +
	            "      \"CommonHeader\": {\n" +
	            "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
	            "        \"APIVer\": \"1.0\",\n" +
	            "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
	            "        \"SubRequestID\": \"1\",\n" +
	            "        \"RequestTrack\": {},\n" +
	            "        \"Flags\": {}\n" +
	            "      },\n" +
	            "\"NoAction\": \"ModifyConfigANR\",\n" +
	            "      \"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" +
	            "    }\n" +
	            "  },\n" +
	            "  \"version\": \"1.0\",\n" +
	            "  \"rpc-name\": \"modifyconfiganr\",\n" +
	            "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
	            "  \"type\": \"request\"\n" +
	            "}\n" +
	            "");
	}

	@Test
	public void testANRChangesDmaapProcessMsgInvalidPayloadConfigurations() throws Exception {
		String msg = "{\n" +
	            "  \"body\": {\n" +
	            "    \"input\": {\n" +
	            "      \"CommonHeader\": {\n" +
	            "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
	            "        \"APIVer\": \"1.0\",\n" +
	            "        \"RequestID\": \"722ee65a-8afd-48df-bf57-c152ae45bacc\",\n" +
	            "        \"SubRequestID\": \"1\",\n" +
	            "        \"RequestTrack\": {},\n" +
	            "        \"Flags\": {}\n" +
	            "      },\n" +
	            "\"Action\": \"ModifyConfigANR\",\n" +
	            "      \"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" +
	            "    }\n" +
	            "  },\n" +
	            "  \"version\": \"1.0\",\n" +
	            "  \"rpc-name\": \"modifyconfiganr\",\n" +
	            "  \"correlation-id\": \"722ee65a-8afd-48df-bf57-c152ae45bacc-1\",\n" +
	            "  \"type\": \"request\"\n" +
	            "}\n" +
	            "";
		
		try {
			OofPciPocDmaapConsumers consumer = new OofPciPocDmaapConsumers();
			consumer.processMsg(msg);

		} catch (final InvalidMessageException e) {
			final String errorMsg = "Cannot parse payload value";
			assertEquals(errorMsg, e.getMessage());
		}
	}
	
	/* ---------- ANR Changes DMAAP messages test cases ------------------- */
}