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