aboutsummaryrefslogtreecommitdiffstats
path: root/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestPciChangesFromPolicyToSDNRDmaapConsumer.java
blob: a42bc48f697a8360c64c0c10d1090752d297b9d2 (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
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 TestPciChangesFromPolicyToSDNRDmaapConsumer {
    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" + 
    		"}";
    
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testRPCMessageBodyResponse() 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 PciChangesFromPolicyToSDNRDmaapConsumer(props).publish("src/main/resources/anr-pci-changes-from-policy-to-sdnr.vt", pciChangesFromPolicyToSDNRInput,configurationsJsonNode);
        
        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 testProcessMsgNullMessage() throws Exception {
		PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer();
		consumer.processMsg(null);
	}

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

	@Test
	public void testProcessMsgMissingActionHeader() throws Exception {
		PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer();
		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 testProcessMsgInvalidPayloadConfigurations() 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 {
			PciChangesFromPolicyToSDNRDmaapConsumer consumer = new PciChangesFromPolicyToSDNRDmaapConsumer();
			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());
		}
	}
}