8b7044f69af3e4ccb2906eeff113a325c6f97473
[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 public class TestA1AdapterPolicyDmaapConsumer {
29     private static final String a1AdapterInput =  "{\n" +
30                       " \"body\": {\n" +
31                       "    \"input\": {\n" +
32                       "      \"CommonHeader\": {\n" +
33                       "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
34                       "        \"APIver\": \"1.0\",\n" +
35                       "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
36                       "        \"SubRequestID\": \"1\",\n" +
37                       "        \"RequestTrack\": {},\n" +
38                       "        \"Flags\": {}\n      },\n" +
39                       "      \"Action\": \"getHealthCheck\",\n" +
40                       "      \"Payload\": {\n" +
41                       "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
42                       "        \"policy-type-id\": \"20000\",\n" +
43                       "        \"description\": \"parameters to control policy \",\n" +
44                       "        \"name\": \"admission_control_policy\",\n" +
45                       "        \"policy-type\": \"object\"\n" +
46                       "      }\n" +
47                       "    },\n" +
48                       "    \"version\": \"1.0\",\n" +
49                       "    \"rpc-name\": \"getHealthCheck\",\n" +
50                       "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
51                       "    \"type\": \"request\"\n" +
52                       "  }\n" +
53                       "}";
54
55         @Test
56         public void test() throws Exception {
57                 Properties props = new Properties();
58
59                 A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
60                 InputStream propStr = TestA1AdapterPolicyDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-a1Adapter-policy-1.properties");
61                 props.load(propStr);
62                 consumer.init(props, "src/test/resources/dmaap-consumer-1.properties");
63                 consumer.processMsg(a1AdapterInput);
64         }
65
66         @Test(expected = InvalidMessageException.class)
67         public void testProcessMsgNullMessage() throws Exception {
68                 A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
69                 consumer.processMsg(null);
70         }
71
72         @Test
73         public void testProcessMsgMissingBody() throws Exception {
74                 String msg =    "{\n" +
75                       " \"body1\": {\n" +
76                       "    \"input\": {\n" +
77                       "      \"CommonHeader\": {\n" +
78                       "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
79                       "        \"APIver\": \"1.0\",\n" +
80                       "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
81                       "        \"SubRequestID\": \"1\",\n" +
82                       "        \"RequestTrack\": {},\n" +
83                       "        \"Flags\": {}\n      },\n" +
84                       "      \"Action\": \"getHealthCheck\",\n" +
85                       "      \"Payload\": {\n" +
86                       "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
87                       "        \"policy-type-id\": \"20000\",\n" +
88                       "        \"description\": \"parameters to control policy \",\n" +
89                       "        \"name\": \"admission_control_policy\",\n" +
90                       "        \"policy-type\": \"object\"\n" +
91                       "      }\n" +
92                       "    },\n" +
93                       "    \"version\": \"1.0\",\n" +
94                       "    \"rpc-name\": \"getHealthCheck\",\n" +
95                       "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
96                       "    \"type\": \"request\"\n" +
97                       "  }\n" +
98                       "}";
99
100                 A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
101                 consumer.processMsg(msg);
102         }
103
104         @Test
105         public void testProcessMsgInvalidRPC() throws Exception {
106     String msg =        "{\n" +
107                       " \"body\": {\n" +
108                       "    \"input\": {\n" +
109                       "      \"CommonHeader\": {\n" +
110                       "        \"TimeStamp\": \"2018-11-30T09:13:37.368Z\",\n" +
111                       "        \"APIver\": \"1.0\",\n" +
112                       "        \"RequestID\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459\",\n" +
113                       "        \"SubRequestID\": \"1\",\n" +
114                       "        \"RequestTrack\": {},\n" +
115                       "        \"Flags\": {}\n      },\n" +
116                       "      \"Action\": \"getHealthCheck\",\n" +
117                       "      \"Payload\": {\n" +
118                       "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
119                       "        \"policy-type-id\": \"20000\",\n" +
120                       "        \"description\": \"parameters to control policy \",\n" +
121                       "        \"name\": \"admission_control_policy\",\n" +
122                       "        \"policy-type\": \"object\"\n" +
123                       "      }\n" +
124                       "    },\n" +
125                       "    \"version\": \"1.0\",\n" +
126                       "    \"rpc-name1\": \"getHealthCheck\",\n" +
127                       "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
128                       "    \"type\": \"request\"\n" +
129                       "  }\n" +
130                       "}";
131
132                 A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
133                 consumer.processMsg(msg);
134         }
135
136 }