d1018a014951f347b90c3d9d39f511463132ce2e
[ccsdk/sli.git] /
1 package org.onap.ccsdk.sli.adaptors.messagerouter.consumer.provider.impl;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5
6 import java.util.Properties;
7
8 import org.junit.Test;
9
10 public class ConsumerFactoryTest {
11
12     @Test
13     public void testFactoryClientCreation() throws Exception {
14         Properties props = new Properties();
15         String userName = "deadpool";
16         String password = "notSECURE";
17         String host = "http://localhost:7001";
18         String group = "myCluster";
19         String id = "node1";
20         Integer connectTimeout = 10000;
21         Integer readTimeout = 20000;
22         props.put("username", userName);
23         props.put("password", password);
24         props.put("host", host);
25         props.put("group", group);
26
27         ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);
28        assertNotNull(factory.createPollingClient());
29        assertNotNull(factory.createPullingClient());
30     }
31     
32     @Test
33     public void testFactoryDefaults() throws Exception {
34         Properties props = new Properties();
35         String userName = "deadpool";
36         String password = "notSECURE";
37         String host = "http://localhost:7001";
38         String group = "myCluster";
39         String id = "node1";
40         Integer connectTimeout = 10000;
41         Integer readTimeout = 20000;
42         props.put("username", userName);
43         props.put("password", password);
44         props.put("host", host);
45         props.put("group", group);
46
47         ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);
48
49         assertNotNull(factory.getAuth());
50         assertNotNull(factory.getConnectTimeout());
51         assertNotNull(factory.getReadTimeout());
52         assertNotNull(factory.getFetchPause());
53         assertNotNull(factory.getLimit());
54         assertNotNull(factory.getTimeoutQueryParamValue());
55     }
56
57     @Test
58     public void testFactoryDefaultsWithProps() {
59         Properties props = new Properties();
60         String userName = "deadpool";
61         String password = "notSECURE";
62         String host = "http://localhost:7001";
63         String auth = "basic";
64         String group = "myCluster";
65         props.put("username", userName);
66         props.put("password", password);
67         props.put("host", host);
68         props.put("group", group);
69
70         ConsumerFactory factory = new ConsumerFactory(props);
71
72         assertNotNull(factory.getAuth());
73         assertNotNull(factory.getConnectTimeout());
74         assertNotNull(factory.getReadTimeout());
75         assertNotNull(factory.getFetchPause());
76         assertNotNull(factory.getLimit());
77         assertNotNull(factory.getTimeoutQueryParamValue());
78     }
79
80     @Test
81     public void testFactoryOverrides() throws Exception {
82         Properties props = new Properties();
83         String userName = "deadpool";
84         String password = "notSECURE";
85         String host = "http://localhost:7001";
86         String group = "myCluster";
87         props.put("username", userName);
88         props.put("password", password);
89         props.put("host", host);
90         props.put("group", group);
91
92         String connectTimeout = "200";
93         String readTimeout = "300";
94         String fetchPause = "1000";
95         String auth = "noauth";
96         String timeoutQueryParamValue = "50";
97         String limit = "2";
98         props.put("connectTimeoutSeconds", connectTimeout);
99         props.put("readTimeoutMinutes", readTimeout);
100         props.put("fetchPause", fetchPause);
101         props.put("auth", auth);
102         props.put("timeout", timeoutQueryParamValue);
103         props.put("limit", limit);
104
105         ConsumerFactory factory = new ConsumerFactory(props);
106
107         assertEquals(auth, factory.getAuth());
108         assertEquals(Integer.valueOf(connectTimeout), factory.getConnectTimeout());
109         assertEquals(Integer.valueOf(readTimeout), factory.getReadTimeout());
110         assertEquals(Integer.valueOf(fetchPause), factory.getFetchPause());
111         assertEquals(Integer.valueOf(limit), factory.getLimit());
112         assertEquals(Integer.valueOf(timeoutQueryParamValue), factory.getTimeoutQueryParamValue());
113     }
114
115     @Test
116     public void testManualOverrides() {
117         Properties props = new Properties();
118         String userName = "deadpool";
119         String password = "notSECURE";
120         String host = "http://localhost:7001";
121         String auth = "basic";
122         String group = "myCluster";
123         props.put("username", userName);
124         props.put("password", password);
125         props.put("host", host);
126         props.put("group", group);
127
128         ConsumerFactory factory = new ConsumerFactory(props);
129
130         assertNotNull(factory.getAuth());
131         assertNotNull(factory.getConnectTimeout());
132         assertNotNull(factory.getReadTimeout());
133         assertNotNull(factory.getFetchPause());
134         assertNotNull(factory.getLimit());
135         assertNotNull(factory.getTimeoutQueryParamValue());
136         String newAuth = "noauth";
137         factory.setAuth(newAuth);
138         assertEquals(newAuth, factory.getAuth());
139
140         Integer connectTimeout = 1;
141         factory.setConnectTimeout(connectTimeout);
142         assertEquals(connectTimeout, factory.getConnectTimeout());
143
144         Integer fetchPause = 5;
145         factory.setFetchPause(fetchPause);
146         assertEquals(fetchPause, factory.getFetchPause());
147
148         factory.setFilter("\"filter\":{\n" + "\"class\":\"And\",\n" + "\"filters\":\n" + "[\n" + "{ \"class\":\"Equals\", \"foo\":\"abc\" },\n" + "{ \"class\":\"Assigned\", \"field\":\"bar\" }\n" + "]\n" + "}");
149         assertNotNull(factory.getFilter());
150
151         Integer limit = 3;
152         factory.setLimit(limit);
153         assertEquals(limit, factory.getLimit());
154
155         Integer readTimeout = 2;
156         factory.setReadTimeout(readTimeout);
157         assertEquals(readTimeout, factory.getReadTimeout());
158
159         Integer timeoutQueryParamValue = 47;
160         factory.setTimeoutQueryParamValue(timeoutQueryParamValue);
161         assertEquals(timeoutQueryParamValue, factory.getTimeoutQueryParamValue());
162     }
163
164 }