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.service;
23 import static org.junit.Assert.*;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Mockito.when;
29 import java.io.IOException;
30 import java.util.ConcurrentModificationException;
32 import javax.servlet.ServletOutputStream;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
36 import org.junit.After;
37 import org.json.JSONArray;
38 import org.json.JSONException;
39 import org.json.JSONObject;
40 import org.junit.Assert;
41 import org.junit.Before;
42 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.mockito.InjectMocks;
46 import org.mockito.Mock;
47 import org.mockito.MockitoAnnotations;
48 import org.powermock.api.mockito.PowerMockito;
49 import org.powermock.core.classloader.annotations.PrepareForTest;
50 import org.powermock.modules.junit4.PowerMockRunner;
52 import com.att.ajsc.beans.PropertiesMapBean;
53 import org.onap.dmaap.dmf.mr.CambriaApiException;
54 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
55 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
56 import org.onap.dmaap.dmf.mr.beans.TopicBean;
57 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
58 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
59 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
60 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
61 import org.onap.dmaap.dmf.mr.metabroker.Topic;
62 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
63 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
64 import org.onap.dmaap.dmf.mr.service.TopicService;
65 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
66 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
67 import com.att.nsa.configs.ConfigDbException;
68 import com.att.nsa.security.NsaAcl;
69 import com.att.nsa.security.NsaApiKey;
70 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
71 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
73 //@RunWith(MockitoJUnitRunner.class)
74 @RunWith(PowerMockRunner.class)
75 @PrepareForTest({ PropertiesMapBean.class })
76 public class TopicRestServiceTest {
79 TopicRestService topicRestService;
82 private TopicService topicService;
84 private TopicRestService service = new TopicRestService();
86 private DMaaPErrorMessages errorMessages;
89 DMaaPContext dmaapContext;
92 ConfigurationReader configReader;
95 ServletOutputStream oStream;
98 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
101 DMaaPAAFAuthenticator dmaapAAFauthenticator;
106 NsaSimpleApiKey nsaSimpleApiKey;
109 HttpServletRequest httpServReq;
112 HttpServletResponse httpServRes;
115 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
130 public void setUp() throws Exception {
132 MockitoAnnotations.initMocks(this);
136 public void tearDown() throws Exception {
139 @Test(expected = DMaaPAccessDeniedException.class)
140 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
141 TopicExistsException, JSONException, ConfigDbException {
143 Assert.assertNotNull(topicRestService);
145 PowerMockito.mockStatic(PropertiesMapBean.class);
148 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
149 .thenReturn("namespace");
151 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
152 when(dmaapContext.getConfigReader()).thenReturn(configReader);
153 when(dmaapContext.getRequest()).thenReturn(httpServReq);
154 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
156 when(dmaapContext.getResponse()).thenReturn(httpServRes);
157 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
158 when(httpServReq.getMethod()).thenReturn("HEAD");
160 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
162 topicRestService.getTopics();
166 public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
167 TopicExistsException, JSONException, ConfigDbException {
169 Assert.assertNotNull(topicRestService);
171 PowerMockito.mockStatic(PropertiesMapBean.class);
174 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
175 .thenReturn("namespace");
177 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
178 when(dmaapContext.getConfigReader()).thenReturn(configReader);
179 when(dmaapContext.getRequest()).thenReturn(httpServReq);
180 when(httpServReq.getHeader("Authorization")).thenReturn(null);
182 when(dmaapContext.getResponse()).thenReturn(httpServRes);
183 String perms = "namespace" + "|" + "*" + "|" + "view";
184 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
186 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
188 topicRestService.getTopics();
192 public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
194 Assert.assertNotNull(topicRestService);
196 PowerMockito.mockStatic(PropertiesMapBean.class);
199 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
200 .thenReturn("namespace");
202 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
203 when(dmaapContext.getConfigReader()).thenReturn(configReader);
204 when(dmaapContext.getRequest()).thenReturn(httpServReq);
205 when(httpServReq.getHeader("Authorization")).thenReturn(null);
207 when(dmaapContext.getResponse()).thenReturn(httpServRes);
208 String perms = "namespace" + "|" + "*" + "|" + "view";
209 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
211 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
213 PowerMockito.doThrow(new IOException()).when(topicService).getTopics(any());
214 } catch (JSONException | ConfigDbException | IOException excp) {
219 topicRestService.getTopics();
220 } catch (CambriaApiException excp) {
225 @Test(expected = DMaaPAccessDeniedException.class)
226 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
227 TopicExistsException, JSONException, ConfigDbException {
229 Assert.assertNotNull(topicRestService);
231 PowerMockito.mockStatic(PropertiesMapBean.class);
234 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
235 .thenReturn("namespace");
237 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
238 when(dmaapContext.getConfigReader()).thenReturn(configReader);
239 when(dmaapContext.getRequest()).thenReturn(httpServReq);
240 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
242 when(dmaapContext.getResponse()).thenReturn(httpServRes);
244 topicRestService.getAllTopics();
248 public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
249 TopicExistsException, JSONException, ConfigDbException {
251 Assert.assertNotNull(topicRestService);
252 PowerMockito.mockStatic(PropertiesMapBean.class);
255 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
256 .thenReturn("namespace");
258 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
259 when(dmaapContext.getConfigReader()).thenReturn(configReader);
260 when(dmaapContext.getRequest()).thenReturn(httpServReq);
261 when(httpServReq.getHeader("Authorization")).thenReturn(null);
263 when(dmaapContext.getResponse()).thenReturn(httpServRes);
265 topicRestService.getAllTopics();
269 public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
271 Assert.assertNotNull(topicRestService);
272 PowerMockito.mockStatic(PropertiesMapBean.class);
275 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
276 .thenReturn("namespace");
278 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
279 when(dmaapContext.getConfigReader()).thenReturn(configReader);
280 when(dmaapContext.getRequest()).thenReturn(httpServReq);
281 when(httpServReq.getHeader("Authorization")).thenReturn(null);
283 when(dmaapContext.getResponse()).thenReturn(httpServRes);
286 PowerMockito.doThrow(new IOException()).when(topicService).getAllTopics(any());
287 } catch (JSONException | ConfigDbException | IOException excp) {
292 topicRestService.getAllTopics();
293 } catch (CambriaApiException excp) {
298 @Test(expected = DMaaPAccessDeniedException.class)
299 public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
300 TopicExistsException, JSONException, ConfigDbException {
302 Assert.assertNotNull(topicRestService);
304 PowerMockito.mockStatic(PropertiesMapBean.class);
307 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
308 .thenReturn("enfTopicName");
310 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
311 when(dmaapContext.getConfigReader()).thenReturn(configReader);
312 when(dmaapContext.getRequest()).thenReturn(httpServReq);
313 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
315 when(dmaapContext.getResponse()).thenReturn(httpServRes);
317 topicRestService.getTopic("topicName");
321 public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
322 TopicExistsException, JSONException, ConfigDbException {
324 Assert.assertNotNull(topicRestService);
326 PowerMockito.mockStatic(PropertiesMapBean.class);
329 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
330 .thenReturn("enfTopicName");
332 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
333 when(dmaapContext.getConfigReader()).thenReturn(configReader);
334 when(dmaapContext.getRequest()).thenReturn(httpServReq);
335 when(httpServReq.getHeader("Authorization")).thenReturn(null);
337 when(dmaapContext.getResponse()).thenReturn(httpServRes);
339 topicRestService.getTopic("topicName");
343 public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
345 Assert.assertNotNull(topicRestService);
347 PowerMockito.mockStatic(PropertiesMapBean.class);
350 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
351 .thenReturn("enfTopicName");
353 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
354 when(dmaapContext.getConfigReader()).thenReturn(configReader);
355 when(dmaapContext.getRequest()).thenReturn(httpServReq);
356 when(httpServReq.getHeader("Authorization")).thenReturn(null);
358 when(dmaapContext.getResponse()).thenReturn(httpServRes);
361 PowerMockito.doThrow(new IOException()).when(topicService).getTopic(any(), any());
362 } catch (TopicExistsException | ConfigDbException | IOException excp) {
367 topicRestService.getTopic("topicName");
368 } catch (CambriaApiException excp) {
374 public void testCreateTopic()
375 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
377 Assert.assertNotNull(topicRestService);
379 when(dmaapContext.getRequest()).thenReturn(httpServReq);
380 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
381 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
382 when(dmaapContext.getConfigReader()).thenReturn(configReader);
384 TopicBean topicBean = new TopicBean();
385 topicBean.setTopicName("enfTopicNamePlusExtra");
387 topicRestService.createTopic(topicBean);
391 public void testCreateTopic_error() {
393 Assert.assertNotNull(topicRestService);
395 when(dmaapContext.getRequest()).thenReturn(httpServReq);
396 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
397 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
398 when(dmaapContext.getConfigReader()).thenReturn(configReader);
400 TopicBean topicBean = new TopicBean();
401 topicBean.setTopicName("enfTopicNamePlusExtra");
404 PowerMockito.doThrow(new IOException()).when(topicService).createTopic(any(), any());
405 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
407 } catch (CambriaApiException excp) {
412 topicRestService.createTopic(topicBean);
413 } catch (CambriaApiException excp) {
418 PowerMockito.doThrow(new TopicExistsException("error")).when(topicService).createTopic(any(), any());
419 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
421 } catch (CambriaApiException excp) {
426 topicRestService.createTopic(topicBean);
427 } catch (CambriaApiException excp) {
432 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).createTopic(any(), any());
433 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
435 } catch (CambriaApiException excp) {
440 topicRestService.createTopic(topicBean);
441 } catch (CambriaApiException excp) {
447 public void testDeleteTopic()
448 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
450 Assert.assertNotNull(topicRestService);
452 when(dmaapContext.getRequest()).thenReturn(httpServReq);
453 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
454 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
455 when(dmaapContext.getConfigReader()).thenReturn(configReader);
457 TopicBean topicBean = new TopicBean();
458 topicBean.setTopicName("enfTopicNamePlusExtra");
460 topicRestService.deleteTopic("enfTopicNamePlusExtra");
464 public void testDeleteTopic_error()
465 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
467 Assert.assertNotNull(topicRestService);
469 when(dmaapContext.getRequest()).thenReturn(httpServReq);
470 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
471 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
472 when(dmaapContext.getConfigReader()).thenReturn(configReader);
474 TopicBean topicBean = new TopicBean();
475 topicBean.setTopicName("enfTopicNamePlusExtra");
478 PowerMockito.doThrow(new IOException()).when(topicService).deleteTopic(any(), any());
479 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
480 | DMaaPAccessDeniedException excp) {
485 topicRestService.deleteTopic("enfTopicNamePlusExtra");
486 } catch (CambriaApiException excp) {
491 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).deleteTopic(any(),
493 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
494 | DMaaPAccessDeniedException excp) {
499 topicRestService.deleteTopic("enfTopicNamePlusExtra");
500 } catch (CambriaApiException excp) {
506 public void testGetPublishersByTopicName()
507 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
509 Assert.assertNotNull(topicRestService);
511 when(dmaapContext.getRequest()).thenReturn(httpServReq);
512 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
513 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
514 when(dmaapContext.getConfigReader()).thenReturn(configReader);
516 TopicBean topicBean = new TopicBean();
517 topicBean.setTopicName("enfTopicNamePlusExtra");
519 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
523 public void testGetPublishersByTopicName_error() {
525 Assert.assertNotNull(topicRestService);
527 when(dmaapContext.getRequest()).thenReturn(httpServReq);
528 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
529 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
530 when(dmaapContext.getConfigReader()).thenReturn(configReader);
532 TopicBean topicBean = new TopicBean();
533 topicBean.setTopicName("enfTopicNamePlusExtra");
536 PowerMockito.doThrow(new IOException()).when(topicService).getPublishersByTopicName(any(),
538 } catch (TopicExistsException | ConfigDbException | IOException e) {
543 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
544 } catch (CambriaApiException excp) {
550 public void testPermitPublisherForTopic()
551 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
553 Assert.assertNotNull(topicRestService);
555 when(dmaapContext.getRequest()).thenReturn(httpServReq);
556 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
557 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
558 when(dmaapContext.getConfigReader()).thenReturn(configReader);
560 TopicBean topicBean = new TopicBean();
561 topicBean.setTopicName("enfTopicNamePlusExtra");
563 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
567 public void testPermitPublisherForTopic_error()
568 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
570 Assert.assertNotNull(topicRestService);
572 when(dmaapContext.getRequest()).thenReturn(httpServReq);
573 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
574 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
575 when(dmaapContext.getConfigReader()).thenReturn(configReader);
577 TopicBean topicBean = new TopicBean();
578 topicBean.setTopicName("enfTopicNamePlusExtra");
581 PowerMockito.doThrow(new IOException()).when(topicService).permitPublisherForTopic(any(),
583 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
584 | DMaaPAccessDeniedException excp) {
589 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
590 } catch (CambriaApiException excp) {
595 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).permitPublisherForTopic(any(),
597 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
598 | DMaaPAccessDeniedException excp) {
603 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
604 } catch (CambriaApiException excp) {
610 public void testDenyPublisherForTopic()
611 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
613 Assert.assertNotNull(topicRestService);
615 when(dmaapContext.getRequest()).thenReturn(httpServReq);
616 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
617 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
618 when(dmaapContext.getConfigReader()).thenReturn(configReader);
620 TopicBean topicBean = new TopicBean();
621 topicBean.setTopicName("enfTopicNamePlusExtra");
623 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
627 public void testDenyPublisherForTopic_error()
628 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
630 Assert.assertNotNull(topicRestService);
632 when(dmaapContext.getRequest()).thenReturn(httpServReq);
633 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
634 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
635 when(dmaapContext.getConfigReader()).thenReturn(configReader);
637 TopicBean topicBean = new TopicBean();
638 topicBean.setTopicName("enfTopicNamePlusExtra");
641 PowerMockito.doThrow(new IOException()).when(topicService).denyPublisherForTopic(any(),
643 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
644 | DMaaPAccessDeniedException excp) {
649 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
650 } catch (CambriaApiException excp) {
655 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyPublisherForTopic(any(),
657 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
658 | DMaaPAccessDeniedException excp) {
663 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
664 } catch (CambriaApiException excp) {
671 public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
672 TopicExistsException, AccessDeniedException {
674 Assert.assertNotNull(topicRestService);
676 when(dmaapContext.getRequest()).thenReturn(httpServReq);
677 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
678 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
679 when(dmaapContext.getConfigReader()).thenReturn(configReader);
681 TopicBean topicBean = new TopicBean();
682 topicBean.setTopicName("enfTopicNamePlusExtra");
684 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
688 public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
689 TopicExistsException, AccessDeniedException {
691 Assert.assertNotNull(topicRestService);
693 when(dmaapContext.getRequest()).thenReturn(httpServReq);
694 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
695 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
696 when(dmaapContext.getConfigReader()).thenReturn(configReader);
698 TopicBean topicBean = new TopicBean();
699 topicBean.setTopicName("enfTopicNamePlusExtra");
702 PowerMockito.doThrow(new IOException()).when(topicService).getConsumersByTopicName(any(),
704 } catch (TopicExistsException | ConfigDbException | IOException excp) {
709 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
710 } catch (CambriaApiException excp) {
716 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
717 TopicExistsException, AccessDeniedException {
719 Assert.assertNotNull(topicRestService);
721 when(dmaapContext.getRequest()).thenReturn(httpServReq);
722 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
723 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
724 when(dmaapContext.getConfigReader()).thenReturn(configReader);
726 TopicBean topicBean = new TopicBean();
727 topicBean.setTopicName("enfTopicNamePlusExtra");
729 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
733 public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
734 TopicExistsException, AccessDeniedException {
736 Assert.assertNotNull(topicRestService);
738 when(dmaapContext.getRequest()).thenReturn(httpServReq);
739 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
740 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
741 when(dmaapContext.getConfigReader()).thenReturn(configReader);
743 TopicBean topicBean = new TopicBean();
744 topicBean.setTopicName("enfTopicNamePlusExtra");
747 PowerMockito.doThrow(new IOException()).when(topicService).permitConsumerForTopic(any(),
749 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
750 | DMaaPAccessDeniedException excp) {
755 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
756 } catch (CambriaApiException excp) {
762 public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
763 IOException, TopicExistsException, AccessDeniedException {
765 Assert.assertNotNull(topicRestService);
767 when(dmaapContext.getRequest()).thenReturn(httpServReq);
768 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
769 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
770 when(dmaapContext.getConfigReader()).thenReturn(configReader);
772 TopicBean topicBean = new TopicBean();
773 topicBean.setTopicName("enfTopicNamePlusExtra");
775 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
779 public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
780 TopicExistsException, AccessDeniedException {
782 Assert.assertNotNull(topicRestService);
784 when(dmaapContext.getRequest()).thenReturn(httpServReq);
785 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
786 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
787 when(dmaapContext.getConfigReader()).thenReturn(configReader);
789 TopicBean topicBean = new TopicBean();
790 topicBean.setTopicName("enfTopicNamePlusExtra");
792 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
796 public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
797 TopicExistsException, AccessDeniedException {
799 Assert.assertNotNull(topicRestService);
801 when(dmaapContext.getRequest()).thenReturn(httpServReq);
802 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
803 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
804 when(dmaapContext.getConfigReader()).thenReturn(configReader);
806 TopicBean topicBean = new TopicBean();
807 topicBean.setTopicName("enfTopicNamePlusExtra");
810 PowerMockito.doThrow(new IOException()).when(topicService).denyConsumerForTopic(any(),
812 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
813 | DMaaPAccessDeniedException excp) {
818 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
819 } catch (CambriaApiException excp) {
824 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyConsumerForTopic(any(),
826 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
827 | DMaaPAccessDeniedException excp) {
832 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
833 } catch (CambriaApiException excp) {