MR Java 11 Uplift
[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.core.classloader.annotations.PowerMockIgnore;
36 import org.powermock.modules.junit4.PowerMockRunner;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38
39 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
40
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;
46 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
47
48 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"})
49 @RunWith(PowerMockRunner.class)
50 @PrepareForTest({ AJSCPropertiesMap.class })
51 public class KafkaConsumerCacheTest {
52         private KafkaConsumerCache kafkaConsumerCache =null;
53         @Mock
54         private ConcurrentHashMap<String, Kafka011Consumer> fConsumers;
55         @Mock
56         private MetricsSet fMetrics;
57
58         @Before
59         public void setUp() throws Exception {
60                 MockitoAnnotations.initMocks(this);
61                 
62         }
63
64         @After
65         public void tearDown() throws Exception {
66         }
67
68
69         @Test
70         public void testSweep() {
71                 kafkaConsumerCache = new KafkaConsumerCache();
72                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
73                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "kSetting_TouchEveryMs")).thenReturn("100");
74                 kafkaConsumerCache.sweep();
75
76         }
77         
78
79         // DOES NOT WORK
80         @Test
81         public void testStartCache() {
82
83                 /*
84                  * KafkaConsumerCache kafka = null;
85                  * 
86                  * try { kafka = new KafkaConsumerCache("123", null);
87                  * 
88                  * } catch (NoClassDefFoundError e) { try { kafka.startCache("DMAAP",
89                  * null); } catch (NullPointerException e1) { // TODO Auto-generated
90                  * catch block assertTrue(true); } catch (KafkaConsumerCacheException
91                  * e1) { // TODO Auto-generated catch block e1.printStackTrace(); } }
92                  */
93
94                 
95                 new CuratorFrameworkImpl();
96                 new MetricsSetImpl();
97                 KafkaConsumerCache kafka=null;
98                 try {
99                         kafka = new KafkaConsumerCache();
100                         kafka.setfApiId("1");
101                         kafka.startCache("DMAAP", null);
102                 } catch (NoClassDefFoundError e) {
103
104                 } catch (KafkaConsumerCacheException e) {
105                         // TODO Auto-generated catch block
106                         e.printStackTrace();
107                 }
108
109         }
110
111         @Test
112         public void testGetCuratorFramework() {
113
114                 CuratorFramework curator = new CuratorFrameworkImpl();
115                 new MetricsSetImpl();
116                 try {
117
118                 } catch (NoClassDefFoundError e) {
119
120                         KafkaConsumerCache.getCuratorFramework(curator);
121                 }
122
123         }
124
125         /*
126          * @Test public void testStopCache() {
127          * 
128          * KafkaConsumerCache kafka = null; new CuratorFrameworkImpl(); new
129          * MetricsSetImpl(); try { kafka = new KafkaConsumerCache("123", null);
130          * kafka.stopCache(); } catch (NoClassDefFoundError e) {
131          * 
132          * }
133          * 
134          * }
135          */
136
137         @Test
138         public void testGetConsumerFor() {
139
140                 KafkaConsumerCache kafka = null;
141
142                 try {
143                         kafka = new KafkaConsumerCache();
144                         kafka.getConsumerFor("testTopic", "CG1", "23");
145                 } catch (NoClassDefFoundError e) {
146
147                 } catch (KafkaConsumerCacheException e) {
148                         // TODO Auto-generated catch block
149                         e.printStackTrace();
150                 }
151
152         }
153
154         @Test
155         public void testPutConsumerFor() {
156
157                 Kafka011Consumer consumer = null;
158                 KafkaConsumerCache kafka = null;
159
160                 try {
161                         kafka = new KafkaConsumerCache();
162
163                 } catch (NoClassDefFoundError e) {
164                         try {
165                                 kafka.putConsumerFor("testTopic", "CG1", "23", consumer);
166                         } catch (NullPointerException e1) {
167                                 // TODO Auto-generated catch block
168                                 assertTrue(true);
169                         } catch (KafkaConsumerCacheException e1) {
170                                 // TODO Auto-generated catch block
171                                 e1.printStackTrace();
172                         }
173                 }
174
175         }
176
177         @Test
178         public void testGetConsumers() {
179
180                 KafkaConsumerCache kafka = null;
181
182                 try {
183                         kafka = new KafkaConsumerCache();
184
185                 } catch (NoClassDefFoundError e) {
186                         try {
187                                 kafka.getConsumers();
188                         } catch (NullPointerException e1) {
189                                 // TODO Auto-generated catch block
190                                 assertTrue(true);
191                         }
192                 }
193
194         }
195
196         @Test
197         public void testDropAllConsumers() {
198
199                 KafkaConsumerCache kafka = null;
200                 try {
201                         kafka = new KafkaConsumerCache();
202
203                 } catch (NoClassDefFoundError e) {
204                         try {
205                                 kafka.dropAllConsumers();
206                         } catch (NullPointerException e1) {
207                                 // TODO Auto-generated catch block
208                                 assertTrue(true);
209                         }
210                 }
211
212         } 
213
214         @Test
215         public void testSignalOwnership() {
216
217                 KafkaConsumerCache kafka = null;
218
219                 try {
220                         kafka = new KafkaConsumerCache();
221                  try {
222                         kafka.signalOwnership("testTopic", "CG1", "23");
223                 } catch (KafkaConsumerCacheException e) {
224                         assertTrue(true);
225                 }
226                 } catch (NoClassDefFoundError e) {}
227
228                 // 
229         }
230
231         @Test
232         public void testDropConsumer() {
233
234                 KafkaConsumerCache kafka = null;
235
236                 try {
237                         kafka = new KafkaConsumerCache();
238                         // kafka.dropConsumer("testTopic", "CG1", "23");
239                 } catch (NoClassDefFoundError e) {
240                         try {
241                                 kafka.dropConsumer("testTopic", "CG1", "23");
242                         } catch (NullPointerException e1) {
243                                 // TODO Auto-generated catch block
244                                 assertTrue(true);
245                         }
246                 }
247
248         }
249         
250
251 }