aboutsummaryrefslogtreecommitdiffstats
path: root/message-router/consumer/provider/src/test/java/org/onap/ccsdk/sli/adaptors/messagerouter/consumer/provider/impl/ConsumerFactoryTest.java
blob: d1018a014951f347b90c3d9d39f511463132ce2e (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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package org.onap.ccsdk.sli.adaptors.messagerouter.consumer.provider.impl;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

import java.util.Properties;

import org.junit.Test;

public class ConsumerFactoryTest {

    @Test
    public void testFactoryClientCreation() throws Exception {
        Properties props = new Properties();
        String userName = "deadpool";
        String password = "notSECURE";
        String host = "http://localhost:7001";
        String group = "myCluster";
        String id = "node1";
        Integer connectTimeout = 10000;
        Integer readTimeout = 20000;
        props.put("username", userName);
        props.put("password", password);
        props.put("host", host);
        props.put("group", group);

        ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);
       assertNotNull(factory.createPollingClient());
       assertNotNull(factory.createPullingClient());
    }
    
    @Test
    public void testFactoryDefaults() throws Exception {
        Properties props = new Properties();
        String userName = "deadpool";
        String password = "notSECURE";
        String host = "http://localhost:7001";
        String group = "myCluster";
        String id = "node1";
        Integer connectTimeout = 10000;
        Integer readTimeout = 20000;
        props.put("username", userName);
        props.put("password", password);
        props.put("host", host);
        props.put("group", group);

        ConsumerFactory factory = new ConsumerFactory(userName, password, host, group, id, connectTimeout, readTimeout);

        assertNotNull(factory.getAuth());
        assertNotNull(factory.getConnectTimeout());
        assertNotNull(factory.getReadTimeout());
        assertNotNull(factory.getFetchPause());
        assertNotNull(factory.getLimit());
        assertNotNull(factory.getTimeoutQueryParamValue());
    }

    @Test
    public void testFactoryDefaultsWithProps() {
        Properties props = new Properties();
        String userName = "deadpool";
        String password = "notSECURE";
        String host = "http://localhost:7001";
        String auth = "basic";
        String group = "myCluster";
        props.put("username", userName);
        props.put("password", password);
        props.put("host", host);
        props.put("group", group);

        ConsumerFactory factory = new ConsumerFactory(props);

        assertNotNull(factory.getAuth());
        assertNotNull(factory.getConnectTimeout());
        assertNotNull(factory.getReadTimeout());
        assertNotNull(factory.getFetchPause());
        assertNotNull(factory.getLimit());
        assertNotNull(factory.getTimeoutQueryParamValue());
    }

    @Test
    public void testFactoryOverrides() throws Exception {
        Properties props = new Properties();
        String userName = "deadpool";
        String password = "notSECURE";
        String host = "http://localhost:7001";
        String group = "myCluster";
        props.put("username", userName);
        props.put("password", password);
        props.put("host", host);
        props.put("group", group);

        String connectTimeout = "200";
        String readTimeout = "300";
        String fetchPause = "1000";
        String auth = "noauth";
        String timeoutQueryParamValue = "50";
        String limit = "2";
        props.put("connectTimeoutSeconds", connectTimeout);
        props.put("readTimeoutMinutes", readTimeout);
        props.put("fetchPause", fetchPause);
        props.put("auth", auth);
        props.put("timeout", timeoutQueryParamValue);
        props.put("limit", limit);

        ConsumerFactory factory = new ConsumerFactory(props);

        assertEquals(auth, factory.getAuth());
        assertEquals(Integer.valueOf(connectTimeout), factory.getConnectTimeout());
        assertEquals(Integer.valueOf(readTimeout), factory.getReadTimeout());
        assertEquals(Integer.valueOf(fetchPause), factory.getFetchPause());
        assertEquals(Integer.valueOf(limit), factory.getLimit());
        assertEquals(Integer.valueOf(timeoutQueryParamValue), factory.getTimeoutQueryParamValue());
    }

    @Test
    public void testManualOverrides() {
        Properties props = new Properties();
        String userName = "deadpool";
        String password = "notSECURE";
        String host = "http://localhost:7001";
        String auth = "basic";
        String group = "myCluster";
        props.put("username", userName);
        props.put("password", password);
        props.put("host", host);
        props.put("group", group);

        ConsumerFactory factory = new ConsumerFactory(props);

        assertNotNull(factory.getAuth());
        assertNotNull(factory.getConnectTimeout());
        assertNotNull(factory.getReadTimeout());
        assertNotNull(factory.getFetchPause());
        assertNotNull(factory.getLimit());
        assertNotNull(factory.getTimeoutQueryParamValue());
        String newAuth = "noauth";
        factory.setAuth(newAuth);
        assertEquals(newAuth, factory.getAuth());

        Integer connectTimeout = 1;
        factory.setConnectTimeout(connectTimeout);
        assertEquals(connectTimeout, factory.getConnectTimeout());

        Integer fetchPause = 5;
        factory.setFetchPause(fetchPause);
        assertEquals(fetchPause, factory.getFetchPause());

        factory.setFilter("\"filter\":{\n" + "\"class\":\"And\",\n" + "\"filters\":\n" + "[\n" + "{ \"class\":\"Equals\", \"foo\":\"abc\" },\n" + "{ \"class\":\"Assigned\", \"field\":\"bar\" }\n" + "]\n" + "}");
        assertNotNull(factory.getFilter());

        Integer limit = 3;
        factory.setLimit(limit);
        assertEquals(limit, factory.getLimit());

        Integer readTimeout = 2;
        factory.setReadTimeout(readTimeout);
        assertEquals(readTimeout, factory.getReadTimeout());

        Integer timeoutQueryParamValue = 47;
        factory.setTimeoutQueryParamValue(timeoutQueryParamValue);
        assertEquals(timeoutQueryParamValue, factory.getTimeoutQueryParamValue());
    }

}