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.assertTrue;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Mockito.when;
28 import com.att.ajsc.beans.PropertiesMapBean;
29 import com.att.nsa.configs.ConfigDbException;
30 import com.att.nsa.security.NsaAcl;
31 import com.att.nsa.security.NsaApiKey;
32 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
33 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
34 import java.io.IOException;
35 import javax.servlet.ServletOutputStream;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38 import org.json.JSONArray;
39 import org.json.JSONException;
40 import org.json.JSONObject;
41 import org.junit.After;
42 import org.junit.Assert;
43 import org.junit.Before;
44 import org.junit.Test;
45 import org.junit.runner.RunWith;
46 import org.mockito.InjectMocks;
47 import org.mockito.Mock;
48 import org.mockito.MockitoAnnotations;
49 import org.onap.dmaap.dmf.mr.CambriaApiException;
50 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
51 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
52 import org.onap.dmaap.dmf.mr.beans.TopicBean;
53 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
54 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
55 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
56 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
57 import org.onap.dmaap.dmf.mr.metabroker.Topic;
58 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
59 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
60 import org.onap.dmaap.dmf.mr.service.TopicService;
61 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
62 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
63 import org.powermock.api.mockito.PowerMockito;
64 import org.powermock.core.classloader.annotations.PowerMockIgnore;
65 import org.powermock.core.classloader.annotations.PrepareForTest;
66 import org.powermock.modules.junit4.PowerMockRunner;
68 //@RunWith(MockitoJUnitRunner.class)
69 @RunWith(PowerMockRunner.class)
70 @PowerMockIgnore("jdk.internal.reflect.*")
71 @PrepareForTest({ PropertiesMapBean.class, DMaaPResponseBuilder.class })
72 public class TopicRestServiceTest {
75 TopicRestService topicRestService;
78 private TopicService topicService;
80 private TopicRestService service = new TopicRestService();
82 private DMaaPErrorMessages errorMessages;
85 DMaaPContext dmaapContext;
88 ConfigurationReader configReader;
91 ServletOutputStream oStream;
94 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
97 DMaaPAAFAuthenticator dmaapAAFauthenticator;
102 NsaSimpleApiKey nsaSimpleApiKey;
105 HttpServletRequest httpServReq;
108 HttpServletResponse httpServRes;
111 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
126 public void setUp() throws Exception {
128 MockitoAnnotations.initMocks(this);
132 public void tearDown() throws Exception {
135 @Test(expected = DMaaPAccessDeniedException.class)
136 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
137 TopicExistsException, JSONException, ConfigDbException {
139 Assert.assertNotNull(topicRestService);
141 PowerMockito.mockStatic(PropertiesMapBean.class);
144 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
145 .thenReturn("namespace");
147 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
148 when(dmaapContext.getConfigReader()).thenReturn(configReader);
149 when(dmaapContext.getRequest()).thenReturn(httpServReq);
150 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
152 when(dmaapContext.getResponse()).thenReturn(httpServRes);
153 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
154 when(httpServReq.getMethod()).thenReturn("HEAD");
156 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
158 topicRestService.getTopics();
162 public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
163 TopicExistsException, JSONException, ConfigDbException {
165 Assert.assertNotNull(topicRestService);
167 PowerMockito.mockStatic(PropertiesMapBean.class);
170 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
171 .thenReturn("namespace");
173 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
174 when(dmaapContext.getConfigReader()).thenReturn(configReader);
175 when(dmaapContext.getRequest()).thenReturn(httpServReq);
176 when(httpServReq.getHeader("Authorization")).thenReturn(null);
178 when(dmaapContext.getResponse()).thenReturn(httpServRes);
179 String perms = "namespace" + "|" + "*" + "|" + "view";
180 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
182 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
184 topicRestService.getTopics();
188 public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
190 Assert.assertNotNull(topicRestService);
192 PowerMockito.mockStatic(PropertiesMapBean.class);
195 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
196 .thenReturn("namespace");
198 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
199 when(dmaapContext.getConfigReader()).thenReturn(configReader);
200 when(dmaapContext.getRequest()).thenReturn(httpServReq);
201 when(httpServReq.getHeader("Authorization")).thenReturn(null);
203 when(dmaapContext.getResponse()).thenReturn(httpServRes);
204 String perms = "namespace" + "|" + "*" + "|" + "view";
205 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
207 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
209 PowerMockito.doThrow(new IOException()).when(topicService).getTopics(any());
210 } catch (JSONException | ConfigDbException | IOException excp) {
215 topicRestService.getTopics();
216 } catch (CambriaApiException excp) {
221 @Test(expected = DMaaPAccessDeniedException.class)
222 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
223 TopicExistsException, JSONException, ConfigDbException {
225 Assert.assertNotNull(topicRestService);
227 PowerMockito.mockStatic(PropertiesMapBean.class);
230 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
231 .thenReturn("namespace");
233 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
234 when(dmaapContext.getConfigReader()).thenReturn(configReader);
235 when(dmaapContext.getRequest()).thenReturn(httpServReq);
236 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
238 when(dmaapContext.getResponse()).thenReturn(httpServRes);
240 topicRestService.getAllTopics();
244 public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
245 TopicExistsException, JSONException, ConfigDbException {
247 Assert.assertNotNull(topicRestService);
248 PowerMockito.mockStatic(PropertiesMapBean.class);
251 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
252 .thenReturn("namespace");
254 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
255 when(dmaapContext.getConfigReader()).thenReturn(configReader);
256 when(dmaapContext.getRequest()).thenReturn(httpServReq);
257 when(httpServReq.getHeader("Authorization")).thenReturn(null);
259 when(dmaapContext.getResponse()).thenReturn(httpServRes);
261 topicRestService.getAllTopics();
265 public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
267 Assert.assertNotNull(topicRestService);
268 PowerMockito.mockStatic(PropertiesMapBean.class);
271 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
272 .thenReturn("namespace");
274 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
275 when(dmaapContext.getConfigReader()).thenReturn(configReader);
276 when(dmaapContext.getRequest()).thenReturn(httpServReq);
277 when(httpServReq.getHeader("Authorization")).thenReturn(null);
279 when(dmaapContext.getResponse()).thenReturn(httpServRes);
282 PowerMockito.doThrow(new IOException()).when(topicService).getAllTopics(any());
283 } catch (JSONException | ConfigDbException | IOException excp) {
288 topicRestService.getAllTopics();
289 } catch (CambriaApiException excp) {
294 @Test(expected = DMaaPAccessDeniedException.class)
295 public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
296 TopicExistsException, JSONException, ConfigDbException {
298 Assert.assertNotNull(topicRestService);
300 PowerMockito.mockStatic(PropertiesMapBean.class);
303 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
304 .thenReturn("enfTopicName");
306 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
307 when(dmaapContext.getConfigReader()).thenReturn(configReader);
308 when(dmaapContext.getRequest()).thenReturn(httpServReq);
309 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
311 when(dmaapContext.getResponse()).thenReturn(httpServRes);
313 topicRestService.getTopic("topicName");
317 public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
318 TopicExistsException, JSONException, ConfigDbException {
320 Assert.assertNotNull(topicRestService);
322 PowerMockito.mockStatic(PropertiesMapBean.class);
325 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
326 .thenReturn("enfTopicName");
328 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
329 when(dmaapContext.getConfigReader()).thenReturn(configReader);
330 when(dmaapContext.getRequest()).thenReturn(httpServReq);
331 when(httpServReq.getHeader("Authorization")).thenReturn(null);
333 when(dmaapContext.getResponse()).thenReturn(httpServRes);
335 topicRestService.getTopic("topicName");
339 public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
341 Assert.assertNotNull(topicRestService);
343 PowerMockito.mockStatic(PropertiesMapBean.class);
346 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
347 .thenReturn("enfTopicName");
349 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
350 when(dmaapContext.getConfigReader()).thenReturn(configReader);
351 when(dmaapContext.getRequest()).thenReturn(httpServReq);
352 when(httpServReq.getHeader("Authorization")).thenReturn(null);
354 when(dmaapContext.getResponse()).thenReturn(httpServRes);
357 PowerMockito.doThrow(new IOException()).when(topicService).getTopic(any(), any());
358 } catch (TopicExistsException | ConfigDbException | IOException excp) {
363 topicRestService.getTopic("topicName");
364 } catch (CambriaApiException excp) {
370 public void testCreateTopic()
371 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
373 Assert.assertNotNull(topicRestService);
375 when(dmaapContext.getRequest()).thenReturn(httpServReq);
376 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
377 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
378 when(dmaapContext.getConfigReader()).thenReturn(configReader);
380 TopicBean topicBean = new TopicBean();
381 topicBean.setTopicName("enfTopicNamePlusExtra");
383 topicRestService.createTopic(topicBean);
387 public void testCreateTopic_error() {
389 Assert.assertNotNull(topicRestService);
391 when(dmaapContext.getRequest()).thenReturn(httpServReq);
392 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
393 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
394 when(dmaapContext.getConfigReader()).thenReturn(configReader);
396 TopicBean topicBean = new TopicBean();
397 topicBean.setTopicName("enfTopicNamePlusExtra");
400 PowerMockito.doThrow(new IOException()).when(topicService).createTopic(any(), any());
401 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
403 } catch (CambriaApiException excp) {
408 topicRestService.createTopic(topicBean);
409 } catch (CambriaApiException excp) {
414 PowerMockito.doThrow(new TopicExistsException("error")).when(topicService).createTopic(any(), any());
415 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
417 } catch (CambriaApiException excp) {
422 topicRestService.createTopic(topicBean);
423 } catch (CambriaApiException excp) {
428 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).createTopic(any(), any());
429 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
431 } catch (CambriaApiException excp) {
436 topicRestService.createTopic(topicBean);
437 } catch (CambriaApiException excp) {
443 public void testDeleteTopic()
444 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
446 Assert.assertNotNull(topicRestService);
448 when(dmaapContext.getRequest()).thenReturn(httpServReq);
449 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
450 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
451 when(dmaapContext.getConfigReader()).thenReturn(configReader);
453 TopicBean topicBean = new TopicBean();
454 topicBean.setTopicName("enfTopicNamePlusExtra");
456 topicRestService.deleteTopic("enfTopicNamePlusExtra");
460 public void testDeleteTopic_error()
461 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
463 Assert.assertNotNull(topicRestService);
465 when(dmaapContext.getRequest()).thenReturn(httpServReq);
466 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
467 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
468 when(dmaapContext.getConfigReader()).thenReturn(configReader);
470 TopicBean topicBean = new TopicBean();
471 topicBean.setTopicName("enfTopicNamePlusExtra");
474 PowerMockito.doThrow(new IOException()).when(topicService).deleteTopic(any(), any());
475 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
476 | DMaaPAccessDeniedException excp) {
481 topicRestService.deleteTopic("enfTopicNamePlusExtra");
482 } catch (CambriaApiException excp) {
487 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).deleteTopic(any(),
489 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
490 | DMaaPAccessDeniedException excp) {
495 topicRestService.deleteTopic("enfTopicNamePlusExtra");
496 } catch (CambriaApiException excp) {
502 public void testGetPublishersByTopicName()
503 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
505 Assert.assertNotNull(topicRestService);
507 when(dmaapContext.getRequest()).thenReturn(httpServReq);
508 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
509 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
510 when(dmaapContext.getConfigReader()).thenReturn(configReader);
512 TopicBean topicBean = new TopicBean();
513 topicBean.setTopicName("enfTopicNamePlusExtra");
515 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
519 public void testGetPublishersByTopicName_error() {
521 Assert.assertNotNull(topicRestService);
523 when(dmaapContext.getRequest()).thenReturn(httpServReq);
524 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
525 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
526 when(dmaapContext.getConfigReader()).thenReturn(configReader);
528 TopicBean topicBean = new TopicBean();
529 topicBean.setTopicName("enfTopicNamePlusExtra");
532 PowerMockito.doThrow(new IOException()).when(topicService).getPublishersByTopicName(any(),
534 } catch (TopicExistsException | ConfigDbException | IOException e) {
539 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
540 } catch (CambriaApiException excp) {
546 public void testPermitPublisherForTopic()
547 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
549 Assert.assertNotNull(topicRestService);
551 when(dmaapContext.getRequest()).thenReturn(httpServReq);
552 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
553 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
554 when(dmaapContext.getConfigReader()).thenReturn(configReader);
556 TopicBean topicBean = new TopicBean();
557 topicBean.setTopicName("enfTopicNamePlusExtra");
559 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
563 public void testPermitPublisherForTopic_error()
564 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
566 Assert.assertNotNull(topicRestService);
568 when(dmaapContext.getRequest()).thenReturn(httpServReq);
569 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
570 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
571 when(dmaapContext.getConfigReader()).thenReturn(configReader);
573 TopicBean topicBean = new TopicBean();
574 topicBean.setTopicName("enfTopicNamePlusExtra");
577 PowerMockito.doThrow(new IOException()).when(topicService).permitPublisherForTopic(any(),
579 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
580 | DMaaPAccessDeniedException excp) {
585 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
586 } catch (CambriaApiException excp) {
591 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).permitPublisherForTopic(any(),
593 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
594 | DMaaPAccessDeniedException excp) {
599 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
600 } catch (CambriaApiException excp) {
606 public void testDenyPublisherForTopic()
607 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
609 Assert.assertNotNull(topicRestService);
611 when(dmaapContext.getRequest()).thenReturn(httpServReq);
612 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
613 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
614 when(dmaapContext.getConfigReader()).thenReturn(configReader);
616 TopicBean topicBean = new TopicBean();
617 topicBean.setTopicName("enfTopicNamePlusExtra");
619 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
623 public void testDenyPublisherForTopic_error()
624 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
626 Assert.assertNotNull(topicRestService);
628 when(dmaapContext.getRequest()).thenReturn(httpServReq);
629 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
630 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
631 when(dmaapContext.getConfigReader()).thenReturn(configReader);
633 TopicBean topicBean = new TopicBean();
634 topicBean.setTopicName("enfTopicNamePlusExtra");
637 PowerMockito.doThrow(new IOException()).when(topicService).denyPublisherForTopic(any(),
639 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
640 | DMaaPAccessDeniedException excp) {
645 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
646 } catch (CambriaApiException excp) {
651 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyPublisherForTopic(any(),
653 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
654 | DMaaPAccessDeniedException excp) {
659 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
660 } catch (CambriaApiException excp) {
667 public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
668 TopicExistsException, AccessDeniedException {
670 Assert.assertNotNull(topicRestService);
672 when(dmaapContext.getRequest()).thenReturn(httpServReq);
673 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
674 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
675 when(dmaapContext.getConfigReader()).thenReturn(configReader);
677 TopicBean topicBean = new TopicBean();
678 topicBean.setTopicName("enfTopicNamePlusExtra");
680 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
684 public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
685 TopicExistsException, AccessDeniedException {
687 Assert.assertNotNull(topicRestService);
689 when(dmaapContext.getRequest()).thenReturn(httpServReq);
690 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
691 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
692 when(dmaapContext.getConfigReader()).thenReturn(configReader);
694 TopicBean topicBean = new TopicBean();
695 topicBean.setTopicName("enfTopicNamePlusExtra");
698 PowerMockito.doThrow(new IOException()).when(topicService).getConsumersByTopicName(any(),
700 } catch (TopicExistsException | ConfigDbException | IOException excp) {
705 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
706 } catch (CambriaApiException excp) {
712 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
713 TopicExistsException, AccessDeniedException {
715 Assert.assertNotNull(topicRestService);
717 when(dmaapContext.getRequest()).thenReturn(httpServReq);
718 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
719 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
720 when(dmaapContext.getConfigReader()).thenReturn(configReader);
722 TopicBean topicBean = new TopicBean();
723 topicBean.setTopicName("enfTopicNamePlusExtra");
725 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
729 public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
730 TopicExistsException, AccessDeniedException {
732 Assert.assertNotNull(topicRestService);
734 when(dmaapContext.getRequest()).thenReturn(httpServReq);
735 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
736 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
737 when(dmaapContext.getConfigReader()).thenReturn(configReader);
739 TopicBean topicBean = new TopicBean();
740 topicBean.setTopicName("enfTopicNamePlusExtra");
743 PowerMockito.doThrow(new IOException()).when(topicService).permitConsumerForTopic(any(),
745 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
746 | DMaaPAccessDeniedException excp) {
751 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
752 } catch (CambriaApiException excp) {
758 public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
759 IOException, TopicExistsException, AccessDeniedException {
761 Assert.assertNotNull(topicRestService);
763 when(dmaapContext.getRequest()).thenReturn(httpServReq);
764 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
765 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
766 when(dmaapContext.getConfigReader()).thenReturn(configReader);
768 TopicBean topicBean = new TopicBean();
769 topicBean.setTopicName("enfTopicNamePlusExtra");
771 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
775 public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
776 TopicExistsException, AccessDeniedException {
778 Assert.assertNotNull(topicRestService);
780 when(dmaapContext.getRequest()).thenReturn(httpServReq);
781 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
782 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
783 when(dmaapContext.getConfigReader()).thenReturn(configReader);
785 TopicBean topicBean = new TopicBean();
786 topicBean.setTopicName("enfTopicNamePlusExtra");
788 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
792 public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
793 TopicExistsException, AccessDeniedException {
795 Assert.assertNotNull(topicRestService);
797 when(dmaapContext.getRequest()).thenReturn(httpServReq);
798 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
799 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
800 when(dmaapContext.getConfigReader()).thenReturn(configReader);
802 TopicBean topicBean = new TopicBean();
803 topicBean.setTopicName("enfTopicNamePlusExtra");
806 PowerMockito.doThrow(new IOException()).when(topicService).denyConsumerForTopic(any(),
808 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
809 | DMaaPAccessDeniedException excp) {
814 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
815 } catch (CambriaApiException excp) {
820 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyConsumerForTopic(any(),
822 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
823 | DMaaPAccessDeniedException excp) {
828 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
829 } catch (CambriaApiException excp) {