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.PowerMockIgnore;
50 import org.powermock.core.classloader.annotations.PrepareForTest;
51 import org.powermock.modules.junit4.PowerMockRunner;
53 import com.att.ajsc.beans.PropertiesMapBean;
54 import org.onap.dmaap.dmf.mr.CambriaApiException;
55 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
56 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
57 import org.onap.dmaap.dmf.mr.beans.TopicBean;
58 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
59 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
60 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
61 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
62 import org.onap.dmaap.dmf.mr.metabroker.Topic;
63 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
64 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
65 import org.onap.dmaap.dmf.mr.service.TopicService;
66 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
67 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
68 import com.att.nsa.configs.ConfigDbException;
69 import com.att.nsa.security.NsaAcl;
70 import com.att.nsa.security.NsaApiKey;
71 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
72 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
74 //@RunWith(MockitoJUnitRunner.class)
75 @RunWith(PowerMockRunner.class)
76 @PowerMockIgnore("jdk.internal.reflect.*")
77 @PrepareForTest({ PropertiesMapBean.class })
78 public class TopicRestServiceTest {
81 TopicRestService topicRestService;
84 private TopicService topicService;
86 private TopicRestService service = new TopicRestService();
88 private DMaaPErrorMessages errorMessages;
91 DMaaPContext dmaapContext;
94 ConfigurationReader configReader;
97 ServletOutputStream oStream;
100 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
103 DMaaPAAFAuthenticator dmaapAAFauthenticator;
108 NsaSimpleApiKey nsaSimpleApiKey;
111 HttpServletRequest httpServReq;
114 HttpServletResponse httpServRes;
117 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
132 public void setUp() throws Exception {
134 MockitoAnnotations.initMocks(this);
138 public void tearDown() throws Exception {
141 @Test(expected = DMaaPAccessDeniedException.class)
142 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
143 TopicExistsException, JSONException, ConfigDbException {
145 Assert.assertNotNull(topicRestService);
147 PowerMockito.mockStatic(PropertiesMapBean.class);
150 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
151 .thenReturn("namespace");
153 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
154 when(dmaapContext.getConfigReader()).thenReturn(configReader);
155 when(dmaapContext.getRequest()).thenReturn(httpServReq);
156 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
158 when(dmaapContext.getResponse()).thenReturn(httpServRes);
159 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
160 when(httpServReq.getMethod()).thenReturn("HEAD");
162 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
164 topicRestService.getTopics();
168 public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
169 TopicExistsException, JSONException, ConfigDbException {
171 Assert.assertNotNull(topicRestService);
173 PowerMockito.mockStatic(PropertiesMapBean.class);
176 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
177 .thenReturn("namespace");
179 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
180 when(dmaapContext.getConfigReader()).thenReturn(configReader);
181 when(dmaapContext.getRequest()).thenReturn(httpServReq);
182 when(httpServReq.getHeader("Authorization")).thenReturn(null);
184 when(dmaapContext.getResponse()).thenReturn(httpServRes);
185 String perms = "namespace" + "|" + "*" + "|" + "view";
186 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
188 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
190 topicRestService.getTopics();
194 public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
196 Assert.assertNotNull(topicRestService);
198 PowerMockito.mockStatic(PropertiesMapBean.class);
201 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
202 .thenReturn("namespace");
204 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
205 when(dmaapContext.getConfigReader()).thenReturn(configReader);
206 when(dmaapContext.getRequest()).thenReturn(httpServReq);
207 when(httpServReq.getHeader("Authorization")).thenReturn(null);
209 when(dmaapContext.getResponse()).thenReturn(httpServRes);
210 String perms = "namespace" + "|" + "*" + "|" + "view";
211 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
213 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
215 PowerMockito.doThrow(new IOException()).when(topicService).getTopics(any());
216 } catch (JSONException | ConfigDbException | IOException excp) {
221 topicRestService.getTopics();
222 } catch (CambriaApiException excp) {
227 @Test(expected = DMaaPAccessDeniedException.class)
228 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
229 TopicExistsException, JSONException, ConfigDbException {
231 Assert.assertNotNull(topicRestService);
233 PowerMockito.mockStatic(PropertiesMapBean.class);
236 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
237 .thenReturn("namespace");
239 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
240 when(dmaapContext.getConfigReader()).thenReturn(configReader);
241 when(dmaapContext.getRequest()).thenReturn(httpServReq);
242 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
244 when(dmaapContext.getResponse()).thenReturn(httpServRes);
246 topicRestService.getAllTopics();
250 public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
251 TopicExistsException, JSONException, ConfigDbException {
253 Assert.assertNotNull(topicRestService);
254 PowerMockito.mockStatic(PropertiesMapBean.class);
257 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
258 .thenReturn("namespace");
260 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
261 when(dmaapContext.getConfigReader()).thenReturn(configReader);
262 when(dmaapContext.getRequest()).thenReturn(httpServReq);
263 when(httpServReq.getHeader("Authorization")).thenReturn(null);
265 when(dmaapContext.getResponse()).thenReturn(httpServRes);
267 topicRestService.getAllTopics();
271 public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
273 Assert.assertNotNull(topicRestService);
274 PowerMockito.mockStatic(PropertiesMapBean.class);
277 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
278 .thenReturn("namespace");
280 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
281 when(dmaapContext.getConfigReader()).thenReturn(configReader);
282 when(dmaapContext.getRequest()).thenReturn(httpServReq);
283 when(httpServReq.getHeader("Authorization")).thenReturn(null);
285 when(dmaapContext.getResponse()).thenReturn(httpServRes);
288 PowerMockito.doThrow(new IOException()).when(topicService).getAllTopics(any());
289 } catch (JSONException | ConfigDbException | IOException excp) {
294 topicRestService.getAllTopics();
295 } catch (CambriaApiException excp) {
300 @Test(expected = DMaaPAccessDeniedException.class)
301 public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
302 TopicExistsException, JSONException, ConfigDbException {
304 Assert.assertNotNull(topicRestService);
306 PowerMockito.mockStatic(PropertiesMapBean.class);
309 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
310 .thenReturn("enfTopicName");
312 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
313 when(dmaapContext.getConfigReader()).thenReturn(configReader);
314 when(dmaapContext.getRequest()).thenReturn(httpServReq);
315 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
317 when(dmaapContext.getResponse()).thenReturn(httpServRes);
319 topicRestService.getTopic("topicName");
323 public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
324 TopicExistsException, JSONException, ConfigDbException {
326 Assert.assertNotNull(topicRestService);
328 PowerMockito.mockStatic(PropertiesMapBean.class);
331 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
332 .thenReturn("enfTopicName");
334 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
335 when(dmaapContext.getConfigReader()).thenReturn(configReader);
336 when(dmaapContext.getRequest()).thenReturn(httpServReq);
337 when(httpServReq.getHeader("Authorization")).thenReturn(null);
339 when(dmaapContext.getResponse()).thenReturn(httpServRes);
341 topicRestService.getTopic("topicName");
345 public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
347 Assert.assertNotNull(topicRestService);
349 PowerMockito.mockStatic(PropertiesMapBean.class);
352 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
353 .thenReturn("enfTopicName");
355 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
356 when(dmaapContext.getConfigReader()).thenReturn(configReader);
357 when(dmaapContext.getRequest()).thenReturn(httpServReq);
358 when(httpServReq.getHeader("Authorization")).thenReturn(null);
360 when(dmaapContext.getResponse()).thenReturn(httpServRes);
363 PowerMockito.doThrow(new IOException()).when(topicService).getTopic(any(), any());
364 } catch (TopicExistsException | ConfigDbException | IOException excp) {
369 topicRestService.getTopic("topicName");
370 } catch (CambriaApiException excp) {
376 public void testCreateTopic()
377 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
379 Assert.assertNotNull(topicRestService);
381 when(dmaapContext.getRequest()).thenReturn(httpServReq);
382 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
383 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
384 when(dmaapContext.getConfigReader()).thenReturn(configReader);
386 TopicBean topicBean = new TopicBean();
387 topicBean.setTopicName("enfTopicNamePlusExtra");
389 topicRestService.createTopic(topicBean);
393 public void testCreateTopic_error() {
395 Assert.assertNotNull(topicRestService);
397 when(dmaapContext.getRequest()).thenReturn(httpServReq);
398 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
399 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
400 when(dmaapContext.getConfigReader()).thenReturn(configReader);
402 TopicBean topicBean = new TopicBean();
403 topicBean.setTopicName("enfTopicNamePlusExtra");
406 PowerMockito.doThrow(new IOException()).when(topicService).createTopic(any(), any());
407 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
409 } catch (CambriaApiException excp) {
414 topicRestService.createTopic(topicBean);
415 } catch (CambriaApiException excp) {
420 PowerMockito.doThrow(new TopicExistsException("error")).when(topicService).createTopic(any(), any());
421 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
423 } catch (CambriaApiException excp) {
428 topicRestService.createTopic(topicBean);
429 } catch (CambriaApiException excp) {
434 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).createTopic(any(), any());
435 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
437 } catch (CambriaApiException excp) {
442 topicRestService.createTopic(topicBean);
443 } catch (CambriaApiException excp) {
449 public void testDeleteTopic()
450 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
452 Assert.assertNotNull(topicRestService);
454 when(dmaapContext.getRequest()).thenReturn(httpServReq);
455 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
456 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
457 when(dmaapContext.getConfigReader()).thenReturn(configReader);
459 TopicBean topicBean = new TopicBean();
460 topicBean.setTopicName("enfTopicNamePlusExtra");
462 topicRestService.deleteTopic("enfTopicNamePlusExtra");
466 public void testDeleteTopic_error()
467 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
469 Assert.assertNotNull(topicRestService);
471 when(dmaapContext.getRequest()).thenReturn(httpServReq);
472 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
473 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
474 when(dmaapContext.getConfigReader()).thenReturn(configReader);
476 TopicBean topicBean = new TopicBean();
477 topicBean.setTopicName("enfTopicNamePlusExtra");
480 PowerMockito.doThrow(new IOException()).when(topicService).deleteTopic(any(), any());
481 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
482 | DMaaPAccessDeniedException excp) {
487 topicRestService.deleteTopic("enfTopicNamePlusExtra");
488 } catch (CambriaApiException excp) {
493 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).deleteTopic(any(),
495 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
496 | DMaaPAccessDeniedException excp) {
501 topicRestService.deleteTopic("enfTopicNamePlusExtra");
502 } catch (CambriaApiException excp) {
508 public void testGetPublishersByTopicName()
509 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
511 Assert.assertNotNull(topicRestService);
513 when(dmaapContext.getRequest()).thenReturn(httpServReq);
514 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
515 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
516 when(dmaapContext.getConfigReader()).thenReturn(configReader);
518 TopicBean topicBean = new TopicBean();
519 topicBean.setTopicName("enfTopicNamePlusExtra");
521 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
525 public void testGetPublishersByTopicName_error() {
527 Assert.assertNotNull(topicRestService);
529 when(dmaapContext.getRequest()).thenReturn(httpServReq);
530 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
531 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
532 when(dmaapContext.getConfigReader()).thenReturn(configReader);
534 TopicBean topicBean = new TopicBean();
535 topicBean.setTopicName("enfTopicNamePlusExtra");
538 PowerMockito.doThrow(new IOException()).when(topicService).getPublishersByTopicName(any(),
540 } catch (TopicExistsException | ConfigDbException | IOException e) {
545 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
546 } catch (CambriaApiException excp) {
552 public void testPermitPublisherForTopic()
553 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
555 Assert.assertNotNull(topicRestService);
557 when(dmaapContext.getRequest()).thenReturn(httpServReq);
558 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
559 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
560 when(dmaapContext.getConfigReader()).thenReturn(configReader);
562 TopicBean topicBean = new TopicBean();
563 topicBean.setTopicName("enfTopicNamePlusExtra");
565 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
569 public void testPermitPublisherForTopic_error()
570 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
572 Assert.assertNotNull(topicRestService);
574 when(dmaapContext.getRequest()).thenReturn(httpServReq);
575 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
576 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
577 when(dmaapContext.getConfigReader()).thenReturn(configReader);
579 TopicBean topicBean = new TopicBean();
580 topicBean.setTopicName("enfTopicNamePlusExtra");
583 PowerMockito.doThrow(new IOException()).when(topicService).permitPublisherForTopic(any(),
585 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
586 | DMaaPAccessDeniedException excp) {
591 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
592 } catch (CambriaApiException excp) {
597 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).permitPublisherForTopic(any(),
599 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
600 | DMaaPAccessDeniedException excp) {
605 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
606 } catch (CambriaApiException excp) {
612 public void testDenyPublisherForTopic()
613 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
615 Assert.assertNotNull(topicRestService);
617 when(dmaapContext.getRequest()).thenReturn(httpServReq);
618 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
619 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
620 when(dmaapContext.getConfigReader()).thenReturn(configReader);
622 TopicBean topicBean = new TopicBean();
623 topicBean.setTopicName("enfTopicNamePlusExtra");
625 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
629 public void testDenyPublisherForTopic_error()
630 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
632 Assert.assertNotNull(topicRestService);
634 when(dmaapContext.getRequest()).thenReturn(httpServReq);
635 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
636 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
637 when(dmaapContext.getConfigReader()).thenReturn(configReader);
639 TopicBean topicBean = new TopicBean();
640 topicBean.setTopicName("enfTopicNamePlusExtra");
643 PowerMockito.doThrow(new IOException()).when(topicService).denyPublisherForTopic(any(),
645 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
646 | DMaaPAccessDeniedException excp) {
651 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
652 } catch (CambriaApiException excp) {
657 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyPublisherForTopic(any(),
659 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
660 | DMaaPAccessDeniedException excp) {
665 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
666 } catch (CambriaApiException excp) {
673 public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
674 TopicExistsException, AccessDeniedException {
676 Assert.assertNotNull(topicRestService);
678 when(dmaapContext.getRequest()).thenReturn(httpServReq);
679 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
680 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
681 when(dmaapContext.getConfigReader()).thenReturn(configReader);
683 TopicBean topicBean = new TopicBean();
684 topicBean.setTopicName("enfTopicNamePlusExtra");
686 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
690 public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
691 TopicExistsException, AccessDeniedException {
693 Assert.assertNotNull(topicRestService);
695 when(dmaapContext.getRequest()).thenReturn(httpServReq);
696 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
697 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
698 when(dmaapContext.getConfigReader()).thenReturn(configReader);
700 TopicBean topicBean = new TopicBean();
701 topicBean.setTopicName("enfTopicNamePlusExtra");
704 PowerMockito.doThrow(new IOException()).when(topicService).getConsumersByTopicName(any(),
706 } catch (TopicExistsException | ConfigDbException | IOException excp) {
711 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
712 } catch (CambriaApiException excp) {
718 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
719 TopicExistsException, AccessDeniedException {
721 Assert.assertNotNull(topicRestService);
723 when(dmaapContext.getRequest()).thenReturn(httpServReq);
724 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
725 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
726 when(dmaapContext.getConfigReader()).thenReturn(configReader);
728 TopicBean topicBean = new TopicBean();
729 topicBean.setTopicName("enfTopicNamePlusExtra");
731 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
735 public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
736 TopicExistsException, AccessDeniedException {
738 Assert.assertNotNull(topicRestService);
740 when(dmaapContext.getRequest()).thenReturn(httpServReq);
741 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
742 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
743 when(dmaapContext.getConfigReader()).thenReturn(configReader);
745 TopicBean topicBean = new TopicBean();
746 topicBean.setTopicName("enfTopicNamePlusExtra");
749 PowerMockito.doThrow(new IOException()).when(topicService).permitConsumerForTopic(any(),
751 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
752 | DMaaPAccessDeniedException excp) {
757 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
758 } catch (CambriaApiException excp) {
764 public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
765 IOException, TopicExistsException, AccessDeniedException {
767 Assert.assertNotNull(topicRestService);
769 when(dmaapContext.getRequest()).thenReturn(httpServReq);
770 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
771 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
772 when(dmaapContext.getConfigReader()).thenReturn(configReader);
774 TopicBean topicBean = new TopicBean();
775 topicBean.setTopicName("enfTopicNamePlusExtra");
777 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
781 public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
782 TopicExistsException, AccessDeniedException {
784 Assert.assertNotNull(topicRestService);
786 when(dmaapContext.getRequest()).thenReturn(httpServReq);
787 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
788 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
789 when(dmaapContext.getConfigReader()).thenReturn(configReader);
791 TopicBean topicBean = new TopicBean();
792 topicBean.setTopicName("enfTopicNamePlusExtra");
794 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
798 public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
799 TopicExistsException, AccessDeniedException {
801 Assert.assertNotNull(topicRestService);
803 when(dmaapContext.getRequest()).thenReturn(httpServReq);
804 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
805 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
806 when(dmaapContext.getConfigReader()).thenReturn(configReader);
808 TopicBean topicBean = new TopicBean();
809 topicBean.setTopicName("enfTopicNamePlusExtra");
812 PowerMockito.doThrow(new IOException()).when(topicService).denyConsumerForTopic(any(),
814 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
815 | DMaaPAccessDeniedException excp) {
820 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
821 } catch (CambriaApiException excp) {
826 PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyConsumerForTopic(any(),
828 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
829 | DMaaPAccessDeniedException excp) {
834 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
835 } catch (CambriaApiException excp) {