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