25fac16452fdbe0d995beea6d6a4d3c27703f40a
[appc.git] /
1 package org.onap.appc.adapter.messaging.dmaap.impl;
2
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertNull;
6 import static org.junit.Assert.fail;
7
8 import java.util.Arrays;
9 import java.util.Collection;
10 import java.util.HashSet;
11 import java.util.Properties;
12
13 import org.junit.Ignore;
14 import org.junit.Test;
15
16 public class TestDmaapConsumerImpl {
17     String[]           hostList = { "192.168.1.1" };
18     Collection<String> hosts    = new HashSet<String>(Arrays.asList(hostList));
19
20     String             topic    = "JunitTopicOne";
21     String             group    = "junit-client";
22     String             id       = "junit-consumer-one";
23     String             key      = "key";
24     String             secret   = "secret";
25     String             filter   = null;
26
27     @Test
28     public void testDmaapConsumerImplNoFilter() {
29
30         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
31
32         assertNotNull(consumer);
33
34         Properties props = consumer.getProperties();
35
36         assertEquals("192.168.1.1", props.getProperty("host"));
37         assertEquals("key", props.getProperty("username"));
38         assertEquals("secret", props.getProperty("password"));
39     }
40
41     @Test
42     public void testDmaapConsumerImplwithFilter() {
43
44         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret, filter);
45
46         assertNotNull(consumer);
47
48     }
49
50     @Test
51     public void testDmaapConsumerImplNoUserPassword() {
52
53         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
54
55         assertNotNull(consumer);
56
57         Properties props = consumer.getProperties();
58
59         assertEquals("192.168.1.1", props.getProperty("host"));
60         assertNull(props.getProperty("username"));
61         assertNull(props.getProperty("password"));
62         assertEquals("HTTPNOAUTH", props.getProperty("TransportType"));
63     }
64
65     @Test
66     public void testUpdateCredentials() {
67         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
68
69         assertNotNull(consumer);
70
71         Properties props = consumer.getProperties();
72
73         assertEquals("192.168.1.1", props.getProperty("host"));
74         assertNull(props.getProperty("username"));
75         assertNull(props.getProperty("password"));
76
77         consumer.updateCredentials(key, secret);
78
79         props = consumer.getProperties();
80         assertEquals("192.168.1.1", props.getProperty("host"));
81         assertEquals("key", props.getProperty("username"));
82         assertEquals("secret", props.getProperty("password"));
83     }
84
85     @Ignore
86     @Test
87     public void testFetch() {
88         fail("Not yet implemented");
89     }
90
91     @Ignore
92     @Test
93     public void testFetchIntInt() {
94         fail("Not yet implemented");
95     }
96
97     @Test
98     public void testCloseNoClient() {
99         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
100
101         assertNotNull(consumer);
102
103         consumer.close();
104     }
105
106     @Ignore
107     @Test
108     public void testCloseWithClient() {
109         fail("Not yet implemented");
110     }
111
112     @Test
113     public void testToString() {
114         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
115
116         assertNotNull(consumer);
117
118         assertEquals("Consumer junit-client/junit-consumer-one listening to JunitTopicOne on [192.168.1.1]",
119                 consumer.toString());
120     }
121
122     @Test
123     public void testUseHttps() {
124         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
125
126         assertNotNull(consumer);
127
128         assertEquals(false, consumer.isHttps());
129
130         consumer.useHttps(true);
131
132         assertEquals(true, consumer.isHttps());
133
134     }
135
136 }