blob: bf7b4e2360f0b5986f37b8c6c55756ce24728f5a (
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
|
/*
* 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 org.junit.Test;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.Properties;
public class TestSdncJsonDmaapConsumer {
private static final String DMAAP_LISTENER_PROPERTIES = "dmaap-listener.properties";
private static final String DMAAP_LISTENER_PROPERTIES_DIR = "src/test/resources";
@Test(expected = InvalidMessageException.class)
public void testProcessMsg_shouldThrowException() throws Exception {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
consumer.processMsg(null);
}
@Test
public void testProcessMsgFieldMap() throws Exception {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
File directory = new File("lib");
if (! directory.exists()){
directory.mkdir();
}
File file = new File("lib" + "/" + "input.map");
try{
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("SDNC.endpoint=>http://localhost:8282/restconf/operations");
bw.close();
}
catch (Exception e){
e.printStackTrace();
}
String msg = "{\n" +
" \"input\" : { \n" +
" }\n" +
"}";
InputStream propStr = TestSdncJsonDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-pserver.properties");
Properties props = new Properties();
props.load(propStr);
consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties");
consumer.processMsg(msg);
}
@Test(expected = InvalidMessageException.class)
public void testProcessMsgFieldMapNoSdncEndPoint() throws Exception {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
File directory = new File("lib");
if (! directory.exists()){
directory.mkdir();
}
File file = new File("lib" + "/" + "input.map");
try{
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write("SDNC");
bw.close();
}
catch (Exception e){
e.printStackTrace();
}
String msg = "{\n" +
" \"input\" : { \n" +
" }\n" +
"}";
InputStream propStr = TestSdncJsonDmaapConsumer.class.getResourceAsStream("/dmaap-consumer-pserver.properties");
Properties props = new Properties();
props.load(propStr);
consumer.init(props, "src/test/resources/dmaap-consumer-pserver.properties");
consumer.processMsg(msg);
}
@Test(expected = InvalidMessageException.class)
public void testProcessMsgFieldMapNoFieldMap() throws Exception {
SdncFlatJsonDmaapConsumer consumer = new SdncFlatJsonDmaapConsumer();
String msg = "{\n" +
" \"input\" : { \n" +
" }\n" +
"}";
consumer.processMsg(msg);
}
}
|