83866cf491e947b13e3e81986a1915d3ec317add
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / backends / kafka / KafkaConsumerCacheTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21  package org.onap.dmaap.mr.cambria.backends.kafka;
22
23 import static org.junit.Assert.*;
24
25 import java.util.concurrent.ConcurrentHashMap;
26
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;
37
38 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
39
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;
46
47 @RunWith(PowerMockRunner.class)
48 @PrepareForTest({ AJSCPropertiesMap.class })
49 public class KafkaConsumerCacheTest {
50         private KafkaConsumerCache kafkaConsumerCache =null;
51         @Mock
52         private ConcurrentHashMap<String, Kafka011Consumer> fConsumers;
53         @Mock
54         private MetricsSet fMetrics;
55
56         @Before
57         public void setUp() throws Exception {
58                 MockitoAnnotations.initMocks(this);
59                 
60         }
61
62         @After
63         public void tearDown() throws Exception {
64         }
65
66
67         @Test
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();
73
74         }
75         
76
77         // DOES NOT WORK
78         @Test
79         public void testStartCache() {
80
81                 /*
82                  * KafkaConsumerCache kafka = null;
83                  * 
84                  * try { kafka = new KafkaConsumerCache("123", null);
85                  * 
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(); } }
90                  */
91
92                 
93                 new CuratorFrameworkImpl();
94                 new MetricsSetImpl();
95                 KafkaConsumerCache kafka=null;
96                 try {
97                         kafka = new KafkaConsumerCache();
98                         kafka.setfApiId("1");
99                         kafka.startCache("DMAAP", null);
100                 } catch (NoClassDefFoundError e) {
101
102                 } catch (KafkaConsumerCacheException e) {
103                         // TODO Auto-generated catch block
104                         e.printStackTrace();
105                 }
106
107         }
108
109         @Test
110         public void testGetCuratorFramework() {
111
112                 CuratorFramework curator = new CuratorFrameworkImpl();
113                 new MetricsSetImpl();
114                 try {
115
116                 } catch (NoClassDefFoundError e) {
117
118                         KafkaConsumerCache.getCuratorFramework(curator);
119                 }
120
121         }
122
123         /*
124          * @Test public void testStopCache() {
125          * 
126          * KafkaConsumerCache kafka = null; new CuratorFrameworkImpl(); new
127          * MetricsSetImpl(); try { kafka = new KafkaConsumerCache("123", null);
128          * kafka.stopCache(); } catch (NoClassDefFoundError e) {
129          * 
130          * }
131          * 
132          * }
133          */
134
135         @Test
136         public void testGetConsumerFor() {
137
138                 KafkaConsumerCache kafka = null;
139
140                 try {
141                         kafka = new KafkaConsumerCache();
142                         kafka.getConsumerFor("testTopic", "CG1", "23");
143                 } catch (NoClassDefFoundError e) {
144
145                 } catch (KafkaConsumerCacheException e) {
146                         // TODO Auto-generated catch block
147                         e.printStackTrace();
148                 }
149
150         }
151
152         @Test
153         public void testPutConsumerFor() {
154
155                 Kafka011Consumer consumer = null;
156                 KafkaConsumerCache kafka = null;
157
158                 try {
159                         kafka = new KafkaConsumerCache();
160
161                 } catch (NoClassDefFoundError e) {
162                         try {
163                                 kafka.putConsumerFor("testTopic", "CG1", "23", consumer);
164                         } catch (NullPointerException e1) {
165                                 // TODO Auto-generated catch block
166                                 assertTrue(true);
167                         } catch (KafkaConsumerCacheException e1) {
168                                 // TODO Auto-generated catch block
169                                 e1.printStackTrace();
170                         }
171                 }
172
173         }
174
175         @Test
176         public void testGetConsumers() {
177
178                 KafkaConsumerCache kafka = null;
179
180                 try {
181                         kafka = new KafkaConsumerCache();
182
183                 } catch (NoClassDefFoundError e) {
184                         try {
185                                 kafka.getConsumers();
186                         } catch (NullPointerException e1) {
187                                 // TODO Auto-generated catch block
188                                 assertTrue(true);
189                         }
190                 }
191
192         }
193
194         @Test
195         public void testDropAllConsumers() {
196
197                 KafkaConsumerCache kafka = null;
198                 try {
199                         kafka = new KafkaConsumerCache();
200
201                 } catch (NoClassDefFoundError e) {
202                         try {
203                                 kafka.dropAllConsumers();
204                         } catch (NullPointerException e1) {
205                                 // TODO Auto-generated catch block
206                                 assertTrue(true);
207                         }
208                 }
209
210         }
211
212         @Test
213         public void testSignalOwnership() {
214
215                 KafkaConsumerCache kafka = null;
216
217                 try {
218                         kafka = new KafkaConsumerCache();
219                         // kafka.signalOwnership("testTopic", "CG1", "23");
220                 } catch (NoClassDefFoundError e) {
221                         try {
222                                 kafka.signalOwnership("testTopic", "CG1", "23");
223                         } catch (KafkaConsumerCacheException e1) {
224                                 // TODO Auto-generated catch block
225                                 e.printStackTrace();
226                         } catch (NullPointerException e1) {
227                                 // TODO Auto-generated catch block
228                                 // assertTrue(true);
229                                 e1.printStackTrace();
230                         }
231
232                 }
233
234                 // assertTrue(true);
235         }
236
237         @Test
238         public void testDropConsumer() {
239
240                 KafkaConsumerCache kafka = null;
241
242                 try {
243                         kafka = new KafkaConsumerCache();
244                         // kafka.dropConsumer("testTopic", "CG1", "23");
245                 } catch (NoClassDefFoundError e) {
246                         try {
247                                 kafka.dropConsumer("testTopic", "CG1", "23");
248                         } catch (NullPointerException e1) {
249                                 // TODO Auto-generated catch block
250                                 assertTrue(true);
251                         }
252                 }
253
254         }
255
256 }