90c379eb961d59efeb6549c65aa6320862cc5147
[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 getIntValueOrDefault_shouldReturnOne_whenDefaultNotProvided() {
294         //given
295         String defaultPropertyName = "propertyName";
296         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
297
298         //when
299         int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
300
301         //then
302         assertEquals(1, extracted);
303     }
304
305     @Test
306     public void getIntValueOrDefault_shouldReturnOne_whenValueIsNegative() {
307         //given
308         String defaultPropertyName = "propertyName";
309         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("-1");
310
311         //when
312         int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
313
314         //then
315         assertEquals(1, extracted);
316     }
317
318     @Test
319     public void getIntValueOrDefault_shouldParseDefaultAndReturnIt_whenGivenValueIsPositive() {
320         //given
321         String defaultPropertyName = "propertyName";
322         when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("3");
323
324         //when
325         int extracted = topicService.getIntValueOrDefault(defaultPropertyName);
326
327         //then
328         assertEquals(3, extracted);
329     }
330
331     @Test(expected = TopicExistsException.class)
332     public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
333             TopicExistsException, JSONException, ConfigDbException {
334
335         Assert.assertNotNull(topicService);
336         when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
337
338         topicService.getTopic(dmaapContext, "topicName");
339     }
340
341     @Test
342     public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
343             TopicExistsException, JSONException, ConfigDbException {
344
345         Assert.assertNotNull(topicService);
346
347         when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
348
349         when(createdTopic.getName()).thenReturn("topicName");
350         when(createdTopic.getDescription()).thenReturn("topicDescription");
351         when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
352
353         when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
354         when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
355
356         topicService.getTopic(dmaapContext, "topicName");
357     }
358
359     @Test(expected = TopicExistsException.class)
360     public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
361             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
362
363         Assert.assertNotNull(topicService);
364
365         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
366
367         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
368
369     }
370
371     @Test
372     public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
373             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
374
375         Assert.assertNotNull(topicService);
376
377         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
378         when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
379         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
380     }
381
382     @Test(expected = TopicExistsException.class)
383     public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
384             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
385
386         Assert.assertNotNull(topicService);
387
388         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
389
390         topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
391
392     }
393
394     @Test
395     public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
396             IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
397
398         Assert.assertNotNull(topicService);
399
400         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
401
402         when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
403
404         topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
405     }
406
407     @Test
408     public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
409             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
410
411         Assert.assertNotNull(topicService);
412
413         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
414
415         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
416     }
417
418     @Test(expected = TopicExistsException.class)
419     public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
420             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
421
422         Assert.assertNotNull(topicService);
423
424         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
425
426         topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
427     }
428
429     @Test
430     public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedWithAAF_andTopicExists() throws Exception {
431         //given
432         String topicName = "org.onap.dmaap.mr.topic-9";
433         when(topicService.isCadiEnabled()).thenReturn(true);
434         when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(true);
435         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
436
437         //when
438         topicService.deleteTopic(dmaapContext, topicName);
439
440         //then
441         verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
442         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
443         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
444     }
445
446     @Test
447     public void deleteTopic_shouldSkipAAFauthorization_whenTopicNameNotEnforced() throws Exception {
448         //given
449         String topicName = "UNAUTHENTICATED.PRH.READY";
450         when(topicService.isCadiEnabled()).thenReturn(true);
451         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
452
453         //when
454         topicService.deleteTopic(dmaapContext, topicName);
455
456         //then
457         verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
458         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
459     }
460
461     @Test
462     public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedInContext_andTopicExists() throws Exception {
463         //given
464         String topicName = "org.onap.dmaap.mr.topic-10";
465         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
466
467         //when
468         topicService.deleteTopic(dmaapContext, topicName);
469
470         //then
471         verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
472         verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
473     }
474
475     @Test
476     public void deleteTopic_shouldNotDeleteTopic_whenUserNotAuthorizedByAAF() throws Exception {
477         //given
478         String topicName = "org.onap.dmaap.mr.topic-10";
479         thrown.expect(DMaaPAccessDeniedException.class);
480
481         when(topicService.isCadiEnabled()).thenReturn(true);
482         when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(false);
483
484         //when
485         topicService.deleteTopic(dmaapContext, topicName);
486
487         //then
488         verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
489         verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
490         verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
491     }
492
493     @Test
494     public void deleteTopic_shouldNotDeleteTopic_whenTopicDoesNotExist() throws Exception {
495         //given
496         String topicName = "org.onap.dmaap.mr.topic-10";
497         thrown.expect(TopicExistsException.class);
498
499         when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(null);
500
501         //when
502         topicService.deleteTopic(dmaapContext, topicName);
503
504         //then
505         verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
506     }
507
508     @Test
509     public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
510             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
511
512         Assert.assertNotNull(topicService);
513         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
514         TopicBean topicBean = new TopicBean();
515         topicBean.setTopicName("enfTopicNamePlusExtra");
516
517         topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
518     }
519
520     @Test(expected = TopicExistsException.class)
521     public void testPermitConsumerForTopic_nulltopic()
522             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
523             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
524
525         Assert.assertNotNull(topicService);
526         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
527         TopicBean topicBean = new TopicBean();
528         topicBean.setTopicName("enfTopicNamePlusExtra");
529
530         topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
531     }
532
533     @Test
534     public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
535             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
536
537         Assert.assertNotNull(topicService);
538         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
539         TopicBean topicBean = new TopicBean();
540         topicBean.setTopicName("enfTopicNamePlusExtra");
541
542         topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
543     }
544
545     @Test(expected = TopicExistsException.class)
546     public void testdenyConsumerForTopic_nulltopic()
547             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
548             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
549
550         Assert.assertNotNull(topicService);
551
552         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
553         TopicBean topicBean = new TopicBean();
554         topicBean.setTopicName("enfTopicNamePlusExtra");
555
556         topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
557     }
558
559
560     @Test
561     public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
562             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
563
564         Assert.assertNotNull(topicService);
565
566         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
567         TopicBean topicBean = new TopicBean();
568         topicBean.setTopicName("enfTopicNamePlusExtra");
569
570         topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
571     }
572
573     @Test(expected = TopicExistsException.class)
574     public void testPermitPublisherForTopic_nulltopic()
575             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
576             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
577
578         Assert.assertNotNull(topicService);
579
580         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
581         TopicBean topicBean = new TopicBean();
582         topicBean.setTopicName("enfTopicNamePlusExtra");
583
584         topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
585     }
586
587     @Test
588     public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
589             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
590
591         Assert.assertNotNull(topicService);
592
593         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
594         TopicBean topicBean = new TopicBean();
595         topicBean.setTopicName("enfTopicNamePlusExtra");
596
597         topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
598         ;
599     }
600
601     @Test(expected = TopicExistsException.class)
602     public void testDenyPublisherForTopic_nulltopic()
603             throws DMaaPAccessDeniedException, CambriaApiException, IOException,
604             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
605
606         Assert.assertNotNull(topicService);
607
608         when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
609         TopicBean topicBean = new TopicBean();
610         topicBean.setTopicName("enfTopicNamePlusExtra");
611
612         topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
613         ;
614     }
615
616     @Test
617     public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
618             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
619
620         Assert.assertNotNull(topicService);
621
622         TopicBean topicBean = new TopicBean();
623         topicBean.setTopicName("enfTopicNamePlusExtra");
624
625         topicService.getAllTopics(dmaapContext);
626     }
627
628     @Test
629     public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
630             TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
631
632         Assert.assertNotNull(topicService);
633
634         TopicBean topicBean = new TopicBean();
635         topicBean.setTopicName("enfTopicNamePlusExtra");
636
637         topicService.getTopics(dmaapContext);
638     }
639
640
641 }
642