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.core.classloader.annotations.PowerMockIgnore;
36 import org.powermock.modules.junit4.PowerMockRunner;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
39 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
41 import org.onap.dmaap.dmf.mr.backends.MetricsSet;
42 import org.onap.dmaap.dmf.mr.backends.kafka.Kafka011Consumer;
43 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache;
44 import org.onap.dmaap.dmf.mr.backends.kafka.KafkaConsumerCache.KafkaConsumerCacheException;
45 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
47 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
48 @RunWith(PowerMockRunner.class)
49 @PrepareForTest({ AJSCPropertiesMap.class })
50 public class KafkaConsumerCacheTest {
51 private KafkaConsumerCache kafkaConsumerCache =null;
53 private ConcurrentHashMap<String, Kafka011Consumer> fConsumers;
55 private MetricsSet fMetrics;
58 public void setUp() throws Exception {
59 MockitoAnnotations.initMocks(this);
64 public void tearDown() throws Exception {
69 public void testSweep() {
70 kafkaConsumerCache = new KafkaConsumerCache();
71 PowerMockito.mockStatic(AJSCPropertiesMap.class);
72 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "kSetting_TouchEveryMs")).thenReturn("100");
73 kafkaConsumerCache.sweep();
80 public void testStartCache() {
83 * KafkaConsumerCache kafka = null;
85 * try { kafka = new KafkaConsumerCache("123", null);
87 * } catch (NoClassDefFoundError e) { try { kafka.startCache("DMAAP",
88 * null); } catch (NullPointerException e1) { // TODO Auto-generated
89 * catch block assertTrue(true); } catch (KafkaConsumerCacheException
90 * e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
94 new CuratorFrameworkImpl();
96 KafkaConsumerCache kafka=null;
98 kafka = new KafkaConsumerCache();
100 kafka.startCache("DMAAP", null);
101 } catch (NoClassDefFoundError e) {
103 } catch (KafkaConsumerCacheException e) {
104 // TODO Auto-generated catch block
111 public void testGetCuratorFramework() {
113 CuratorFramework curator = new CuratorFrameworkImpl();
114 new MetricsSetImpl();
117 } catch (NoClassDefFoundError e) {
119 KafkaConsumerCache.getCuratorFramework(curator);
125 * @Test public void testStopCache() {
127 * KafkaConsumerCache kafka = null; new CuratorFrameworkImpl(); new
128 * MetricsSetImpl(); try { kafka = new KafkaConsumerCache("123", null);
129 * kafka.stopCache(); } catch (NoClassDefFoundError e) {
137 public void testGetConsumerFor() {
139 KafkaConsumerCache kafka = null;
142 kafka = new KafkaConsumerCache();
143 kafka.getConsumerFor("testTopic", "CG1", "23");
144 } catch (NoClassDefFoundError e) {
146 } catch (KafkaConsumerCacheException e) {
147 // TODO Auto-generated catch block
154 public void testPutConsumerFor() {
156 Kafka011Consumer consumer = null;
157 KafkaConsumerCache kafka = null;
160 kafka = new KafkaConsumerCache();
162 } catch (NoClassDefFoundError e) {
164 kafka.putConsumerFor("testTopic", "CG1", "23", consumer);
165 } catch (NullPointerException e1) {
166 // TODO Auto-generated catch block
168 } catch (KafkaConsumerCacheException e1) {
169 // TODO Auto-generated catch block
170 e1.printStackTrace();
177 public void testGetConsumers() {
179 KafkaConsumerCache kafka = null;
182 kafka = new KafkaConsumerCache();
184 } catch (NoClassDefFoundError e) {
186 kafka.getConsumers();
187 } catch (NullPointerException e1) {
188 // TODO Auto-generated catch block
196 public void testDropAllConsumers() {
198 KafkaConsumerCache kafka = null;
200 kafka = new KafkaConsumerCache();
202 } catch (NoClassDefFoundError e) {
204 kafka.dropAllConsumers();
205 } catch (NullPointerException e1) {
206 // TODO Auto-generated catch block
214 public void testSignalOwnership() {
216 KafkaConsumerCache kafka = null;
219 kafka = new KafkaConsumerCache();
221 kafka.signalOwnership("testTopic", "CG1", "23");
222 } catch (KafkaConsumerCacheException e) {
225 } catch (NoClassDefFoundError e) {}
231 public void testDropConsumer() {
233 KafkaConsumerCache kafka = null;
236 kafka = new KafkaConsumerCache();
237 // kafka.dropConsumer("testTopic", "CG1", "23");
238 } catch (NoClassDefFoundError e) {
240 kafka.dropConsumer("testTopic", "CG1", "23");
241 } catch (NullPointerException e1) {
242 // TODO Auto-generated catch block