4073b554259b38d7169c858eaf8a2b70deb9550c
[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 TestSdncLcmDmaapConsumer {
29     private static final String lcmInput = 
30                                 "{\r\n" +
31                                 "    \"version\": \"lcm-dmaap.version\",\r\n" +
32                                 "    \"cambria.partition\": \"SDNC\",\r\n" +
33                                 "    \"correlation-id\": \"lcm-dmaap.correlation-id\",\r\n" +
34                                 "    \"rpc-name\": \"upgrade-software\",\r\n" +
35                                 "    \"type\": \"lcm-dmaap.type\",\r\n" +
36                                 "    \"body\": {\r\n" +
37                                 "        \"input\": {\r\n" +
38                                 "            \"common-header\": {\r\n" +
39                                 "                \"api-ver\": \"lcm-dmaap.api-ver\",\r\n" +
40                                 "                \"flags\": {\r\n" +
41                                 "                    \"ttl\": \"lcm-dmaap.flags.mode\",\r\n" +
42                                 "                    \"force\": \"lcm-dmaap.flags.force\",\r\n" +
43                                 "                    \"mode\": \"lcm-dmaap.flags.mode\"\r\n" +
44                                 "                },\r\n" +
45                                 "                \"originator-id\": \"lcm-dmaap.originator-id\",\r\n" +
46                                 "                \"request-id\": \"lcm-dmaap.request-id\",\r\n" +
47                                 "                \"sub-request-id\": \"lcm-dmaap.sub-request-id\",\r\n" +
48                                 "                \"timestamp\": \"lcm-dmaap.timestamp\"\r\n" +
49                                 "            },\r\n" +
50                                 "            \"payload\": \"lcm-dmaap.payload\"\r\n" +
51                                 "        }\r\n" +
52                                 "    }\r\n" +
53                                 "}";
54     
55
56         @Test
57         public void test() throws Exception {
58                 Properties props = new Properties();
59
60                 SdncLcmDmaapConsumer consumer = new SdncLcmDmaapConsumer();
61                 InputStream propStr = TestSdncLcmDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-1.properties");
62                 props.load(propStr);
63                 consumer.init(props, "src/test/resources/dmaap-consumer-1.properties");
64                 consumer.processMsg(lcmInput);
65         }
66
67         @Test(expected = InvalidMessageException.class)
68         public void testProcessMsgNullMessage() throws Exception {
69                 SdncLcmDmaapConsumer consumer = new SdncLcmDmaapConsumer();
70                 consumer.processMsg(null);
71         }
72         
73         @Test
74         public void testProcessMsgMissingBody() throws Exception {
75                 String msg =    "{\r\n" +
76                                 "    \"version\": \"lcm-dmaap.version\",\r\n" +
77                                 "    \"cambria.partition\": \"SDNC\",\r\n" +
78                                 "    \"correlation-id\": \"lcm-dmaap.correlation-id\",\r\n" +
79                                 "    \"rpc-name\": \"upgrade-software\",\r\n" +
80                                 "    \"type\": \"lcm-dmaap.type\",\r\n" +
81                                 "    \"body1\": {\r\n" +
82                                 "        \"input\": {\r\n" +
83                                 "            \"common-header\": {\r\n" +
84                                 "                \"api-ver\": \"lcm-dmaap.api-ver\",\r\n" +
85                                 "                \"flags\": {\r\n" +
86                                 "                    \"ttl\": \"lcm-dmaap.flags.mode\",\r\n" +
87                                 "                    \"force\": \"lcm-dmaap.flags.force\",\r\n" +
88                                 "                    \"mode\": \"lcm-dmaap.flags.mode\"\r\n" +
89                                 "                },\r\n" +
90                                 "                \"originator-id\": \"lcm-dmaap.originator-id\",\r\n" +
91                                 "                \"request-id\": \"lcm-dmaap.request-id\",\r\n" +
92                                 "                \"sub-request-id\": \"lcm-dmaap.sub-request-id\",\r\n" +
93                                 "                \"timestamp\": \"lcm-dmaap.timestamp\"\r\n" +
94                                 "            },\r\n" +
95                                 "            \"payload\": \"lcm-dmaap.payload\"\r\n" +
96                                 "        }\r\n" +
97                                 "    }\r\n" +
98                                 "}";
99                 
100                 SdncLcmDmaapConsumer consumer = new SdncLcmDmaapConsumer();
101                 consumer.processMsg(msg);
102         }
103
104         @Test
105         public void testProcessMsgInvalidRPC() throws Exception {
106                 String msg =    "{\r\n" +
107                                 "    \"version\": \"lcm-dmaap.version\",\r\n" +
108                                 "    \"cambria.partition\": \"SDNC\",\r\n" +
109                                 "    \"correlation-id\": \"lcm-dmaap.correlation-id\",\r\n" +
110                                 "    \"rpc-name1\": \"upgrade-software\",\r\n" +
111                                 "    \"type\": \"lcm-dmaap.type\",\r\n" +
112                                 "    \"body\": {\r\n" +
113                                 "        \"input\": {\r\n" +
114                                 "            \"common-header\": {\r\n" +
115                                 "                \"api-ver\": \"lcm-dmaap.api-ver\",\r\n" +
116                                 "                \"flags\": {\r\n" +
117                                 "                    \"ttl\": \"lcm-dmaap.flags.mode\",\r\n" +
118                                 "                    \"force\": \"lcm-dmaap.flags.force\",\r\n" +
119                                 "                    \"mode\": \"lcm-dmaap.flags.mode\"\r\n" +
120                                 "                },\r\n" +
121                                 "                \"originator-id\": \"lcm-dmaap.originator-id\",\r\n" +
122                                 "                \"request-id\": \"lcm-dmaap.request-id\",\r\n" +
123                                 "                \"sub-request-id\": \"lcm-dmaap.sub-request-id\",\r\n" +
124                                 "                \"timestamp\": \"lcm-dmaap.timestamp\"\r\n" +
125                                 "            },\r\n" +
126                                 "            \"payload\": \"lcm-dmaap.payload\"\r\n" +
127                                 "        }\r\n" +
128                                 "    }\r\n" +
129                                 "}";
130                 
131                 SdncLcmDmaapConsumer consumer = new SdncLcmDmaapConsumer();
132                 consumer.processMsg(msg);
133         }
134
135         @Test
136         public void testProcessMsgInvalidPartition() throws Exception {
137                 String msg =    "{\r\n" +
138                                 "    \"version\": \"lcm-dmaap.version\",\r\n" +
139                                 "    \"cambria.partition\": \"BAD\",\r\n" +
140                                 "    \"correlation-id\": \"lcm-dmaap.correlation-id\",\r\n" +
141                                 "    \"rpc-name\": \"upgrade-software\",\r\n" +
142                                 "    \"type\": \"lcm-dmaap.type\",\r\n" +
143                                 "    \"body\": {\r\n" +
144                                 "        \"input\": {\r\n" +
145                                 "            \"common-header\": {\r\n" +
146                                 "                \"api-ver\": \"lcm-dmaap.api-ver\",\r\n" +
147                                 "                \"flags\": {\r\n" +
148                                 "                    \"ttl\": \"lcm-dmaap.flags.mode\",\r\n" +
149                                 "                    \"force\": \"lcm-dmaap.flags.force\",\r\n" +
150                                 "                    \"mode\": \"lcm-dmaap.flags.mode\"\r\n" +
151                                 "                },\r\n" +
152                                 "                \"originator-id\": \"lcm-dmaap.originator-id\",\r\n" +
153                                 "                \"request-id\": \"lcm-dmaap.request-id\",\r\n" +
154                                 "                \"sub-request-id\": \"lcm-dmaap.sub-request-id\",\r\n" +
155                                 "                \"timestamp\": \"lcm-dmaap.timestamp\"\r\n" +
156                                 "            },\r\n" +
157                                 "            \"payload\": \"lcm-dmaap.payload\"\r\n" +
158                                 "        }\r\n" +
159                                 "    }\r\n" +
160                                 "}";
161
162
163                 SdncLcmDmaapConsumer consumer = new SdncLcmDmaapConsumer();
164                 consumer.processMsg(msg);
165         }
166 }