2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.dmaap.dmf.mr.service.impl;
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;
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.util.Arrays;
45 import java.util.HashSet;
46 import javax.servlet.ServletOutputStream;
47 import javax.servlet.http.HttpServletRequest;
48 import javax.servlet.http.HttpServletResponse;
49 import org.json.JSONException;
50 import org.json.JSONObject;
51 import org.junit.Assert;
52 import org.junit.Before;
53 import org.junit.Rule;
54 import org.junit.Test;
55 import org.junit.rules.ExpectedException;
56 import org.junit.runner.RunWith;
57 import org.mockito.Mock;
58 import org.mockito.Spy;
59 import org.mockito.runners.MockitoJUnitRunner;
60 import org.onap.dmaap.dmf.mr.CambriaApiException;
61 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
62 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
63 import org.onap.dmaap.dmf.mr.beans.TopicBean;
64 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
65 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
66 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
67 import org.onap.dmaap.dmf.mr.metabroker.Broker1;
68 import org.onap.dmaap.dmf.mr.metabroker.Topic;
69 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
70 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
71 import sun.security.acl.PrincipalImpl;
74 @RunWith(MockitoJUnitRunner.class)
75 public class TopicServiceImplTest {
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;
84 private TopicServiceImpl topicService;
87 private DMaaPErrorMessages errorMessages;
90 private DMaaPContext dmaapContext;
93 private ConfigurationReader configReader;
96 private ServletOutputStream oStream;
99 private DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
102 private HttpServletRequest httpServReq;
105 private HttpServletResponse httpServRes;
108 private DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
111 private Topic createdTopic;
114 private NsaAcl nsaAcl;
117 public ExpectedException thrown = ExpectedException.none();
120 public void setUp() throws Exception {
121 configureSpyInstance();
122 topicService.setErrorMessages(errorMessages);
124 when(dmaapContext.getRequest()).thenReturn(httpServReq);
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:");
138 private void givenTopicBean(String topicName) {
139 topicBean = new TopicBean();
140 topicBean.setTopicName(topicName);
145 public void createTopic_shouldSkipAAFAuthorization_whenCadiIsEnabled_andTopicNameNotEnforced() throws Exception {
147 String topicName = "UNAUTHENTICATED.PRH.REGISTRATION";
148 givenTopicBean(topicName);
150 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
151 .thenReturn(createdTopic);
154 topicService.createTopic(dmaapContext, topicBean);
157 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(),
159 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
160 verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
164 public void createTopic_shouldSkipAAFAuthorization_whenCADIdisabled() throws Exception {
166 String topicName = "org.onap.dmaap.mr.topic-2";
167 givenTopicBean(topicName);
169 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
170 .thenReturn(createdTopic);
173 topicService.createTopic(dmaapContext, topicBean);
176 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(),
178 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
179 verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
183 public void createTopic_shouldPass_whenCADIisDisabled_andNoUserInDmaapContext() throws Exception {
185 String topicName = "org.onap.dmaap.mr.topic-3";
186 givenTopicBean(topicName);
188 doReturn(null).when(topicService).getDmaapAuthenticatedUser(dmaapContext);
189 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
190 .thenReturn(createdTopic);
193 topicService.createTopic(dmaapContext, topicBean);
196 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(),
198 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
202 public void createTopic_shouldPassWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
204 String topicName = "org.onap.dmaap.mr.topic-4";
205 givenTopicBean(topicName);
207 when(topicService.isCadiEnabled()).thenReturn(true);
208 when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(true);
209 when(httpServReq.getUserPrincipal()).thenReturn(new PrincipalImpl("user"));
210 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean()))
211 .thenReturn(createdTopic);
214 topicService.createTopic(dmaapContext, topicBean);
217 verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
218 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean());
219 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
220 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
224 public void createTopic_shouldFailWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
226 thrown.expect(DMaaPAccessDeniedException.class);
228 String topicName = "org.onap.dmaap.mr.topic-5";
229 givenTopicBean(topicName);
231 when(topicService.isCadiEnabled()).thenReturn(true);
232 when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(false);
233 when(httpServReq.getUserPrincipal()).thenReturn(new PrincipalImpl("user"));
235 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean()))
236 .thenReturn(createdTopic);
239 topicService.createTopic(dmaapContext, topicBean);
242 verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
243 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
244 verifyZeroInteractions(dmaapKafkaMetaBroker);
245 verifyZeroInteractions(createdTopic);
249 public void createTopic_shouldThrowApiException_whenBrokerThrowsConfigDbException() throws Exception {
251 thrown.expect(CambriaApiException.class);
253 String topicName = "org.onap.dmaap.mr.topic-6";
254 givenTopicBean(topicName);
256 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
257 .thenThrow(new ConfigDbException("fail"));
260 topicService.createTopic(dmaapContext, topicBean);
263 verifyZeroInteractions(createdTopic);
267 public void createTopic_shouldFailGracefully_whenTopicExistsExceptionOccurs() throws Exception {
269 String topicName = "org.onap.dmaap.mr.topic-7";
270 givenTopicBean(topicName);
272 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
273 .thenThrow(new Broker1.TopicExistsException("enfTopicNamePlusExtra"));
276 topicService.createTopic(dmaapContext, topicBean);
279 verifyZeroInteractions(createdTopic);
283 public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsZero() {
286 String defaultPropertyName = "propertyName";
287 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
290 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
293 assertEquals(6, extracted);
297 public void getValueOrDefault_shouldReturnGivenValue_whenGreaterThanZero() {
300 String defaultPropertyName = "propertyName";
303 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
306 assertEquals(value, extracted);
307 verify(topicService, never()).getPropertyFromAJSCmap(defaultPropertyName);
311 public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsNegative() {
314 String defaultPropertyName = "propertyName";
315 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
318 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
321 assertEquals(6, extracted);
325 public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNotProvided() {
328 String defaultPropertyName = "propertyName";
329 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
332 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
335 assertEquals(1, extracted);
339 public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNaN() {
342 String defaultPropertyName = "propertyName";
343 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("a");
346 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
349 assertEquals(1, extracted);
352 @Test(expected = TopicExistsException.class)
353 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
354 TopicExistsException, JSONException, ConfigDbException {
356 Assert.assertNotNull(topicService);
357 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
358 when(dmaapContext.getConfigReader()).thenReturn(configReader);
359 when(dmaapContext.getRequest()).thenReturn(httpServReq);
360 when(dmaapContext.getResponse()).thenReturn(httpServRes);
361 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
362 when(httpServReq.getMethod()).thenReturn("HEAD");
364 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
366 topicService.getTopic(dmaapContext, "topicName");
370 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
371 TopicExistsException, JSONException, ConfigDbException {
373 Assert.assertNotNull(topicService);
374 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
375 when(dmaapContext.getConfigReader()).thenReturn(configReader);
376 when(dmaapContext.getRequest()).thenReturn(httpServReq);
377 when(dmaapContext.getResponse()).thenReturn(httpServRes);
378 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
380 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
382 when(createdTopic.getName()).thenReturn("topicName");
383 when(createdTopic.getDescription()).thenReturn("topicDescription");
384 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
386 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
387 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
389 when(httpServReq.getMethod()).thenReturn("HEAD");
391 when(httpServRes.getOutputStream()).thenReturn(oStream);
393 topicService.getTopic(dmaapContext, "topicName");
396 @Test(expected = TopicExistsException.class)
397 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
398 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
400 Assert.assertNotNull(topicService);
402 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
403 when(dmaapContext.getConfigReader()).thenReturn(configReader);
404 when(dmaapContext.getRequest()).thenReturn(httpServReq);
405 when(dmaapContext.getResponse()).thenReturn(httpServRes);
406 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
407 when(httpServReq.getMethod()).thenReturn("HEAD");
409 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
411 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
416 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
417 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
419 Assert.assertNotNull(topicService);
421 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
422 when(dmaapContext.getConfigReader()).thenReturn(configReader);
423 when(dmaapContext.getRequest()).thenReturn(httpServReq);
424 when(dmaapContext.getResponse()).thenReturn(httpServRes);
425 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
426 when(httpServReq.getMethod()).thenReturn("HEAD");
428 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
429 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
430 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
433 @Test(expected = TopicExistsException.class)
434 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
435 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
437 Assert.assertNotNull(topicService);
439 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
440 when(dmaapContext.getConfigReader()).thenReturn(configReader);
441 when(dmaapContext.getRequest()).thenReturn(httpServReq);
442 when(dmaapContext.getResponse()).thenReturn(httpServRes);
443 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
444 when(httpServReq.getMethod()).thenReturn("HEAD");
446 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
448 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
453 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
454 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
456 Assert.assertNotNull(topicService);
458 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
459 when(dmaapContext.getConfigReader()).thenReturn(configReader);
460 when(dmaapContext.getRequest()).thenReturn(httpServReq);
461 when(dmaapContext.getResponse()).thenReturn(httpServRes);
462 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
463 when(httpServReq.getMethod()).thenReturn("HEAD");
465 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
467 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
469 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
473 public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
474 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
476 Assert.assertNotNull(topicService);
478 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
480 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
482 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
484 when(dmaapContext.getConfigReader()).thenReturn(configReader);
485 when(dmaapContext.getRequest()).thenReturn(httpServReq);
486 when(dmaapContext.getResponse()).thenReturn(httpServRes);
487 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
488 when(httpServReq.getMethod()).thenReturn("HEAD");
490 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
492 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
494 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
497 @Test(expected = TopicExistsException.class)
498 public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
499 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
501 Assert.assertNotNull(topicService);
503 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
505 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
507 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
509 when(dmaapContext.getConfigReader()).thenReturn(configReader);
510 when(dmaapContext.getRequest()).thenReturn(httpServReq);
511 when(dmaapContext.getResponse()).thenReturn(httpServRes);
512 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
513 when(httpServReq.getMethod()).thenReturn("HEAD");
515 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
517 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
519 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
523 public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedWithAAF_andTopicExists() throws Exception {
525 String topicName = "org.onap.dmaap.mr.topic-9";
526 when(topicService.isCadiEnabled()).thenReturn(true);
527 when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(true);
528 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
531 topicService.deleteTopic(dmaapContext, topicName);
534 verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
535 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
536 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
540 public void deleteTopic_shouldSkipAAFauthorization_whenTopicNameNotEnforced() throws Exception {
542 String topicName = "UNAUTHENTICATED.PRH.READY";
543 when(topicService.isCadiEnabled()).thenReturn(true);
544 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
547 topicService.deleteTopic(dmaapContext, topicName);
550 verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
551 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
555 public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedInContext_andTopicExists() throws Exception {
557 String topicName = "org.onap.dmaap.mr.topic-10";
558 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
561 topicService.deleteTopic(dmaapContext, topicName);
564 verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
565 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
569 public void deleteTopic_shouldNotDeleteTopic_whenUserNotAuthorizedByAAF() throws Exception {
571 String topicName = "org.onap.dmaap.mr.topic-10";
572 thrown.expect(DMaaPAccessDeniedException.class);
574 when(topicService.isCadiEnabled()).thenReturn(true);
575 when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(false);
576 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
579 topicService.deleteTopic(dmaapContext, topicName);
582 verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
583 verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
584 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
588 public void deleteTopic_shouldNotDeleteTopic_whenTopicDoesNotExist() throws Exception {
590 String topicName = "org.onap.dmaap.mr.topic-10";
591 thrown.expect(TopicExistsException.class);
593 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(null);
596 topicService.deleteTopic(dmaapContext, topicName);
599 verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
603 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
604 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
606 Assert.assertNotNull(topicService);
608 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
609 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
610 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
612 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
613 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
614 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
615 when(dmaapContext.getRequest()).thenReturn(httpServReq);
617 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
618 when(dmaapContext.getConfigReader()).thenReturn(configReader);
619 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
620 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
621 TopicBean topicBean = new TopicBean();
622 topicBean.setTopicName("enfTopicNamePlusExtra");
624 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
627 @Test(expected = TopicExistsException.class)
628 public void testPermitConsumerForTopic_nulltopic()
629 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
630 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
632 Assert.assertNotNull(topicService);
634 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
635 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
636 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
638 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
639 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
640 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
641 when(dmaapContext.getRequest()).thenReturn(httpServReq);
643 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
644 when(dmaapContext.getConfigReader()).thenReturn(configReader);
645 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
646 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
647 TopicBean topicBean = new TopicBean();
648 topicBean.setTopicName("enfTopicNamePlusExtra");
650 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
654 public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
655 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
657 Assert.assertNotNull(topicService);
659 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
660 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
661 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
663 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
664 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
665 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
666 when(dmaapContext.getRequest()).thenReturn(httpServReq);
668 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
669 when(dmaapContext.getConfigReader()).thenReturn(configReader);
670 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
671 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
672 TopicBean topicBean = new TopicBean();
673 topicBean.setTopicName("enfTopicNamePlusExtra");
675 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
678 @Test(expected = TopicExistsException.class)
679 public void testdenyConsumerForTopic_nulltopic()
680 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
681 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
683 Assert.assertNotNull(topicService);
685 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
686 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
687 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
689 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
690 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
691 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
692 when(dmaapContext.getRequest()).thenReturn(httpServReq);
694 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
695 when(dmaapContext.getConfigReader()).thenReturn(configReader);
696 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
697 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
698 TopicBean topicBean = new TopicBean();
699 topicBean.setTopicName("enfTopicNamePlusExtra");
701 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
706 public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
707 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
709 Assert.assertNotNull(topicService);
711 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
712 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
713 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
715 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
716 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
717 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
718 when(dmaapContext.getRequest()).thenReturn(httpServReq);
720 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
721 when(dmaapContext.getConfigReader()).thenReturn(configReader);
722 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
723 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
724 TopicBean topicBean = new TopicBean();
725 topicBean.setTopicName("enfTopicNamePlusExtra");
727 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
730 @Test(expected = TopicExistsException.class)
731 public void testPermitPublisherForTopic_nulltopic()
732 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
733 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
735 Assert.assertNotNull(topicService);
737 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
738 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
739 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
741 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
742 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
743 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
744 when(dmaapContext.getRequest()).thenReturn(httpServReq);
746 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
747 when(dmaapContext.getConfigReader()).thenReturn(configReader);
748 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
749 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
750 TopicBean topicBean = new TopicBean();
751 topicBean.setTopicName("enfTopicNamePlusExtra");
753 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
757 public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
758 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
760 Assert.assertNotNull(topicService);
762 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
763 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
764 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
766 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
767 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
768 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
769 when(dmaapContext.getRequest()).thenReturn(httpServReq);
770 when(dmaapContext.getResponse()).thenReturn(httpServRes);
772 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
773 when(dmaapContext.getConfigReader()).thenReturn(configReader);
774 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
775 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
776 TopicBean topicBean = new TopicBean();
777 topicBean.setTopicName("enfTopicNamePlusExtra");
779 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
783 @Test(expected = TopicExistsException.class)
784 public void testDenyPublisherForTopic_nulltopic()
785 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
786 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
788 Assert.assertNotNull(topicService);
790 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
791 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
792 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
794 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
795 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
796 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
797 when(dmaapContext.getRequest()).thenReturn(httpServReq);
799 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
800 when(dmaapContext.getConfigReader()).thenReturn(configReader);
801 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
802 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
803 TopicBean topicBean = new TopicBean();
804 topicBean.setTopicName("enfTopicNamePlusExtra");
806 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
811 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
812 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
814 Assert.assertNotNull(topicService);
816 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
817 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
818 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
819 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
820 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
821 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
822 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
823 when(dmaapContext.getRequest()).thenReturn(httpServReq);
825 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
826 when(dmaapContext.getConfigReader()).thenReturn(configReader);
827 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
828 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
829 TopicBean topicBean = new TopicBean();
830 topicBean.setTopicName("enfTopicNamePlusExtra");
832 topicService.getAllTopics(dmaapContext);
836 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
837 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
839 Assert.assertNotNull(topicService);
841 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
842 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
843 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
844 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
845 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
846 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
847 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
848 when(dmaapContext.getRequest()).thenReturn(httpServReq);
850 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
851 when(dmaapContext.getConfigReader()).thenReturn(configReader);
852 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
853 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
854 TopicBean topicBean = new TopicBean();
855 topicBean.setTopicName("enfTopicNamePlusExtra");
857 topicService.getTopics(dmaapContext);