0c563b4c5614b8c2bd8d8e5528cd93eb1a093248
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / service / TopicRestServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21  package org.onap.dmaap.service;
22
23 import static org.junit.Assert.*;
24
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Mockito.when;
28
29 import java.io.IOException;
30 import java.util.ConcurrentModificationException;
31
32 import javax.servlet.ServletOutputStream;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35
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;
43
44 import org.junit.runner.RunWith;
45 import org.mockito.InjectMocks;
46 import org.mockito.Mock;
47 import org.mockito.MockitoAnnotations;
48 import org.powermock.api.mockito.PowerMockito;
49 import org.powermock.core.classloader.annotations.PrepareForTest;
50 import org.powermock.modules.junit4.PowerMockRunner;
51
52 import com.att.ajsc.beans.PropertiesMapBean;
53 import org.onap.dmaap.dmf.mr.CambriaApiException;
54 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
55 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
56 import org.onap.dmaap.dmf.mr.beans.TopicBean;
57 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
58 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
59 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
60 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
61 import org.onap.dmaap.dmf.mr.metabroker.Topic;
62 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
63 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
64 import org.onap.dmaap.dmf.mr.service.TopicService;
65 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
66 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
67 import com.att.nsa.configs.ConfigDbException;
68 import com.att.nsa.security.NsaAcl;
69 import com.att.nsa.security.NsaApiKey;
70 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
71 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
72
73 //@RunWith(MockitoJUnitRunner.class)
74 @RunWith(PowerMockRunner.class)
75 @PrepareForTest({ PropertiesMapBean.class })
76 public class TopicRestServiceTest {
77
78         @InjectMocks
79         TopicRestService topicRestService;
80
81         @Mock
82         private TopicService topicService;
83
84         private TopicRestService service = new TopicRestService();
85         @Mock
86         private DMaaPErrorMessages errorMessages;
87
88         @Mock
89         DMaaPContext dmaapContext;
90
91         @Mock
92         ConfigurationReader configReader;
93
94         @Mock
95         ServletOutputStream oStream;
96
97         @Mock
98         DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
99
100         @Mock
101         DMaaPAAFAuthenticator dmaapAAFauthenticator;
102         @Mock
103         NsaApiKey user;
104
105         @Mock
106         NsaSimpleApiKey nsaSimpleApiKey;
107
108         @Mock
109         HttpServletRequest httpServReq;
110
111         @Mock
112         HttpServletResponse httpServRes;
113
114         @Mock
115         DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
116
117         @Mock
118         Topic createdTopic;
119
120         @Mock
121         NsaAcl nsaAcl;
122
123         @Mock
124         JSONObject jsonObj;
125
126         @Mock
127         JSONArray jsonArray;
128
129         @Before
130         public void setUp() throws Exception {
131
132                 MockitoAnnotations.initMocks(this);
133         }
134
135         @After
136         public void tearDown() throws Exception {
137         }
138
139         @Test(expected = DMaaPAccessDeniedException.class)
140         public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
141                         TopicExistsException, JSONException, ConfigDbException {
142
143                 Assert.assertNotNull(topicRestService);
144
145                 PowerMockito.mockStatic(PropertiesMapBean.class);
146
147                 assertTrue(true);
148                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
149                                 .thenReturn("namespace");
150
151                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
152                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
153                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
154                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
155
156                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
157                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
158                 when(httpServReq.getMethod()).thenReturn("HEAD");
159
160                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
161
162                 topicRestService.getTopics();
163         }
164
165         @Test
166         public void testGetTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
167                         TopicExistsException, JSONException, ConfigDbException {
168
169                 Assert.assertNotNull(topicRestService);
170
171                 PowerMockito.mockStatic(PropertiesMapBean.class);
172
173                 assertTrue(true);
174                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
175                                 .thenReturn("namespace");
176
177                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
178                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
179                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
180                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
181
182                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
183                 String perms = "namespace" + "|" + "*" + "|" + "view";
184                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
185
186                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
187
188                 topicRestService.getTopics();
189         }
190
191         @Test
192         public void testGetTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
193
194                 Assert.assertNotNull(topicRestService);
195
196                 PowerMockito.mockStatic(PropertiesMapBean.class);
197
198                 assertTrue(true);
199                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
200                                 .thenReturn("namespace");
201
202                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
203                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
204                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
205                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
206
207                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
208                 String perms = "namespace" + "|" + "*" + "|" + "view";
209                 when(dmaapAAFauthenticator.aafAuthentication(httpServReq, perms)).thenReturn(true);
210
211                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
212                 try {
213                         PowerMockito.doThrow(new IOException()).when(topicService).getTopics(any());
214                 } catch (JSONException | ConfigDbException | IOException excp) {
215                         assertTrue(false);
216                 }
217
218                 try {
219                         topicRestService.getTopics();
220                 } catch (CambriaApiException excp) {
221                         assertTrue(true);
222                 }
223         }
224
225         @Test(expected = DMaaPAccessDeniedException.class)
226         public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
227                         TopicExistsException, JSONException, ConfigDbException {
228
229                 Assert.assertNotNull(topicRestService);
230
231                 PowerMockito.mockStatic(PropertiesMapBean.class);
232
233                 assertTrue(true);
234                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
235                                 .thenReturn("namespace");
236
237                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
238                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
239                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
240                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
241
242                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
243
244                 topicRestService.getAllTopics();
245         }
246
247         @Test
248         public void testGetAllTopics_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
249                         TopicExistsException, JSONException, ConfigDbException {
250
251                 Assert.assertNotNull(topicRestService);
252                 PowerMockito.mockStatic(PropertiesMapBean.class);
253
254                 assertTrue(true);
255                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
256                                 .thenReturn("namespace");
257
258                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
259                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
260                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
261                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
262
263                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
264
265                 topicRestService.getAllTopics();
266         }
267
268         @Test
269         public void testGetAllTopics_error() throws DMaaPAccessDeniedException, TopicExistsException, ConfigDbException {
270
271                 Assert.assertNotNull(topicRestService);
272                 PowerMockito.mockStatic(PropertiesMapBean.class);
273
274                 assertTrue(true);
275                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.namespace.aaf"))
276                                 .thenReturn("namespace");
277
278                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
279                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
280                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
281                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
282
283                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
284
285                 try {
286                         PowerMockito.doThrow(new IOException()).when(topicService).getAllTopics(any());
287                 } catch (JSONException | ConfigDbException | IOException excp) {
288                         assertTrue(false);
289                 }
290
291                 try {
292                         topicRestService.getAllTopics();
293                 } catch (CambriaApiException excp) {
294                         assertTrue(true);
295                 }
296         }
297
298         @Test(expected = DMaaPAccessDeniedException.class)
299         public void testGetTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
300                         TopicExistsException, JSONException, ConfigDbException {
301
302                 Assert.assertNotNull(topicRestService);
303
304                 PowerMockito.mockStatic(PropertiesMapBean.class);
305
306                 assertTrue(true);
307                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
308                                 .thenReturn("enfTopicName");
309
310                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
311                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
312                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
313                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
314
315                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
316
317                 topicRestService.getTopic("topicName");
318         }
319
320         @Test
321         public void testGetTopic_nullAuth() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
322                         TopicExistsException, JSONException, ConfigDbException {
323
324                 Assert.assertNotNull(topicRestService);
325
326                 PowerMockito.mockStatic(PropertiesMapBean.class);
327
328                 assertTrue(true);
329                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
330                                 .thenReturn("enfTopicName");
331
332                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
333                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
334                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
335                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
336
337                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
338
339                 topicRestService.getTopic("topicName");
340         }
341
342         @Test
343         public void testGetTopic_error() throws DMaaPAccessDeniedException, ConfigDbException {
344
345                 Assert.assertNotNull(topicRestService);
346
347                 PowerMockito.mockStatic(PropertiesMapBean.class);
348
349                 assertTrue(true);
350                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
351                                 .thenReturn("enfTopicName");
352
353                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
354                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
355                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
356                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
357
358                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
359
360                 try {
361                         PowerMockito.doThrow(new IOException()).when(topicService).getTopic(any(), any());
362                 } catch (TopicExistsException | ConfigDbException | IOException excp) {
363                         assertTrue(false);
364                 }
365
366                 try {
367                         topicRestService.getTopic("topicName");
368                 } catch (CambriaApiException excp) {
369                         assertTrue(true);
370                 }
371         }
372
373         @Test
374         public void testCreateTopic()
375                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
376
377                 Assert.assertNotNull(topicRestService);
378
379                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
380                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
381                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
382                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
383
384                 TopicBean topicBean = new TopicBean();
385                 topicBean.setTopicName("enfTopicNamePlusExtra");
386
387                 topicRestService.createTopic(topicBean);
388         }
389
390         @Test
391         public void testCreateTopic_error() {
392
393                 Assert.assertNotNull(topicRestService);
394
395                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
396                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
397                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
398                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
399
400                 TopicBean topicBean = new TopicBean();
401                 topicBean.setTopicName("enfTopicNamePlusExtra");
402
403                 try {
404                         PowerMockito.doThrow(new IOException()).when(topicService).createTopic(any(), any());
405                 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
406                         assertTrue(false);
407                 } catch (CambriaApiException excp) {
408                         assertTrue(false);
409                 }
410
411                 try {
412                         topicRestService.createTopic(topicBean);
413                 } catch (CambriaApiException excp) {
414                         assertTrue(true);
415                 }
416
417                 try {
418                         PowerMockito.doThrow(new TopicExistsException("error")).when(topicService).createTopic(any(), any());
419                 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
420                         assertTrue(false);
421                 } catch (CambriaApiException excp) {
422                         assertTrue(false);
423                 }
424
425                 try {
426                         topicRestService.createTopic(topicBean);
427                 } catch (CambriaApiException excp) {
428                         assertTrue(true);
429                 }
430
431                 try {
432                         PowerMockito.doThrow(new AccessDeniedException()).when(topicService).createTopic(any(), any());
433                 } catch (TopicExistsException | IOException | AccessDeniedException | DMaaPAccessDeniedException excp) {
434                         assertTrue(false);
435                 } catch (CambriaApiException excp) {
436                         assertTrue(false);
437                 }
438
439                 try {
440                         topicRestService.createTopic(topicBean);
441                 } catch (CambriaApiException excp) {
442                         assertTrue(true);
443                 }
444         }
445
446         @Test
447         public void testDeleteTopic()
448                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
449
450                 Assert.assertNotNull(topicRestService);
451
452                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
453                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
454                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
455                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
456
457                 TopicBean topicBean = new TopicBean();
458                 topicBean.setTopicName("enfTopicNamePlusExtra");
459
460                 topicRestService.deleteTopic("enfTopicNamePlusExtra");
461         }
462
463         @Test
464         public void testDeleteTopic_error()
465                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
466
467                 Assert.assertNotNull(topicRestService);
468
469                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
470                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
471                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
472                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
473
474                 TopicBean topicBean = new TopicBean();
475                 topicBean.setTopicName("enfTopicNamePlusExtra");
476
477                 try {
478                         PowerMockito.doThrow(new IOException()).when(topicService).deleteTopic(any(), any());
479                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
480                                 | DMaaPAccessDeniedException excp) {
481                         assertTrue(false);
482                 }
483
484                 try {
485                         topicRestService.deleteTopic("enfTopicNamePlusExtra");
486                 } catch (CambriaApiException excp) {
487                         assertTrue(true);
488                 }
489
490                 try {
491                         PowerMockito.doThrow(new AccessDeniedException()).when(topicService).deleteTopic(any(),
492                                         any());
493                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
494                                 | DMaaPAccessDeniedException excp) {
495                         assertTrue(false);
496                 }
497
498                 try {
499                         topicRestService.deleteTopic("enfTopicNamePlusExtra");
500                 } catch (CambriaApiException excp) {
501                         assertTrue(true);
502                 }
503         }
504
505         @Test
506         public void testGetPublishersByTopicName()
507                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
508
509                 Assert.assertNotNull(topicRestService);
510
511                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
512                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
513                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
514                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
515
516                 TopicBean topicBean = new TopicBean();
517                 topicBean.setTopicName("enfTopicNamePlusExtra");
518
519                 topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
520         }
521
522         @Test
523         public void testGetPublishersByTopicName_error() {
524
525                 Assert.assertNotNull(topicRestService);
526
527                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
528                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
529                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
530                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
531
532                 TopicBean topicBean = new TopicBean();
533                 topicBean.setTopicName("enfTopicNamePlusExtra");
534
535                 try {
536                         PowerMockito.doThrow(new IOException()).when(topicService).getPublishersByTopicName(any(),
537                                         any());
538                 } catch (TopicExistsException | ConfigDbException | IOException e) {
539                         assertTrue(false);
540                 }
541
542                 try {
543                         topicRestService.getPublishersByTopicName("enfTopicNamePlusExtra");
544                 } catch (CambriaApiException excp) {
545                         assertTrue(true);
546                 }
547         }
548
549         @Test
550         public void testPermitPublisherForTopic()
551                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
552
553                 Assert.assertNotNull(topicRestService);
554
555                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
556                 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
557                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
558                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
559
560                 TopicBean topicBean = new TopicBean();
561                 topicBean.setTopicName("enfTopicNamePlusExtra");
562
563                 topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
564         }
565
566         @Test
567         public void testPermitPublisherForTopic_error()
568                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
569
570                 Assert.assertNotNull(topicRestService);
571
572                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
573                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
574                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
575                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
576
577                 TopicBean topicBean = new TopicBean();
578                 topicBean.setTopicName("enfTopicNamePlusExtra");
579
580                 try {
581                         PowerMockito.doThrow(new IOException()).when(topicService).permitPublisherForTopic(any(),
582                                         any(), any());
583                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
584                                 | DMaaPAccessDeniedException excp) {
585                         assertTrue(false);
586                 }
587
588                 try {
589                         topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
590                 } catch (CambriaApiException excp) {
591                         assertTrue(true);
592                 }
593
594                 try {
595                         PowerMockito.doThrow(new AccessDeniedException()).when(topicService).permitPublisherForTopic(any(),
596                                         any(), any());
597                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
598                                 | DMaaPAccessDeniedException excp) {
599                         assertTrue(false);
600                 }
601
602                 try {
603                         topicRestService.permitPublisherForTopic("enfTopicNamePlusExtra", "producerID");
604                 } catch (CambriaApiException excp) {
605                         assertTrue(true);
606                 }
607         }
608
609         @Test
610         public void testDenyPublisherForTopic()
611                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
612
613                 Assert.assertNotNull(topicRestService);
614
615                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
616                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
617                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
618                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
619
620                 TopicBean topicBean = new TopicBean();
621                 topicBean.setTopicName("enfTopicNamePlusExtra");
622
623                 topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
624         }
625
626         @Test
627         public void testDenyPublisherForTopic_error()
628                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
629
630                 Assert.assertNotNull(topicRestService);
631
632                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
633                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
634                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
635                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
636
637                 TopicBean topicBean = new TopicBean();
638                 topicBean.setTopicName("enfTopicNamePlusExtra");
639
640                 try {
641                         PowerMockito.doThrow(new IOException()).when(topicService).denyPublisherForTopic(any(),
642                                         any(), any());
643                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
644                                 | DMaaPAccessDeniedException excp) {
645                         assertTrue(false);
646                 }
647
648                 try {
649                         topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
650                 } catch (CambriaApiException excp) {
651                         assertTrue(true);
652                 }
653
654                 try {
655                         PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyPublisherForTopic(any(),
656                                         any(), any());
657                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
658                                 | DMaaPAccessDeniedException excp) {
659                         assertTrue(false);
660                 }
661
662                 try {
663                         topicRestService.denyPublisherForTopic("enfTopicNamePlusExtra", "producerID");
664                 } catch (CambriaApiException excp) {
665                         assertTrue(true);
666                 }
667
668         }
669
670         @Test
671         public void testGetConsumersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
672                         TopicExistsException, AccessDeniedException {
673
674                 Assert.assertNotNull(topicRestService);
675
676                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
677                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
678                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
679                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
680
681                 TopicBean topicBean = new TopicBean();
682                 topicBean.setTopicName("enfTopicNamePlusExtra");
683
684                 topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
685         }
686
687         @Test
688         public void testGetConsumersByTopicName_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
689                         TopicExistsException, AccessDeniedException {
690
691                 Assert.assertNotNull(topicRestService);
692
693                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
694                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
695                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
696                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
697
698                 TopicBean topicBean = new TopicBean();
699                 topicBean.setTopicName("enfTopicNamePlusExtra");
700
701                 try {
702                         PowerMockito.doThrow(new IOException()).when(topicService).getConsumersByTopicName(any(),
703                                         any());
704                 } catch (TopicExistsException | ConfigDbException | IOException excp) {
705                         assertTrue(false);
706                 }
707
708                 try {
709                         topicRestService.getConsumersByTopicName("enfTopicNamePlusExtra");
710                 } catch (CambriaApiException excp) {
711                         assertTrue(true);
712                 }
713         }
714
715         @Test
716         public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
717                         TopicExistsException, AccessDeniedException {
718
719                 Assert.assertNotNull(topicRestService);
720
721                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
722                 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
723                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
724                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
725
726                 TopicBean topicBean = new TopicBean();
727                 topicBean.setTopicName("enfTopicNamePlusExtra");
728
729                 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
730         }
731
732         @Test
733         public void testPermitConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
734                         TopicExistsException, AccessDeniedException {
735
736                 Assert.assertNotNull(topicRestService);
737
738                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
739                 when(dmaaPAuthenticator.authenticate(any())).thenReturn(nsaSimpleApiKey);
740                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
741                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
742
743                 TopicBean topicBean = new TopicBean();
744                 topicBean.setTopicName("enfTopicNamePlusExtra");
745
746                 try {
747                         PowerMockito.doThrow(new IOException()).when(topicService).permitConsumerForTopic(any(),
748                                         any(), any());
749                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
750                                 | DMaaPAccessDeniedException excp) {
751                         assertTrue(false);
752                 }
753
754                 try {
755                         topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
756                 } catch (CambriaApiException excp) {
757                         assertTrue(true);
758                 }
759         }
760
761         @Test
762         public void testPermitConsumerForTopicWithException() throws DMaaPAccessDeniedException, CambriaApiException,
763                         IOException, TopicExistsException, AccessDeniedException {
764
765                 Assert.assertNotNull(topicRestService);
766
767                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
768                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
769                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
770                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
771
772                 TopicBean topicBean = new TopicBean();
773                 topicBean.setTopicName("enfTopicNamePlusExtra");
774
775                 topicRestService.permitConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
776         }
777
778         @Test
779         public void testDenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
780                         TopicExistsException, AccessDeniedException {
781
782                 Assert.assertNotNull(topicRestService);
783
784                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
785                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
786                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
787                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
788
789                 TopicBean topicBean = new TopicBean();
790                 topicBean.setTopicName("enfTopicNamePlusExtra");
791
792                 topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
793         }
794
795         @Test
796         public void testDenyConsumerForTopic_error() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
797                         TopicExistsException, AccessDeniedException {
798
799                 Assert.assertNotNull(topicRestService);
800
801                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
802                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
803                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
804                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
805
806                 TopicBean topicBean = new TopicBean();
807                 topicBean.setTopicName("enfTopicNamePlusExtra");
808
809                 try {
810                         PowerMockito.doThrow(new IOException()).when(topicService).denyConsumerForTopic(any(),
811                                         any(), any());
812                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
813                                 | DMaaPAccessDeniedException excp) {
814                         assertTrue(false);
815                 }
816
817                 try {
818                         topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
819                 } catch (CambriaApiException excp) {
820                         assertTrue(true);
821                 }
822
823                 try {
824                         PowerMockito.doThrow(new AccessDeniedException()).when(topicService).denyConsumerForTopic(any(),
825                                         any(), any());
826                 } catch (TopicExistsException | ConfigDbException | IOException | AccessDeniedException
827                                 | DMaaPAccessDeniedException excp) {
828                         assertTrue(false);
829                 }
830
831                 try {
832                         topicRestService.denyConsumerForTopic("enfTopicNamePlusExtra", "consumerID");
833                 } catch (CambriaApiException excp) {
834                         assertTrue(true);
835                 }
836         }
837
838 }