2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.dmaap.mr.cambria.backends.kafka;
23 import static org.junit.Assert.*;
25 import java.util.concurrent.ConcurrentHashMap;
27 import org.apache.curator.framework.CuratorFramework;
28 import org.junit.After;
29 import org.junit.Before;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.mockito.Mock;
33 import org.mockito.MockitoAnnotations;
34 import org.powermock.api.mockito.PowerMockito;
35 import org.powermock.modules.junit4.PowerMockRunner;
36 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
40 import org.onap.dmaap.dmf.mr.backends.MetricsSet;
41 import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer;
42 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache;
43 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache.KafkaConsumerCacheException;
44 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
45 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
47 @RunWith(PowerMockRunner.class)
48 @PrepareForTest({ AJSCPropertiesMap.class })
49 public class KafkaConsumerCacheTest {
50 private KafkaConsumerCache kafkaConsumerCache =null;
52 private ConcurrentHashMap<String, Kafka011Consumer> fConsumers;
54 private MetricsSet fMetrics;
57 public void setUp() throws Exception {
58 MockitoAnnotations.initMocks(this);
63 public void tearDown() throws Exception {
68 public void testSweep() {
69 kafkaConsumerCache = new KafkaConsumerCache();
70 PowerMockito.mockStatic(AJSCPropertiesMap.class);
71 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "kSetting_TouchEveryMs")).thenReturn("100");
72 kafkaConsumerCache.sweep();
79 public void testStartCache() {
82 * KafkaConsumerCache kafka = null;
84 * try { kafka = new KafkaConsumerCache("123", null);
86 * } catch (NoClassDefFoundError e) { try { kafka.startCache("DMAAP",
87 * null); } catch (NullPointerException e1) { // TODO Auto-generated
88 * catch block assertTrue(true); } catch (KafkaConsumerCacheException
89 * e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
93 new CuratorFrameworkImpl();
95 KafkaConsumerCache kafka=null;
97 kafka = new KafkaConsumerCache();
99 kafka.startCache("DMAAP", null);
100 } catch (NoClassDefFoundError e) {
102 } catch (KafkaConsumerCacheException e) {
103 // TODO Auto-generated catch block
110 public void testGetCuratorFramework() {
112 CuratorFramework curator = new CuratorFrameworkImpl();
113 new MetricsSetImpl();
116 } catch (NoClassDefFoundError e) {
118 KafkaConsumerCache.getCuratorFramework(curator);
124 * @Test public void testStopCache() {
126 * KafkaConsumerCache kafka = null; new CuratorFrameworkImpl(); new
127 * MetricsSetImpl(); try { kafka = new KafkaConsumerCache("123", null);
128 * kafka.stopCache(); } catch (NoClassDefFoundError e) {
136 public void testGetConsumerFor() {
138 KafkaConsumerCache kafka = null;
141 kafka = new KafkaConsumerCache();
142 kafka.getConsumerFor("testTopic", "CG1", "23");
143 } catch (NoClassDefFoundError e) {
145 } catch (KafkaConsumerCacheException e) {
146 // TODO Auto-generated catch block
153 public void testPutConsumerFor() {
155 Kafka011Consumer consumer = null;
156 KafkaConsumerCache kafka = null;
159 kafka = new KafkaConsumerCache();
161 } catch (NoClassDefFoundError e) {
163 kafka.putConsumerFor("testTopic", "CG1", "23", consumer);
164 } catch (NullPointerException e1) {
165 // TODO Auto-generated catch block
167 } catch (KafkaConsumerCacheException e1) {
168 // TODO Auto-generated catch block
169 e1.printStackTrace();
176 public void testGetConsumers() {
178 KafkaConsumerCache kafka = null;
181 kafka = new KafkaConsumerCache();
183 } catch (NoClassDefFoundError e) {
185 kafka.getConsumers();
186 } catch (NullPointerException e1) {
187 // TODO Auto-generated catch block
195 public void testDropAllConsumers() {
197 KafkaConsumerCache kafka = null;
199 kafka = new KafkaConsumerCache();
201 } catch (NoClassDefFoundError e) {
203 kafka.dropAllConsumers();
204 } catch (NullPointerException e1) {
205 // TODO Auto-generated catch block
213 public void testSignalOwnership() {
215 KafkaConsumerCache kafka = null;
218 kafka = new KafkaConsumerCache();
220 kafka.signalOwnership("testTopic", "CG1", "23");
221 } catch (KafkaConsumerCacheException e) {
224 } catch (NoClassDefFoundError e) {}
230 public void testDropConsumer() {
232 KafkaConsumerCache kafka = null;
235 kafka = new KafkaConsumerCache();
236 // kafka.dropConsumer("testTopic", "CG1", "23");
237 } catch (NoClassDefFoundError e) {
239 kafka.dropConsumer("testTopic", "CG1", "23");
240 } catch (NullPointerException e1) {
241 // TODO Auto-generated catch block