4424aa92ff8d053dcd1115df7e835152616a8034
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / dmf / mr / service / impl / TopicServiceImplTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * org.onap.dmaap
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2019 Nokia Intellectual Property. All rights reserved.
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.dmaap.dmf.mr.service.impl;
24
25 import static org.junit.Assert.assertEquals;
26 import static org.mockito.Matchers.any;
27 import static org.mockito.Matchers.anyBoolean;
28 import static org.mockito.Matchers.anyInt;
29 import static org.mockito.Matchers.anyString;
30 import static org.mockito.Matchers.contains;
31 import static org.mockito.Matchers.eq;
32 import static org.mockito.Mockito.doNothing;
33 import static org.mockito.Mockito.doReturn;
34 import static org.mockito.Mockito.never;
35 import static org.mockito.Mockito.verify;
36 import static org.mockito.Mockito.verifyZeroInteractions;
37 import static org.mockito.Mockito.when;
38
39 import com.att.nsa.configs.ConfigDbException;
40 import com.att.nsa.security.NsaAcl;
41 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
42 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
43 import java.io.IOException;
44 import java.nio.file.attribute.UserPrincipal;
45 import java.security.Principal;
46 import java.util.Arrays;
47 import java.util.HashSet;
48 import javax.servlet.ServletOutputStream;
49 import javax.servlet.http.HttpServletRequest;
50 import javax.servlet.http.HttpServletResponse;
51 import org.json.JSONException;
52 import org.json.JSONObject;
53 import org.junit.Assert;
54 import org.junit.Before;
55 import org.junit.Rule;
56 import org.junit.Test;
57 import org.junit.rules.ExpectedException;
58 import org.junit.runner.RunWith;
59 import org.mockito.Mock;
60 import org.mockito.Spy;
61 import org.mockito.runners.MockitoJUnitRunner;
62 import org.onap.dmaap.dmf.mr.CambriaApiException;
63 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
64 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
65 import org.onap.dmaap.dmf.mr.beans.TopicBean;
66 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
67 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
68 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
69 import org.onap.dmaap.dmf.mr.metabroker.Broker1;
70 import org.onap.dmaap.dmf.mr.metabroker.Topic;
71 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
72 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
73
74
75 @RunWith(MockitoJUnitRunner.class)
76 public class TopicServiceImplTest {
77
78     private static final String TOPIC_CREATE_PEM = "org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:org.onap.dmaap.mr|create";
79     private static final String TOPIC_DELETE_PEM = "org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:org.onap.dmaap.mr|destroy";
80     private NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
81     private TopicBean topicBean;
82
83     @Spy
84     private TopicServiceImpl topicService;
85
86     @Mock
87     private DMaaPErrorMessages errorMessages;
88
89     @Mock
90     private DMaaPContext dmaapContext;
91
92     @Mock
93     private ConfigurationReader configReader;
94
95     @Mock
96     private ServletOutputStream oStream;
97
98     @Mock
99     private DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
100
101     @Mock
102     private HttpServletRequest httpServReq;
103
104     @Mock
105     private HttpServletResponse httpServRes;
106
107     @Mock
108     private DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
109
110     @Mock
111     private Topic createdTopic;
112
113     @Mock
114     private NsaAcl nsaAcl;
115
116     @Rule
117     public ExpectedException thrown = ExpectedException.none();
118
119     @Before
120     public void setUp() throws Exception {
121         configureSpyInstance();
122         topicService.setErrorMessages(errorMessages);
123
124         when(dmaapContext.getRequest()).thenReturn(httpServReq);
125     }
126
127     private void configureSpyInstance() throws Exception {
128         doReturn(user).when(topicService).getDmaapAuthenticatedUser(any(DMaaPContext.class));
129         doReturn(dmaapKafkaMetaBroker).when(topicService).getMetaBroker(any(DMaaPContext.class));
130         doNothing().when(topicService).respondOk(any(DMaaPContext.class),anyString());
131         doNothing().when(topicService).respondOk(any(DMaaPContext.class),any(JSONObject.class));
132         when(topicService.getPropertyFromAJSCbean("enforced.topic.name.AAF"))
133                 .thenReturn("org.onap.dmaap.mr");
134         when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf"))
135                 .thenReturn("org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:");
136     }
137
138     private void givenTopicBean(String topicName) {
139         topicBean = new TopicBean();
140         topicBean.setTopicName(topicName);
141     }
142
143
144     @Test
145     public void createTopic_shouldSkipAAFAuthorization_whenCadiIsEnabled_andTopicNameNotEnforced() throws Exception {
146         //given
147         String topicName = "UNAUTHENTICATED.PRH.REGISTRATION";
148
149         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
150                 .thenReturn(createdTopic);
151
152         givenTopicBean(topicName);
153
154         //when
155         topicService.createTopic(dmaapContext, topicBean);
156
157         //then
158         verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
159                 anyBoolean());
160         verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
161         verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
162     }
163
164     @Test
165     public void createTopic_shouldSkipAAFAuthorization_whenCADIdisabled() throws Exception {
166         //given
167         String topicName = "org.onap.dmaap.mr.topic-2";
168         givenTopicBean(topicName);
169
170         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
171                 .thenReturn(createdTopic);
172
173         //when
174         topicService.createTopic(dmaapContext, topicBean);
175
176         //then
177         verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
178                 anyBoolean());
179         verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
180         verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
181     }
182
183     @Test
184     public void createTopic_shouldPass_whenCADIisDisabled_andNoUserInDmaapContext() throws Exception {
185         //given
186         String topicName = "org.onap.dmaap.mr.topic-3";
187         givenTopicBean(topicName);
188
189         doReturn(null).when(topicService).getDmaapAuthenticatedUser(dmaapContext);
190         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
191                 .thenReturn(createdTopic);
192
193         //when
194         topicService.createTopic(dmaapContext, topicBean);
195
196         //then
197         verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
198                 anyBoolean());
199         verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
200     }
201
202     @Test
203     public void createTopic_shouldPassWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
204         //given
205         String topicName = "org.onap.dmaap.mr.topic-4";
206         givenTopicBean(topicName);
207
208         Principal user = new UserPrincipal(){
209             @Override
210             public String getName(){
211                 return "user";
212             }
213         };
214         when(topicService.isCadiEnabled()).thenReturn(true);
215         when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(true);
216         when(httpServReq.getUserPrincipal()).thenReturn(user);
217         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean()))
218                 .thenReturn(createdTopic);
219
220         //when
221         topicService.createTopic(dmaapContext, topicBean);
222
223         //then
224         verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
225         verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean());
226         verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
227         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
228     }
229
230     @Test
231     public void createTopic_shouldFailWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
232         //given
233         thrown.expect(DMaaPAccessDeniedException.class);
234
235         String topicName = "org.onap.dmaap.mr.topic-5";
236         givenTopicBean(topicName);
237
238         Principal user = new Principal(){
239             @Override
240             public String getName(){
241                 return "user";
242             }
243         };
244         when(topicService.isCadiEnabled()).thenReturn(true);
245         when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(false);
246         when(httpServReq.getUserPrincipal()).thenReturn(user);
247
248         //when
249         topicService.createTopic(dmaapContext, topicBean);
250
251         //then
252         verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
253         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
254         verifyZeroInteractions(dmaapKafkaMetaBroker);
255         verifyZeroInteractions(createdTopic);
256     }
257
258     @Test
259     public void createTopic_shouldThrowApiException_whenBrokerThrowsConfigDbException() throws Exception {
260         //given
261         thrown.expect(CambriaApiException.class);
262
263         String topicName = "org.onap.dmaap.mr.topic-6";
264         givenTopicBean(topicName);
265
266         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), any(), anyInt(), anyInt(), anyBoolean()))
267                 .thenThrow(new ConfigDbException("fail"));
268
269         //when
270         topicService.createTopic(dmaapContext, topicBean);
271
272         //then
273         verifyZeroInteractions(createdTopic);
274     }
275
276     @Test
277     public void createTopic_shouldFailGracefully_whenTopicExistsExceptionOccurs() throws Exception {
278         //given
279         String topicName = "org.onap.dmaap.mr.topic-7";
280         givenTopicBean(topicName);
281
282         when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
283                 .thenThrow(new Broker1.TopicExistsException("enfTopicNamePlusExtra"));
284
285         //when
286         topicService.createTopic(dmaapContext, topicBean);
287
288         //then
289         verifyZeroInteractions(createdTopic);
290     }
291
292     @Test
293     public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsZero() {
294         //given
295         int value = 0;
296         String defaultPropertyName = "propertyName";
297         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
298
299         //when
300         int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
301
302         //then
303         assertEquals(6, extracted);
304     }
305
306     @Test
307     public void getValueOrDefault_shouldReturnGivenValue_whenGreaterThanZero() {
308         //given
309         int value = 3;
310         String defaultPropertyName = "propertyName";
311
312         //when
313         int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
314
315         //then
316         assertEquals(value, extracted);
317         verify(topicService, never()).getPropertyFromAJSCmap(defaultPropertyName);
318     }
319
320     @Test
321     public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsNegative() {
322         //given
323         int value = -3;
324         String defaultPropertyName = "propertyName";
325         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
326
327         //when
328         int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
329
330         //then
331         assertEquals(6, extracted);
332     }
333
334     @Test
335     public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNotProvided() {
336         //given
337         int value = 0;
338         String defaultPropertyName = "propertyName";
339         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
340
341         //when
342         int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
343
344         //then
345         assertEquals(1, extracted);
346     }
347
348     @Test
349     public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNaN() {
350         //given
351         int value = 0;
352         String defaultPropertyName = "propertyName";
353         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("a");
354
355         //when
356         int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
357
358         //then
359         assertEquals(1, extracted);
360     }
361
362     @Test(expected = TopicExistsException.class)
363     public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
364             TopicExistsException, JSONException, ConfigDbException {
365
366         Assert.assertNotNull(topicService);
367         when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
368
369         topicService.getTopic(dmaapContext, "topicName");
370     }
371
372     @Test
373     public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
374             TopicExistsException, JSONException, ConfigDbException {
375
376         Assert.assertNotNull(topicService);
377
378         when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
379
380         when(createdTopic.getName()).thenReturn("topicName");
381         when(createdTopic.getDescription()).thenReturn("topicDescription");
382         when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
383
384         when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
385         when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
386
387         topicService.getTopic(dmaapContext, "topicName");
388     }
389
390     @Test(expected = TopicExistsException.class)
391     public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
392             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
393
394         Assert.assertNotNull(topicService);
395
396         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
397
398         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
399
400     }
401
402     @Test
403     public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
404             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
405
406         Assert.assertNotNull(topicService);
407
408         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
409         when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
410         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
411     }
412
413     @Test(expected = TopicExistsException.class)
414     public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
415             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
416
417         Assert.assertNotNull(topicService);
418
419         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
420
421         topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
422
423     }
424
425     @Test
426     public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
427             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
428
429         Assert.assertNotNull(topicService);
430
431         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
432
433         when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
434
435         topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
436     }
437
438     @Test
439     public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
440             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
441
442         Assert.assertNotNull(topicService);
443
444         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
445
446         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
447     }
448
449     @Test(expected = TopicExistsException.class)
450     public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
451             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
452
453         Assert.assertNotNull(topicService);
454
455         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
456
457         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
458     }
459
460     @Test
461     public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedWithAAF_andTopicExists() throws Exception {
462         //given
463         String topicName = "org.onap.dmaap.mr.topic-9";
464         when(topicService.isCadiEnabled()).thenReturn(true);
465         when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(true);
466         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
467
468         //when
469         topicService.deleteTopic(dmaapContext, topicName);
470
471         //then
472         verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
473         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
474         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
475     }
476
477     @Test
478     public void deleteTopic_shouldSkipAAFauthorization_whenTopicNameNotEnforced() throws Exception {
479         //given
480         String topicName = "UNAUTHENTICATED.PRH.READY";
481         when(topicService.isCadiEnabled()).thenReturn(true);
482         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
483
484         //when
485         topicService.deleteTopic(dmaapContext, topicName);
486
487         //then
488         verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
489         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
490     }
491
492     @Test
493     public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedInContext_andTopicExists() throws Exception {
494         //given
495         String topicName = "org.onap.dmaap.mr.topic-10";
496         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
497
498         //when
499         topicService.deleteTopic(dmaapContext, topicName);
500
501         //then
502         verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
503         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
504     }
505
506     @Test
507     public void deleteTopic_shouldNotDeleteTopic_whenUserNotAuthorizedByAAF() throws Exception {
508         //given
509         String topicName = "org.onap.dmaap.mr.topic-10";
510         thrown.expect(DMaaPAccessDeniedException.class);
511
512         when(topicService.isCadiEnabled()).thenReturn(true);
513         when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(false);
514
515         //when
516         topicService.deleteTopic(dmaapContext, topicName);
517
518         //then
519         verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
520         verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
521         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
522     }
523
524     @Test
525     public void deleteTopic_shouldNotDeleteTopic_whenTopicDoesNotExist() throws Exception {
526         //given
527         String topicName = "org.onap.dmaap.mr.topic-10";
528         thrown.expect(TopicExistsException.class);
529
530         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(null);
531
532         //when
533         topicService.deleteTopic(dmaapContext, topicName);
534
535         //then
536         verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
537     }
538
539     @Test
540     public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
541             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
542
543         Assert.assertNotNull(topicService);
544         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
545         TopicBean topicBean = new TopicBean();
546         topicBean.setTopicName("enfTopicNamePlusExtra");
547
548         topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
549     }
550
551     @Test(expected = TopicExistsException.class)
552     public void testPermitConsumerForTopic_nulltopic()
553             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
554             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
555
556         Assert.assertNotNull(topicService);
557         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
558         TopicBean topicBean = new TopicBean();
559         topicBean.setTopicName("enfTopicNamePlusExtra");
560
561         topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
562     }
563
564     @Test
565     public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
566             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
567
568         Assert.assertNotNull(topicService);
569         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
570         TopicBean topicBean = new TopicBean();
571         topicBean.setTopicName("enfTopicNamePlusExtra");
572
573         topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
574     }
575
576     @Test(expected = TopicExistsException.class)
577     public void testdenyConsumerForTopic_nulltopic()
578             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
579             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
580
581         Assert.assertNotNull(topicService);
582
583         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
584         TopicBean topicBean = new TopicBean();
585         topicBean.setTopicName("enfTopicNamePlusExtra");
586
587         topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
588     }
589
590
591     @Test
592     public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
593             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
594
595         Assert.assertNotNull(topicService);
596
597         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
598         TopicBean topicBean = new TopicBean();
599         topicBean.setTopicName("enfTopicNamePlusExtra");
600
601         topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
602     }
603
604     @Test(expected = TopicExistsException.class)
605     public void testPermitPublisherForTopic_nulltopic()
606             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
607             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
608
609         Assert.assertNotNull(topicService);
610
611         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
612         TopicBean topicBean = new TopicBean();
613         topicBean.setTopicName("enfTopicNamePlusExtra");
614
615         topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
616     }
617
618     @Test
619     public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
620             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
621
622         Assert.assertNotNull(topicService);
623
624         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
625         TopicBean topicBean = new TopicBean();
626         topicBean.setTopicName("enfTopicNamePlusExtra");
627
628         topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
629         ;
630     }
631
632     @Test(expected = TopicExistsException.class)
633     public void testDenyPublisherForTopic_nulltopic()
634             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
635             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
636
637         Assert.assertNotNull(topicService);
638
639         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
640         TopicBean topicBean = new TopicBean();
641         topicBean.setTopicName("enfTopicNamePlusExtra");
642
643         topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
644         ;
645     }
646
647     @Test
648     public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
649             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
650
651         Assert.assertNotNull(topicService);
652
653         TopicBean topicBean = new TopicBean();
654         topicBean.setTopicName("enfTopicNamePlusExtra");
655
656         topicService.getAllTopics(dmaapContext);
657     }
658
659     @Test
660     public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
661             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
662
663         Assert.assertNotNull(topicService);
664
665         TopicBean topicBean = new TopicBean();
666         topicBean.setTopicName("enfTopicNamePlusExtra");
667
668         topicService.getTopics(dmaapContext);
669     }
670
671
672 }
673