443cb1596404727a1c9152609b675e6a88c31b95
[appc.git] /
1 /* 
2  * ============LICENSE_START======================================================= 
3  * ONAP : APPC 
4  * ================================================================================ 
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved. 
6  * ============================================================================= 
7  * Licensed under the Apache License, Version 2.0 (the "License"); 
8  * you may not use this file except in compliance with the License. 
9  * You may obtain a copy of the License at 
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0 
12  * 
13  * Unless required by applicable law or agreed to in writing, software 
14  * distributed under the License is distributed on an "AS IS" BASIS, 
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
16  * See the License for the specific language governing permissions and 
17  * limitations under the License. 
18  * ============LICENSE_END========================================================= 
19  */
20
21 package org.onap.appc.adapter.messaging.dmaap.impl;
22
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
27
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.HashSet;
31 import java.util.Properties;
32 import java.util.Set;
33
34 import org.junit.Ignore;
35 import org.junit.Test;
36
37 public class TestDmaapProducerImpl {
38     String[]           hostList = { "192.168.1.1" };
39     Collection<String> hosts    = new HashSet<String>(Arrays.asList(hostList));
40
41     String             topic    = "JunitTopicOne";
42     String             group    = "junit-client";
43     String             id       = "junit-consumer-one";
44     String             key      = "key";
45     String             secret   = "secret";
46     String             filter   = null;
47
48     @Test
49     public void testDmaapProducerImplSingleTopic() {
50         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
51
52         assertNotNull(producer);
53
54         Properties props = producer.getProperties();
55
56         assertNotNull(props);
57
58         assertEquals("key", props.getProperty("username"));
59         assertEquals("secret", props.getProperty("password"));
60     }
61
62     @Test
63     public void testDmaapProducerImplMultipleTopic() {
64         String[] topicList = { "topic1", "topic2" };
65         Set<String> topicNames = new HashSet<String>(Arrays.asList(topicList));
66
67         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topicNames, key, secret);
68
69         assertNotNull(producer);
70
71         Properties props = producer.getProperties();
72
73         assertNotNull(props);
74
75         assertEquals("key", props.getProperty("username"));
76         assertEquals("secret", props.getProperty("password"));
77
78     }
79
80     @Test
81     public void testDmaapProducerImplNoUserPass() {
82         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
83
84         assertNotNull(producer);
85
86         Properties props = producer.getProperties();
87
88         assertNotNull(props);
89
90         assertNull(props.getProperty("username"));
91         assertNull(props.getProperty("password"));
92     }
93
94     @Test
95     public void testUpdateCredentials() {
96         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
97
98         assertNotNull(producer);
99
100         Properties props = producer.getProperties();
101
102         assertNotNull(props);
103
104         assertNull(props.getProperty("username"));
105         assertNull(props.getProperty("password"));
106
107         producer.updateCredentials(key, secret);
108
109         props = producer.getProperties();
110
111         assertNotNull(props);
112
113         assertEquals("key", props.getProperty("username"));
114         assertEquals("secret", props.getProperty("password"));
115
116     }
117
118     @Ignore
119     @Test
120     public void testPost() {
121         fail("Not yet implemented");
122     }
123
124     @Test
125     public void testCloseNoClient() {
126         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
127
128         assertNotNull(producer);
129
130         producer.close();
131     }
132
133     @Ignore
134     @Test
135     public void testCloseWithClient() {
136         fail("Not yet implemented");
137     }
138
139     @Test
140     public void testUseHttps() {
141         DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
142
143         assertNotNull(producer);
144
145         assertEquals(false, producer.isHttps());
146
147         producer.useHttps(true);
148
149         assertEquals(true, producer.isHttps());
150
151     }
152
153 }