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.dmaap.service;
\r
23 import static org.junit.Assert.*;
\r
25 import static org.mockito.Matchers.anyString;
\r
26 import static org.mockito.Mockito.when;
\r
28 import java.io.IOException;
\r
29 import javax.servlet.ServletOutputStream;
\r
30 import javax.servlet.http.HttpServletRequest;
\r
31 import javax.servlet.http.HttpServletResponse;
\r
33 import org.junit.After;
\r
34 import org.json.JSONArray;
\r
35 import org.json.JSONException;
\r
36 import org.json.JSONObject;
\r
37 import org.junit.Assert;
\r
38 import org.junit.Before;
\r
39 import org.junit.Test;
\r
41 import org.junit.runner.RunWith;
\r
42 import org.mockito.InjectMocks;
\r
43 import org.mockito.Mock;
\r
44 import org.mockito.MockitoAnnotations;
\r
45 import org.powermock.api.mockito.PowerMockito;
\r
46 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
47 import org.powermock.modules.junit4.PowerMockRunner;
\r
49 import com.att.ajsc.beans.PropertiesMapBean;
\r
50 import com.att.nsa.cambria.CambriaApiException;
\r
51 import com.att.nsa.cambria.beans.DMaaPContext;
\r
52 import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
\r
53 import com.att.nsa.cambria.beans.TopicBean;
\r
54 import com.att.nsa.cambria.constants.CambriaConstants;
\r
55 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
\r
56 import com.att.nsa.cambria.exception.DMaaPErrorMessages;
\r
57 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
\r
58 import com.att.nsa.cambria.metabroker.Topic;
\r
59 import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
\r
60 import com.att.nsa.cambria.security.DMaaPAuthenticator;
\r
61 import com.att.nsa.cambria.service.TopicService;
\r
62 import com.att.nsa.cambria.utils.ConfigurationReader;
\r
63 import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
\r
64 import com.att.nsa.configs.ConfigDbException;
\r
65 import com.att.nsa.security.NsaAcl;
\r
66 import com.att.nsa.security.NsaApiKey;
\r
67 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
\r
68 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
\r
70 //@RunWith(MockitoJUnitRunner.class)
\r
71 @RunWith(PowerMockRunner.class)
\r
72 @PrepareForTest({ PropertiesMapBean.class })
\r
73 public class TopicRestServiceTest {
\r
76 TopicRestService topicService;
\r
79 private TopicService tService;
\r
81 private TopicRestService service = new TopicRestService();
\r
83 private DMaaPErrorMessages errorMessages;
\r
86 DMaaPContext dmaapContext;
\r
89 ConfigurationReader configReader;
\r
92 ServletOutputStream oStream;
\r
95 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
\r
98 DMaaPAAFAuthenticator dmaapAAFauthenticator;
\r
103 NsaSimpleApiKey nsaSimpleApiKey;
\r
106 HttpServletRequest httpServReq;
\r
109 HttpServletResponse httpServRes;
\r
112 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
\r
115 Topic createdTopic;
\r
121 JSONObject jsonObj;
\r
124 JSONArray jsonArray;
\r
127 public void setUp() throws Exception {
\r
129 MockitoAnnotations.initMocks(this);
\r
133 public void tearDown() throws Exception {
\r
136 @Test(expected = DMaaPAccessDeniedException.class)
\r
137 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
138 TopicExistsException, JSONException, ConfigDbException {
\r
140 Assert.assertNotNull(topicService);
\r
142 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
145 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
146 .thenReturn("namespace");
\r
148 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
149 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
150 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
151 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
\r
153 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
154 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
155 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
157 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
159 topicService.getTopics();
\r
163 public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
164 TopicExistsException, JSONException, ConfigDbException {
\r
166 Assert.assertNotNull(topicService);
\r
168 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
171 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
172 .thenReturn("namespace");
\r
174 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
175 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
176 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
177 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
179 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
180 String perms = "namespace" + "|" + "*" + "|" + "view";
\r
181 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
\r
183 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
185 topicService.getTopics();
\r
189 public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
\r
191 Assert.assertNotNull(topicService);
\r
193 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
196 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
197 .thenReturn("namespace");
\r
199 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
200 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
201 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
202 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
204 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
205 String perms = "namespace" + "|" + "*" + "|" + "view";
\r
206 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
\r
208 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
210 PowerMockito.doThrow(new IOException()).when(tService).getTopics(dmaapContext);
\r
211 } catch (JSONException | ConfigDbException | IOException excp) {
\r
216 topicService.getTopics();
\r
217 } catch (CambriaApiException excp) {
\r
222 @Test(expected = DMaaPAccessDeniedException.class)
\r
223 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
224 TopicExistsException, JSONException, ConfigDbException {
\r
226 Assert.assertNotNull(topicService);
\r
228 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
231 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
232 .thenReturn("namespace");
\r
234 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
235 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
236 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
237 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
\r
239 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
241 topicService.getAllTopics();
\r
245 public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
246 TopicExistsException, JSONException, ConfigDbException {
\r
248 Assert.assertNotNull(topicService);
\r
249 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
252 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
253 .thenReturn("namespace");
\r
255 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
256 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
257 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
258 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
260 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
262 topicService.getAllTopics();
\r
266 public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
\r
268 Assert.assertNotNull(topicService);
\r
269 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
272 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
\r
273 .thenReturn("namespace");
\r
275 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
276 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
277 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
278 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
280 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
283 PowerMockito.doThrow(new IOException()).when(tService).getAllTopics(dmaapContext);
\r
284 } catch (JSONException | ConfigDbException | IOException excp) {
\r
289 topicService.getAllTopics();
\r
290 } catch (CambriaApiException excp) {
\r
295 @Test(expected = DMaaPAccessDeniedException.class)
\r
296 public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
297 TopicExistsException, JSONException, ConfigDbException {
\r
299 Assert.assertNotNull(topicService);
\r
301 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
304 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
305 .thenReturn("enfTopicName");
\r
307 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
308 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
309 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
310 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
\r
312 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
314 topicService.getTopic("topicName");
\r
318 public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
319 TopicExistsException, JSONException, ConfigDbException {
\r
321 Assert.assertNotNull(topicService);
\r
323 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
326 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
327 .thenReturn("enfTopicName");
\r
329 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
330 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
331 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
332 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
334 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
336 topicService.getTopic("topicName");
\r
340 public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
\r
342 Assert.assertNotNull(topicService);
\r
344 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
347 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
348 .thenReturn("enfTopicName");
\r
350 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
351 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
352 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
353 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
355 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
358 PowerMockito.doThrow(new IOException()).when(tService).getTopic(dmaapContext, "topicName");
\r
359 } catch (TopicExistsException | ConfigDbException | IOException excp) {
\r
364 topicService.getTopic("topicName");
\r
365 } catch (CambriaApiException excp) {
\r
371 public void testCreateTopic()
\r
372 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
374 Assert.assertNotNull(topicService);
\r
376 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
377 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
378 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
379 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
381 TopicBean topicBean = new TopicBean();
\r
382 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
384 topicService.createTopic(topicBean);
\r
388 public void testCreateTopic_error() {
\r
390 Assert.assertNotNull(topicService);
\r
392 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
393 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
394 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
395 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
397 TopicBean topicBean = new TopicBean();
\r
398 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
401 PowerMockito.doThrow(new IOException()).when(tService).createTopic(dmaapContext, topicBean);
\r
402 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
\r
404 } catch (CambriaApiException excp) {
\r
409 topicService.createTopic(topicBean);
\r
410 } catch (CambriaApiException excp) {
\r
415 PowerMockito.doThrow(new TopicExistsException("error")).when(tService).createTopic(dmaapContext, topicBean);
\r
416 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
\r
418 } catch (CambriaApiException excp) {
\r
423 topicService.createTopic(topicBean);
\r
424 } catch (CambriaApiException excp) {
\r
429 PowerMockito.doThrow(new AccessDeniedException()).when(tService).createTopic(dmaapContext, topicBean);
\r
430 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
\r
432 } catch (CambriaApiException excp) {
\r
437 topicService.createTopic(topicBean);
\r
438 } catch (CambriaApiException excp) {
\r
444 public void testDeleteTopic()
\r
445 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
447 Assert.assertNotNull(topicService);
\r
449 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
450 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
451 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
452 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
454 TopicBean topicBean = new TopicBean();
\r
455 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
457 topicService.deleteTopic("enfTopicNamePlusExtra");
\r
461 public void testDeleteTopic_error()
\r
462 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
464 Assert.assertNotNull(topicService);
\r
466 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
467 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
468 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
469 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
471 TopicBean topicBean = new TopicBean();
\r
472 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
475 PowerMockito.doThrow(new IOException()).when(tService).deleteTopic(dmaapContext, "enfTopicNamePlusExtra");
\r
476 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
477 | DMaaPAccessDeniedException excp) {
\r
482 topicService.deleteTopic("enfTopicNamePlusExtra");
\r
483 } catch (CambriaApiException excp) {
\r
488 PowerMockito.doThrow(new AccessDeniedException()).when(tService).deleteTopic(dmaapContext,
\r
489 "enfTopicNamePlusExtra");
\r
490 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
491 | DMaaPAccessDeniedException excp) {
\r
496 topicService.deleteTopic("enfTopicNamePlusExtra");
\r
497 } catch (CambriaApiException excp) {
\r
503 public void testGetPublishersByTopicName()
\r
504 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
506 Assert.assertNotNull(topicService);
\r
508 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
509 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
510 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
511 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
513 TopicBean topicBean = new TopicBean();
\r
514 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
516 topicService.getPublishersByTopicName("enfTopicNamePlusExtra");
\r
520 public void testGetPublishersByTopicName_error() {
\r
522 Assert.assertNotNull(topicService);
\r
524 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
525 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
526 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
527 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
529 TopicBean topicBean = new TopicBean();
\r
530 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
533 PowerMockito.doThrow(new IOException()).when(tService).getPublishersByTopicName(dmaapContext,
\r
534 "enfTopicNamePlusExtra");
\r
535 } catch (TopicExistsException | ConfigDbException | IOException e) {
\r
540 topicService.getPublishersByTopicName("enfTopicNamePlusExtra");
\r
541 } catch (CambriaApiException excp) {
\r
547 public void testPermitPublisherForTopic()
\r
548 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
550 Assert.assertNotNull(topicService);
\r
552 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
553 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
554 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
555 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
557 TopicBean topicBean = new TopicBean();
\r
558 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
560 topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
564 public void testPermitPublisherForTopic_error()
\r
565 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
567 Assert.assertNotNull(topicService);
\r
569 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
570 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
571 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
572 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
574 TopicBean topicBean = new TopicBean();
\r
575 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
578 PowerMockito.doThrow(new IOException()).when(tService).permitPublisherForTopic(dmaapContext,
\r
579 "enfTopicNamePlusExtra", "producerID");
\r
580 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
581 | DMaaPAccessDeniedException excp) {
\r
586 topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
587 } catch (CambriaApiException excp) {
\r
592 PowerMockito.doThrow(new AccessDeniedException()).when(tService).permitPublisherForTopic(dmaapContext,
\r
593 "enfTopicNamePlusExtra", "producerID");
\r
594 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
595 | DMaaPAccessDeniedException excp) {
\r
600 topicService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
601 } catch (CambriaApiException excp) {
\r
607 public void testDenyPublisherForTopic()
\r
608 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
610 Assert.assertNotNull(topicService);
\r
612 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
613 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
614 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
615 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
617 TopicBean topicBean = new TopicBean();
\r
618 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
620 topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
624 public void testDenyPublisherForTopic_error()
\r
625 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
627 Assert.assertNotNull(topicService);
\r
629 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
630 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
631 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
632 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
634 TopicBean topicBean = new TopicBean();
\r
635 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
638 PowerMockito.doThrow(new IOException()).when(tService).denyPublisherForTopic(dmaapContext,
\r
639 "enfTopicNamePlusExtra", "producerID");
\r
640 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
641 | DMaaPAccessDeniedException excp) {
\r
646 topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
647 } catch (CambriaApiException excp) {
\r
652 PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyPublisherForTopic(dmaapContext,
\r
653 "enfTopicNamePlusExtra", "producerID");
\r
654 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
655 | DMaaPAccessDeniedException excp) {
\r
660 topicService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
\r
661 } catch (CambriaApiException excp) {
\r
668 public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
669 TopicExistsException, AccessDeniedException {
\r
671 Assert.assertNotNull(topicService);
\r
673 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
674 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
675 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
676 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
678 TopicBean topicBean = new TopicBean();
\r
679 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
681 topicService.getConsumersByTopicName("enfTopicNamePlusExtra");
\r
685 public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
686 TopicExistsException, AccessDeniedException {
\r
688 Assert.assertNotNull(topicService);
\r
690 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
691 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
692 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
693 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
695 TopicBean topicBean = new TopicBean();
\r
696 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
699 PowerMockito.doThrow(new IOException()).when(tService).getConsumersByTopicName(dmaapContext,
\r
700 "enfTopicNamePlusExtra");
\r
701 } catch (TopicExistsException | ConfigDbException | IOException excp) {
\r
706 topicService.getConsumersByTopicName("enfTopicNamePlusExtra");
\r
707 } catch (CambriaApiException excp) {
\r
713 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
714 TopicExistsException, AccessDeniedException {
\r
716 Assert.assertNotNull(topicService);
\r
718 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
719 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
720 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
721 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
723 TopicBean topicBean = new TopicBean();
\r
724 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
726 topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
730 public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
731 TopicExistsException, AccessDeniedException {
\r
733 Assert.assertNotNull(topicService);
\r
735 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
736 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
737 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
738 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
740 TopicBean topicBean = new TopicBean();
\r
741 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
744 PowerMockito.doThrow(new IOException()).when(tService).permitConsumerForTopic(dmaapContext,
\r
745 "enfTopicNamePlusExtra", "consumerID");
\r
746 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
747 | DMaaPAccessDeniedException excp) {
\r
752 topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
753 } catch (CambriaApiException excp) {
\r
759 public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
\r
760 IOException, TopicExistsException, AccessDeniedException {
\r
762 Assert.assertNotNull(topicService);
\r
764 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
765 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
766 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
767 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
769 TopicBean topicBean = new TopicBean();
\r
770 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
772 topicService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
776 public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
777 TopicExistsException, AccessDeniedException {
\r
779 Assert.assertNotNull(topicService);
\r
781 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
782 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
783 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
784 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
786 TopicBean topicBean = new TopicBean();
\r
787 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
789 topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
793 public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
794 TopicExistsException, AccessDeniedException {
\r
796 Assert.assertNotNull(topicService);
\r
798 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
799 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
800 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
801 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
803 TopicBean topicBean = new TopicBean();
\r
804 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
807 PowerMockito.doThrow(new IOException()).when(tService).denyConsumerForTopic(dmaapContext,
\r
808 "enfTopicNamePlusExtra", "consumerID");
\r
809 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
810 | DMaaPAccessDeniedException excp) {
\r
815 topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
816 } catch (CambriaApiException excp) {
\r
821 PowerMockito.doThrow(new AccessDeniedException()).when(tService).denyConsumerForTopic(dmaapContext,
\r
822 "enfTopicNamePlusExtra", "consumerID");
\r
823 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
\r
824 | DMaaPAccessDeniedException excp) {
\r
829 topicService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
\r
830 } catch (CambriaApiException excp) {
\r