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;
34 import org.junit.Ignore;
35 import org.junit.Test;
37 public class TestDmaapProducerImpl {
38 String[] hostList = { "192.168.1.1" };
39 Collection<String> hosts = new HashSet<String>(Arrays.asList(hostList));
41 String topic = "JunitTopicOne";
42 String group = "junit-client";
43 String id = "junit-consumer-one";
45 String secret = "secret";
49 public void testDmaapProducerImplSingleTopic() {
50 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
52 assertNotNull(producer);
54 Properties props = producer.getProperties();
58 assertEquals("key", props.getProperty("username"));
59 assertEquals("secret", props.getProperty("password"));
63 public void testDmaapProducerImplMultipleTopic() {
64 String[] topicList = { "topic1", "topic2" };
65 Set<String> topicNames = new HashSet<String>(Arrays.asList(topicList));
67 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topicNames, key, secret);
69 assertNotNull(producer);
71 Properties props = producer.getProperties();
75 assertEquals("key", props.getProperty("username"));
76 assertEquals("secret", props.getProperty("password"));
81 public void testDmaapProducerImplNoUserPass() {
82 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
84 assertNotNull(producer);
86 Properties props = producer.getProperties();
90 assertNull(props.getProperty("username"));
91 assertNull(props.getProperty("password"));
95 public void testUpdateCredentials() {
96 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, null, null);
98 assertNotNull(producer);
100 Properties props = producer.getProperties();
102 assertNotNull(props);
104 assertNull(props.getProperty("username"));
105 assertNull(props.getProperty("password"));
107 producer.updateCredentials(key, secret);
109 props = producer.getProperties();
111 assertNotNull(props);
113 assertEquals("key", props.getProperty("username"));
114 assertEquals("secret", props.getProperty("password"));
120 public void testPost() {
121 fail("Not yet implemented");
125 public void testCloseNoClient() {
126 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
128 assertNotNull(producer);
135 public void testCloseWithClient() {
136 fail("Not yet implemented");
140 public void testUseHttps() {
141 DmaapProducerImpl producer = new DmaapProducerImpl(hosts, topic, key, secret);
143 assertNotNull(producer);
145 assertEquals(false, producer.isHttps());
147 producer.useHttps(true);
149 assertEquals(true, producer.isHttps());