aboutsummaryrefslogtreecommitdiffstats
path: root/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestA1AdapterPolicyDmaapConsumer.java
blob: 8b7044f69af3e4ccb2906eeff113a325c6f97473 (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
/*
 * Copyright (c) 2017. Lorem ipsum dolor sit amet, consectetur adipiscing elit.
 * Morbi non lorem porttitor neque feugiat blandit. Ut vitae ipsum eget quam lacinia accumsan.
 * Etiam sed turpis ac ipsum condimentum fringilla. Maecenas magna.
 * Proin dapibus sapien vel ante. Aliquam erat volutpat. Pellentesque sagittis ligula eget metus.
 * Vestibulum commodo. Ut rhoncus gravida arcu.
 */

package org.onap.ccsdk.sli.northbound.dmaapclient;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Properties;

import org.apache.commons.io.FileUtils;

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

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

public class TestA1AdapterPolicyDmaapConsumer {
    private static final String a1AdapterInput =  "{\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\": \"getHealthCheck\",\n" +
		      "      \"Payload\": {\n" +
		      "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
		      "        \"policy-type-id\": \"20000\",\n" +
		      "        \"description\": \"parameters to control policy \",\n" +
		      "        \"name\": \"admission_control_policy\",\n" +
		      "        \"policy-type\": \"object\"\n" +
		      "      }\n" +
		      "    },\n" +
		      "    \"version\": \"1.0\",\n" +
		      "    \"rpc-name\": \"getHealthCheck\",\n" +
		      "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
		      "    \"type\": \"request\"\n" +
		      "  }\n" +
		      "}";

	@Test
	public void test() throws Exception {
		Properties props = new Properties();

		A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
		InputStream propStr = TestA1AdapterPolicyDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-a1Adapter-policy-1.properties");
		props.load(propStr);
		consumer.init(props, "src/test/resources/dmaap-consumer-1.properties");
		consumer.processMsg(a1AdapterInput);
	}

	@Test(expected = InvalidMessageException.class)
	public void testProcessMsgNullMessage() throws Exception {
		A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
		consumer.processMsg(null);
	}

	@Test
	public void testProcessMsgMissingBody() throws Exception {
		String msg = 	"{\n" +
		      " \"body1\": {\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\": \"getHealthCheck\",\n" +
		      "      \"Payload\": {\n" +
		      "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
		      "        \"policy-type-id\": \"20000\",\n" +
		      "        \"description\": \"parameters to control policy \",\n" +
		      "        \"name\": \"admission_control_policy\",\n" +
		      "        \"policy-type\": \"object\"\n" +
		      "      }\n" +
		      "    },\n" +
		      "    \"version\": \"1.0\",\n" +
		      "    \"rpc-name\": \"getHealthCheck\",\n" +
		      "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
		      "    \"type\": \"request\"\n" +
		      "  }\n" +
		      "}";

		A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
		consumer.processMsg(msg);
	}

	@Test
	public void testProcessMsgInvalidRPC() 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\": \"getHealthCheck\",\n" +
		      "      \"Payload\": {\n" +
		      "        \"near-rt-ric-id\": \"near-RT-ric1\",\n" +
		      "        \"policy-type-id\": \"20000\",\n" +
		      "        \"description\": \"parameters to control policy \",\n" +
		      "        \"name\": \"admission_control_policy\",\n" +
		      "        \"policy-type\": \"object\"\n" +
		      "      }\n" +
		      "    },\n" +
		      "    \"version\": \"1.0\",\n" +
		      "    \"rpc-name1\": \"getHealthCheck\",\n" +
		      "    \"correlation-id\": \"9d2d790e-a5f0-11e8-98d0-529269fb1459-1\",\n" +
		      "    \"type\": \"request\"\n" +
		      "  }\n" +
		      "}";

		A1AdapterPolicyDmaapConsumer consumer = new A1AdapterPolicyDmaapConsumer();
		consumer.processMsg(msg);
	}

}