2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.appc.adapter.messaging.dmaap.impl;
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;
28 import java.util.Arrays;
29 import java.util.Collection;
30 import java.util.HashSet;
31 import java.util.Properties;
33 import org.junit.Ignore;
34 import org.junit.Test;
36 public class TestDmaapConsumerImpl {
37 String[] hostList = { "192.168.1.1" };
38 Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
40 String topic = "JunitTopicOne";
41 String group = "junit-client";
42 String id = "junit-consumer-one";
44 String secret = "secret";
48 public void testDmaapConsumerImplNoFilter() {
50 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
52 assertNotNull(consumer);
54 Properties props = consumer.getProperties();
56 assertEquals("192.168.1.1", props.getProperty("host"));
57 assertEquals("key", props.getProperty("username"));
58 assertEquals("secret", props.getProperty("password"));
62 public void testDmaapConsumerImplwithFilter() {
64 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret, filter);
66 assertNotNull(consumer);
71 public void testDmaapConsumerImplNoUserPassword() {
73 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
75 assertNotNull(consumer);
77 Properties props = consumer.getProperties();
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"));
86 public void testUpdateCredentials() {
87 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
89 assertNotNull(consumer);
91 Properties props = consumer.getProperties();
93 assertEquals("192.168.1.1", props.getProperty("host"));
94 assertNull(props.getProperty("username"));
95 assertNull(props.getProperty("password"));
97 consumer.updateCredentials(key, secret);
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"));
107 public void testFetch() {
108 fail("Not yet implemented");
113 public void testFetchIntInt() {
114 fail("Not yet implemented");
118 public void testCloseNoClient() {
119 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
121 assertNotNull(consumer);
128 public void testCloseWithClient() {
129 fail("Not yet implemented");
133 public void testToString() {
134 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, null, null);
136 assertNotNull(consumer);
138 assertEquals("Consumer junit-client/junit-consumer-one listening to JunitTopicOne on [192.168.1.1]",
139 consumer.toString());
143 public void testUseHttps() {
144 DmaapConsumerImpl consumer = new DmaapConsumerImpl(hosts, topic, group, id, key, secret);
146 assertNotNull(consumer);
148 assertEquals(false, consumer.isHttps());
150 consumer.useHttps(true);
152 assertEquals(true, consumer.isHttps());