2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END=========================================================
\r
21 package com.att.nsa.cambria.service.impl;
\r
23 /*import static org.mockito.Matchers.anyBoolean;
\r
24 import static org.mockito.Matchers.anyInt;
\r
25 import static org.mockito.Matchers.anyString;
\r
26 import static org.mockito.Mockito.times;
\r
27 import static org.mockito.Mockito.verify;
\r
28 import static org.mockito.Mockito.when;*/
\r
30 import java.io.IOException;
\r
31 import java.util.Arrays;
\r
32 import java.util.HashSet;
\r
34 import javax.servlet.ServletOutputStream;
\r
35 import javax.servlet.http.HttpServletRequest;
\r
36 import javax.servlet.http.HttpServletResponse;
\r
38 import org.json.JSONArray;
\r
39 import org.json.JSONException;
\r
40 import org.json.JSONObject;
\r
41 import org.junit.Assert;
\r
42 import org.junit.Before;
\r
43 import org.junit.Test;
\r
44 import org.junit.runner.RunWith;
\r
45 /*import org.mockito.InjectMocks;
\r
46 import org.mockito.Mock;
\r
47 import org.mockito.MockitoAnnotations;
\r
48 import org.powermock.api.mockito.PowerMockito;
\r
49 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
50 import org.powermock.modules.junit4.PowerMockRunner;
\r
52 import com.att.ajsc.beans.PropertiesMapBean;
\r
53 import com.att.nsa.cambria.CambriaApiException;
\r
54 import com.att.nsa.cambria.beans.DMaaPContext;
\r
55 import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
\r
56 import com.att.nsa.cambria.beans.TopicBean;
\r
57 import com.att.nsa.cambria.constants.CambriaConstants;
\r
58 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
\r
59 import com.att.nsa.cambria.exception.DMaaPErrorMessages;
\r
60 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
\r
61 import com.att.nsa.cambria.metabroker.Topic;
\r
62 import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
\r
63 import com.att.nsa.cambria.security.DMaaPAuthenticator;
\r
64 import com.att.nsa.cambria.utils.ConfigurationReader;
\r
65 import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
\r
66 import com.att.nsa.configs.ConfigDbException;*/
\r
67 import com.att.nsa.security.NsaAcl;
\r
68 import com.att.nsa.security.NsaApiKey;
\r
69 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
\r
70 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
\r
72 //@RunWith(MockitoJUnitRunner.class)
\r
73 /*@RunWith(PowerMockRunner.class)
\r
74 @PrepareForTest({ PropertiesMapBean.class })*/
\r
75 public class TopicServiceImplTest {/*
\r
78 TopicServiceImpl topicService;
\r
81 private DMaaPErrorMessages errorMessages;
\r
84 DMaaPContext dmaapContext;
\r
87 ConfigurationReader configReader;
\r
90 ServletOutputStream oStream;
\r
93 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
\r
96 DMaaPAAFAuthenticator dmaapAAFauthenticator;
\r
101 NsaSimpleApiKey nsaSimpleApiKey;
\r
104 HttpServletRequest httpServReq;
\r
107 HttpServletResponse httpServRes;
\r
110 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
\r
113 Topic createdTopic;
\r
119 JSONObject jsonObj;
\r
122 JSONArray jsonArray;
\r
125 public void setUp() {
\r
126 MockitoAnnotations.initMocks(this);
\r
129 @Test(expected = DMaaPAccessDeniedException.class)
\r
130 public void testCreateTopicWithEnforcedName()
\r
131 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
133 Assert.assertNotNull(topicService);
\r
135 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
137 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
138 .thenReturn("enfTopicName");
\r
140 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
141 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
142 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
143 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
144 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
146 TopicBean topicBean = new TopicBean();
\r
147 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
149 topicService.createTopic(dmaapContext, topicBean);
\r
153 public void testCreateTopicWithTopicNameNotEnforced()
\r
154 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
156 Assert.assertNotNull(topicService);
\r
158 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
159 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
161 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
162 .thenReturn("enfTopicName");
\r
164 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
165 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
167 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
168 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
170 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
171 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
172 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
173 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
175 when(nsaAcl.isActive()).thenReturn(true);
\r
176 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
178 when(createdTopic.getName()).thenReturn("topicName");
\r
179 when(createdTopic.getOwner()).thenReturn("Owner");
\r
180 when(createdTopic.getDescription()).thenReturn("Description");
\r
181 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
182 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
184 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
\r
185 .thenReturn(createdTopic);
\r
187 TopicBean topicBean = new TopicBean();
\r
188 topicBean.setTopicName("NotEnforcedTopicName");
\r
190 topicService.createTopic(dmaapContext, topicBean);
\r
192 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
\r
196 @Test(expected = DMaaPAccessDeniedException.class)
\r
197 public void testCreateTopicNoUserInContextAndNoAuthHeader()
\r
198 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
200 Assert.assertNotNull(topicService);
\r
202 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
204 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
205 .thenReturn("enfTopicName");
\r
207 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
208 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
209 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
211 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
212 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
214 TopicBean topicBean = new TopicBean();
\r
215 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
217 topicService.createTopic(dmaapContext, topicBean);
\r
220 @Test(expected = DMaaPAccessDeniedException.class)
\r
221 public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
\r
222 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
224 Assert.assertNotNull(topicService);
\r
226 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
228 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
229 .thenReturn("enfTopicName");
\r
231 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
\r
232 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
233 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
235 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
236 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
238 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
\r
239 // anyString())).thenReturn(false);
\r
241 TopicBean topicBean = new TopicBean();
\r
242 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
244 topicService.createTopic(dmaapContext, topicBean);
\r
247 @Test(expected = TopicExistsException.class)
\r
248 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
249 TopicExistsException, JSONException, ConfigDbException {
\r
251 Assert.assertNotNull(topicService);
\r
252 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
253 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
254 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
255 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
256 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
257 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
259 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
261 topicService.getTopic(dmaapContext, "topicName");
\r
265 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
266 TopicExistsException, JSONException, ConfigDbException {
\r
268 Assert.assertNotNull(topicService);
\r
269 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
270 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
271 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
272 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
273 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
275 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
\r
277 when(createdTopic.getName()).thenReturn("topicName");
\r
278 when(createdTopic.getDescription()).thenReturn("topicDescription");
\r
279 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
281 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
282 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
284 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
286 when(httpServRes.getOutputStream()).thenReturn(oStream);
\r
288 topicService.getTopic(dmaapContext, "topicName");
\r
291 @Test(expected = TopicExistsException.class)
\r
292 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
293 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
295 Assert.assertNotNull(topicService);
\r
297 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
298 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
299 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
300 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
301 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
302 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
304 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
306 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
311 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
312 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
314 Assert.assertNotNull(topicService);
\r
316 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
317 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
318 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
319 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
320 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
321 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
323 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
324 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
325 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
328 @Test(expected = TopicExistsException.class)
\r
329 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
330 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
332 Assert.assertNotNull(topicService);
\r
334 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
335 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
336 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
337 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
338 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
339 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
341 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
343 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
348 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
349 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
351 Assert.assertNotNull(topicService);
\r
353 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
354 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
355 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
356 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
357 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
358 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
360 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
362 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
364 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
368 // public void testDeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
369 // IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
371 // Assert.assertNotNull(topicService);
\r
373 // PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
375 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
377 // PowerMockito.when(AJSCPropertiesMap.
\r
378 // getProperty(CambriaConstants.msgRtr_prop,"msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
\r
381 // when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
382 // when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
383 // when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
384 // when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
385 // when(httpServReq.getMethod()).thenReturn("HEAD");
\r
387 // when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
389 // when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
391 // topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
397 @Test(expected = TopicExistsException.class)
\r
398 public void testPermitPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
399 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
401 Assert.assertNotNull(topicService);
\r
403 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
404 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
405 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
406 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
408 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
409 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
410 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
411 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
412 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
413 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
415 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
417 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
421 public void testPermitPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
422 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
424 Assert.assertNotNull(topicService);
\r
426 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
427 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
428 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
429 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
431 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
432 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
433 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
434 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
435 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
436 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
438 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
441 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
445 @Test(expected = TopicExistsException.class)
\r
446 public void testDenyPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
447 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
449 Assert.assertNotNull(topicService);
\r
451 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
452 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
453 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
454 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
456 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
457 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
458 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
459 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
460 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
461 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
463 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
465 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
469 public void testDenyPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
470 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
472 Assert.assertNotNull(topicService);
\r
474 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
475 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
476 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
477 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
479 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
480 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
481 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
482 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
483 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
484 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
486 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
489 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
492 @Test(expected = TopicExistsException.class)
\r
493 public void testPermitConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
494 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
496 Assert.assertNotNull(topicService);
\r
498 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
499 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
500 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
501 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
503 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
504 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
505 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
506 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
507 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
508 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
510 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
512 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
516 public void testPermitConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
517 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
519 Assert.assertNotNull(topicService);
\r
521 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
522 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
523 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
524 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
526 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
527 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
528 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
529 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
530 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
531 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
533 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
536 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
540 @Test(expected = TopicExistsException.class)
\r
541 public void testDenyConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
542 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
544 Assert.assertNotNull(topicService);
\r
546 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
547 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
548 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
549 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
551 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
552 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
553 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
554 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
555 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
556 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
558 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
560 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
564 public void testDenyConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
565 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
567 Assert.assertNotNull(topicService);
\r
569 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
570 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
571 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
572 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
574 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
575 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
576 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
577 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
578 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
579 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
581 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
584 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r