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;
30 import java.util.Arrays;
31 import java.util.Collection;
32 import java.util.HashSet;
33 import java.util.Properties;
36 import org.junit.Before;
37 import org.junit.Ignore;
38 import org.junit.Test;
40 public class TestDmaapProducerImpl {
41 String[] hostList = { "192.168.1.1" };
42 Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
44 String topic = "JunitTopicOne";
45 String group = "junit-client";
46 String id = "junit-consumer-one";
48 String secret = "secret";
51 private DmaapProducerImpl producer;
55 producer = new DmaapProducerImpl(hosts, topic, null, null);
59 public void testDmaapProducerImplSingleTopic() {
60 producer = new DmaapProducerImpl(hosts, topic, key, secret);
62 assertNotNull(producer);
64 Properties props = producer.getProperties();
68 assertEquals("key", props.getProperty("username"));
69 assertEquals("secret", props.getProperty("password"));
73 public void testDmaapProducerImplMultipleTopic() {
74 String[] topicList = { "topic1", "topic2" };
75 Set<String> topicNames = new HashSet<String>(Arrays.asList(topicList));
77 producer = new DmaapProducerImpl(hosts, topicNames, key, secret);
79 assertNotNull(producer);
81 Properties props = producer.getProperties();
85 assertEquals("key", props.getProperty("username"));
86 assertEquals("secret", props.getProperty("password"));
91 public void testDmaapProducerImplNoUserPass() {
92 assertNotNull(producer);
94 Properties props = producer.getProperties();
98 assertNull(props.getProperty("username"));
99 assertNull(props.getProperty("password"));
103 public void testUpdateCredentials() {
104 assertNotNull(producer);
106 Properties props = producer.getProperties();
108 assertNotNull(props);
110 assertNull(props.getProperty("username"));
111 assertNull(props.getProperty("password"));
113 producer.updateCredentials(key, secret);
115 props = producer.getProperties();
117 assertNotNull(props);
119 assertEquals("key", props.getProperty("username"));
120 assertEquals("secret", props.getProperty("password"));
125 public void testPost() {
126 boolean successful = producer.post("partition", "data");
127 assertEquals(true, successful);
131 public void testCloseNoClient() {
132 producer = new DmaapProducerImpl(hosts, topic, key, secret);
134 assertNotNull(producer);
141 public void testCloseWithClient() {
142 producer.post("partition", "data");
143 assertNotNull(producer);
148 public void testUseHttps() {
149 producer = new DmaapProducerImpl(hosts, topic, key, secret);
151 assertNotNull(producer);
153 assertEquals(false, producer.isHttps());
155 producer.useHttps(true);
157 assertEquals(true, producer.isHttps());