122a6d40b1bcf997b269cfa33b8293185d86b966
[ccsdk/sli.git] /
1 /*
2  * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
3  * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
4  * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
5  * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
6  * Vestibulum commodo. Ut rhoncus gravida arcu.
7  */
8
9 package org.onap.ccsdk.sli.northbound.dmaapclient;
10
11 import static org.junit.Assert.assertTrue;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.InputStream;
16 import java.lang.reflect.Field;
17 import java.util.Map;
18 import java.util.Properties;
19
20 import org.apache.commons.io.FileUtils;
21
22 import org.junit.Before;
23 import org.junit.Test;
24
25 import com.fasterxml.jackson.databind.JsonNode;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27
28
29 public class TestCMNotifyDmaapConsumer {
30     private static final String cMNotifyInput =  "{\n" +
31     " \"body\": {\n" +
32     "    \"input\": {\n" +
33     "      \"CommonHeader\": {\n" +
34     "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
35     "        \"APIver\": \"1.0\",\n" +
36     "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
37     "        \"SubRequestID\": \"1\",\n" +
38     "        \"RequestTrack\": {},\n" +
39     "        \"Flags\": {}\n      },\n" +
40     "      \"Action\": \"nbrlist-change-notification\",\n" +
41     "      \"Payload\": {\n" +
42      "        \"fap-service-number-of-entries-changed\": 1,\n" +
43      "        \"fap-service\": [{ \"alias\": \n" +
44      "        \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" +
45      "        \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" +
46      "        [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" +
47      "        \"pnf-name\": \"ncserver1\",\n" +
48      "        \"blacklisted\": false }] }] }\n" +
49      "     }\n" +
50     "    },\n" +
51     "    \"version\": \"1.0\",\n" +
52     "    \"rpc-name\": \"nbrlist-change-notification\",\n" +
53     "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
54     "    \"type\": \"request\"\n" +
55     "}";
56
57
58         @Test
59         public void test() throws Exception {
60                 Properties props = new Properties();
61
62                 CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer();
63                 InputStream propStr = TestCMNotifyDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-cMNotify-1.properties");
64                 props.load(propStr);
65                 consumer.init(props, "src/test/resources/dmaap-consumer-1.properties");
66                 consumer.processMsg(cMNotifyInput);
67         }
68
69         @Test(expected = InvalidMessageException.class)
70         public void testProcessMsgNullMessage() throws Exception {
71                 CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer();
72                 consumer.processMsg(null);
73         }
74
75         @Test
76         public void testProcessMsgMissingBody() throws Exception {
77                 String msg =    "{\n" +
78     " \"bodyTest\": {\n" +
79     "    \"input\": {\n" +
80     "      \"CommonHeader\": {\n" +
81     "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
82     "        \"APIver\": \"1.0\",\n" +
83     "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
84     "        \"SubRequestID\": \"1\",\n" +
85     "        \"RequestTrack\": {},\n" +
86     "        \"Flags\": {}\n      },\n" +
87     "      \"Action\": \"nbrlist-change-notification\",\n" +
88     "      \"Payload\": {\n" +
89      "        \"fap-service-number-of-entries-changed\": 1,\n" +
90      "        \"fap-service\": [{ \"alias\": \n" +
91      "        \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" +
92      "        \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" +
93      "        [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" +
94      "        \"pnf-name\": \"ncserver1\",\n" +
95      "        \"blacklisted\": false }] }] }\n" +
96      "     }\n" +
97     "    },\n" +
98     "    \"version\": \"1.0\",\n" +
99     "    \"rpc-name\": \"nbrlist-change-notification\",\n" +
100     "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
101     "    \"type\": \"request\"\n" +
102     "}";
103                 CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer();
104                 consumer.processMsg(msg);
105         }
106
107         @Test
108         public void testProcessMsgInvalidRPC() throws Exception {
109     String msg =        "{\n" +
110     " \"body\": {\n" +
111     "    \"input\": {\n" +
112     "      \"CommonHeader\": {\n" +
113     "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
114     "        \"APIver\": \"1.0\",\n" +
115     "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
116     "        \"SubRequestID\": \"1\",\n" +
117     "        \"RequestTrack\": {},\n" +
118     "        \"Flags\": {}\n      },\n" +
119     "      \"Action\": \"nbrlist-change-notification\",\n" +
120     "      \"Payload\": {\n" +
121      "        \"fap-service-number-of-entries-changed\": 1,\n" +
122      "        \"fap-service\": [{ \"alias\": \n" +
123      "        \"Chn0001\", \"cid\": \"Chn0001\", \"lte-cell-number-of-entries\": 1,\n" +
124      "        \"lte-ran-neighbor-list-in-use-lte-cell-changed\": \n" +
125      "        [{ \"plmnid\": \"ran-1\", \"cid\": \"Chn0002\", \"phy-cell-id\": 4,\n" +
126      "        \"pnf-name\": \"ncserver1\",\n" +
127      "        \"blacklisted\": false }] }] }\n" +
128      "     }\n" +
129     "    },\n" +
130     "    \"version\": \"1.0\",\n" +
131     "    \"rpc-nameTest\": \"nbrlist-change-notification\",\n" +
132     "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
133     "    \"type\": \"request\"\n" +
134     "}";
135
136                 CMNotifyDmaapConsumer consumer = new CMNotifyDmaapConsumer();
137                 consumer.processMsg(msg);
138         }
139
140 }