e71cb7580836adb07bc3e3069fb30f1d480e225e
[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
33 import org.junit.Ignore;
34 import org.junit.Test;
35
36 public class TestDmaapConsumerImpl {
37     String[]           hostList = { "192.168.1.1" };
38     Collection<String> hosts    = new HashSet<String>(Arrays.asList(hostList));
39
40     String             topic    = "JunitTopicOne";
41     String             group    = "junit-client";
42     String             id       = "junit-consumer-one";
43     String             key      = "key";
44     String             secret   = "secret";
45     String             filter   = null;
46
47     @Test
48     public void testDmaapConsumerImplNoFilter() {
49
50         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
51
52         assertNotNull(consumer);
53
54         Properties props = consumer.getProperties();
55
56         assertEquals("192.168.1.1", props.getProperty("host"));
57         assertEquals("key", props.getProperty("username"));
58         assertEquals("secret", props.getProperty("password"));
59     }
60
61     @Test
62     public void testDmaapConsumerImplwithFilter() {
63
64         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret, filter);
65
66         assertNotNull(consumer);
67
68     }
69
70     @Test
71     public void testDmaapConsumerImplNoUserPassword() {
72
73         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
74
75         assertNotNull(consumer);
76
77         Properties props = consumer.getProperties();
78
79         assertEquals("192.168.1.1", props.getProperty("host"));
80         assertNull(props.getProperty("username"));
81         assertNull(props.getProperty("password"));
82         assertEquals("HTTPNOAUTH", props.getProperty("TransportType"));
83     }
84
85     @Test
86     public void testUpdateCredentials() {
87         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
88
89         assertNotNull(consumer);
90
91         Properties props = consumer.getProperties();
92
93         assertEquals("192.168.1.1", props.getProperty("host"));
94         assertNull(props.getProperty("username"));
95         assertNull(props.getProperty("password"));
96
97         consumer.updateCredentials(key, secret);
98
99         props = consumer.getProperties();
100         assertEquals("192.168.1.1", props.getProperty("host"));
101         assertEquals("key", props.getProperty("username"));
102         assertEquals("secret", props.getProperty("password"));
103     }
104
105     @Ignore
106     @Test
107     public void testFetch() {
108         fail("Not yet implemented");
109     }
110
111     @Ignore
112     @Test
113     public void testFetchIntInt() {
114         fail("Not yet implemented");
115     }
116
117     @Test
118     public void testCloseNoClient() {
119         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
120
121         assertNotNull(consumer);
122
123         consumer.close();
124     }
125
126     @Ignore
127     @Test
128     public void testCloseWithClient() {
129         fail("Not yet implemented");
130     }
131
132     @Test
133     public void testToString() {
134         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
135
136         assertNotNull(consumer);
137
138         assertEquals("Consumer junit-client/junit-consumer-one listening to JunitTopicOne on [192.168.1.1]",
139                 consumer.toString());
140     }
141
142     @Test
143     public void testUseHttps() {
144         DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
145
146         assertNotNull(consumer);
147
148         assertEquals(false, consumer.isHttps());
149
150         consumer.useHttps(true);
151
152         assertEquals(true, consumer.isHttps());
153
154     }
155
156 }