956d620c633ebe202e64f46468f6da594fa1cb57
[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 import java.util.Set;
13
14 import org.junit.Ignore;
15 import org.junit.Test;
16
17 public class TestDmaapProducerImpl {
18     String[]           hostList = { "192.168.1.1" };
19     Collection<String> hosts    = new HashSet<String>(Arrays.asList(hostList));
20
21     String             topic    = "JunitTopicOne";
22     String             group    = "junit-client";
23     String             id       = "junit-consumer-one";
24     String             key      = "key";
25     String             secret   = "secret";
26     String             filter   = null;
27
28     @Test
29     public void testDmaapProducerImplSingleTopic() {
30         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
31
32         assertNotNull(producer);
33
34         Properties props = producer.getProperties();
35
36         assertNotNull(props);
37
38         assertEquals("key", props.getProperty("username"));
39         assertEquals("secret", props.getProperty("password"));
40     }
41
42     @Test
43     public void testDmaapProducerImplMultipleTopic() {
44         String[] topicList = { "topic1", "topic2" };
45         Set<String> topicNames = new HashSet<String>(Arrays.asList(topicList));
46
47         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topicNames, key, secret);
48
49         assertNotNull(producer);
50
51         Properties props = producer.getProperties();
52
53         assertNotNull(props);
54
55         assertEquals("key", props.getProperty("username"));
56         assertEquals("secret", props.getProperty("password"));
57
58     }
59
60     @Test
61     public void testDmaapProducerImplNoUserPass() {
62         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
63
64         assertNotNull(producer);
65
66         Properties props = producer.getProperties();
67
68         assertNotNull(props);
69
70         assertNull(props.getProperty("username"));
71         assertNull(props.getProperty("password"));
72     }
73
74     @Test
75     public void testUpdateCredentials() {
76         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
77
78         assertNotNull(producer);
79
80         Properties props = producer.getProperties();
81
82         assertNotNull(props);
83
84         assertNull(props.getProperty("username"));
85         assertNull(props.getProperty("password"));
86
87         producer.updateCredentials(key, secret);
88
89         props = producer.getProperties();
90
91         assertNotNull(props);
92
93         assertEquals("key", props.getProperty("username"));
94         assertEquals("secret", props.getProperty("password"));
95
96     }
97
98     @Ignore
99     @Test
100     public void testPost() {
101         fail("Not yet implemented");
102     }
103
104     @Test
105     public void testCloseNoClient() {
106         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
107
108         assertNotNull(producer);
109
110         producer.close();
111     }
112
113     @Ignore
114     @Test
115     public void testCloseWithClient() {
116         fail("Not yet implemented");
117     }
118
119     @Test
120     public void testUseHttps() {
121         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
122
123         assertNotNull(producer);
124
125         assertEquals(false, producer.isHttps());
126
127         producer.useHttps(true);
128
129         assertEquals(true, producer.isHttps());
130
131     }
132
133 }