2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.appc.adapter.messaging.dmaap.impl;
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;
34 import org.junit.Ignore;
35 import org.junit.Test;
38 public class TestDmaapConsumerImpl {
39 String[] hostList = { "192.168.1.1" };
40 Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
42 String topic = "JunitTopicOne";
43 String group = "junit-client";
44 String id = "junit-consumer-one";
46 String secret = "secret";
50 public void testDmaapConsumerImplNoFilter() {
52 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
54 assertNotNull(consumer);
56 Properties props = consumer.getProperties();
58 assertEquals("192.168.1.1", props.getProperty("host"));
59 assertEquals("key", props.getProperty("username"));
60 assertEquals("secret", props.getProperty("password"));
64 public void testDmaapConsumerImplwithFilter() {
67 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret, filter);
69 assertNotNull(consumer);
74 public void testDmaapConsumerImplNoUserPassword() {
76 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
78 assertNotNull(consumer);
80 Properties props = consumer.getProperties();
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"));
89 public void testUpdateCredentials() {
90 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
92 assertNotNull(consumer);
94 Properties props = consumer.getProperties();
96 assertEquals("192.168.1.1", props.getProperty("host"));
97 assertNull(props.getProperty("username"));
98 assertNull(props.getProperty("password"));
100 consumer.updateCredentials(key, secret);
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"));
108 @Ignore("test is taking 130 sec")
110 public void testFetch() {
111 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
113 assertNotNull(consumer);
115 consumer.fetch(5000,500);
120 public void testFetchIntInt() {
121 fail("Not yet implemented");
125 public void testCloseNoClient() {
126 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
128 assertNotNull(consumer);
135 public void testCloseWithClient() {
136 fail("Not yet implemented");
140 public void testToString() {
141 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
143 assertNotNull(consumer);
145 assertEquals("Consumer junit-client/junit-consumer-one listening to JunitTopicOne on [192.168.1.1]",
146 consumer.toString());
150 public void testUseHttps() {
151 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
153 assertNotNull(consumer);
155 assertEquals(false, consumer.isHttps());
157 consumer.useHttps(true);
159 assertEquals(true, consumer.isHttps());
164 public void testGetClient()
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"));
175 public void testInitMetric()
177 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
178 assertNotNull(consumer);