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.ArgumentMatchers.any;
27 import static org.mockito.ArgumentMatchers.anyBoolean;
28 import static org.mockito.ArgumentMatchers.anyInt;
29 import static org.mockito.ArgumentMatchers.anyString;
30 import static org.mockito.ArgumentMatchers.contains;
31 import static org.mockito.ArgumentMatchers.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.ajsc.filemonitor.AJSCPropertiesMap;
40 import com.att.nsa.configs.ConfigDbException;
41 import com.att.nsa.security.NsaAcl;
42 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
43 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
44 import java.io.IOException;
45 import java.nio.file.attribute.UserPrincipal;
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.junit.MockitoJUnit;
62 import org.mockito.junit.MockitoJUnitRunner;
63 import org.mockito.junit.MockitoRule;
64 import org.mockito.quality.Strictness;
65 import org.onap.dmaap.dmf.mr.CambriaApiException;
66 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
67 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
68 import org.onap.dmaap.dmf.mr.beans.TopicBean;
69 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
70 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
71 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
72 import org.onap.dmaap.dmf.mr.metabroker.Broker1;
73 import org.onap.dmaap.dmf.mr.metabroker.Topic;
74 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
75 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
76 import java.security.Principal;
77 import org.powermock.core.classloader.annotations.PowerMockIgnore;
78 import org.powermock.core.classloader.annotations.PrepareForTest;
79 import org.powermock.modules.junit4.PowerMockRunner;
82 @RunWith(MockitoJUnitRunner.Silent.class)
83 public class TopicServiceImplTest {
86 private static final String TOPIC_CREATE_PEM = "org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:org.onap.dmaap.mr|create";
87 private static final String TOPIC_DELETE_PEM = "org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:org.onap.dmaap.mr|destroy";
88 private NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
89 private TopicBean topicBean;
92 private TopicServiceImpl topicService;
95 private DMaaPErrorMessages errorMessages;
98 private DMaaPContext dmaapContext;
101 private ConfigurationReader configReader;
104 private ServletOutputStream oStream;
107 private DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
110 private HttpServletRequest httpServReq;
113 private HttpServletResponse httpServRes;
116 private DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
119 private Topic createdTopic;
122 private NsaAcl nsaAcl;
125 public ExpectedException thrown = ExpectedException.none();
128 public void setUp() throws Exception {
129 configureSpyInstance();
130 topicService.setErrorMessages(errorMessages);
132 when(dmaapContext.getRequest()).thenReturn(httpServReq);
135 private void configureSpyInstance() throws Exception {
136 doReturn(user).when(topicService).getDmaapAuthenticatedUser(any(DMaaPContext.class));
137 doReturn(dmaapKafkaMetaBroker).when(topicService).getMetaBroker(any(DMaaPContext.class));
138 doNothing().when(topicService).respondOk(any(DMaaPContext.class),anyString());
139 doNothing().when(topicService).respondOk(any(DMaaPContext.class),any(JSONObject.class));
140 when(topicService.getPropertyFromAJSCbean("enforced.topic.name.AAF"))
141 .thenReturn("org.onap.dmaap.mr");
142 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf"))
143 .thenReturn("org.onap.dmaap.mr.topicFactory|:org.onap.dmaap.mr.topic:");
146 private void givenTopicBean(String topicName) {
147 topicBean = new TopicBean();
148 topicBean.setTopicName(topicName);
153 public void createTopic_shouldSkipAAFAuthorization_whenCadiIsEnabled_andTopicNameNotEnforced() throws Exception {
155 String topicName = "UNAUTHENTICATED.PRH.REGISTRATION";
157 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
158 .thenReturn(createdTopic);
160 givenTopicBean(topicName);
163 topicService.createTopic(dmaapContext, topicBean);
166 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
168 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
169 verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
173 public void createTopic_shouldSkipAAFAuthorization_whenCADIdisabled() throws Exception {
175 String topicName = "org.onap.dmaap.mr.topic-2";
176 givenTopicBean(topicName);
178 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
179 .thenReturn(createdTopic);
182 topicService.createTopic(dmaapContext, topicBean);
185 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
187 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
188 verify(httpServReq, never()).isUserInRole(TOPIC_CREATE_PEM);
192 public void createTopic_shouldPass_whenCADIisDisabled_andNoUserInDmaapContext() throws Exception {
194 String topicName = "org.onap.dmaap.mr.topic-3";
195 givenTopicBean(topicName);
197 doReturn(null).when(topicService).getDmaapAuthenticatedUser(dmaapContext);
198 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
199 .thenReturn(createdTopic);
202 topicService.createTopic(dmaapContext, topicBean);
205 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(),
207 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
211 public void createTopic_shouldPassWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
213 String topicName = "org.onap.dmaap.mr.topic-4";
214 givenTopicBean(topicName);
216 Principal user = new UserPrincipal(){
218 public String getName(){
222 when(topicService.isCadiEnabled()).thenReturn(true);
223 when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(true);
224 when(httpServReq.getUserPrincipal()).thenReturn(user);
225 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean()))
226 .thenReturn(createdTopic);
229 topicService.createTopic(dmaapContext, topicBean);
232 verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
233 verify(dmaapKafkaMetaBroker).createTopic(eq(topicName), any(), eq("user"), anyInt(), anyInt(), anyBoolean());
234 verify(topicService).respondOk(eq(dmaapContext), any(JSONObject.class));
235 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
239 public void createTopic_shouldFailWithAAFauthorization_whenCadiIsEnabled_andTopicNameWithEnforcedPrefix() throws Exception {
241 thrown.expect(DMaaPAccessDeniedException.class);
243 String topicName = "org.onap.dmaap.mr.topic-5";
244 givenTopicBean(topicName);
246 Principal user = new Principal(){
248 public String getName(){
252 when(topicService.isCadiEnabled()).thenReturn(true);
253 when(httpServReq.isUserInRole(TOPIC_CREATE_PEM)).thenReturn(false);
254 when(httpServReq.getUserPrincipal()).thenReturn(user);
256 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), anyString(), eq("user"), anyInt(), anyInt(), anyBoolean()))
257 .thenReturn(createdTopic);
260 topicService.createTopic(dmaapContext, topicBean);
263 verify(httpServReq).isUserInRole(TOPIC_CREATE_PEM);
264 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
265 verifyZeroInteractions(dmaapKafkaMetaBroker);
266 verifyZeroInteractions(createdTopic);
270 public void createTopic_shouldThrowApiException_whenBrokerThrowsConfigDbException() throws Exception {
272 thrown.expect(CambriaApiException.class);
274 String topicName = "org.onap.dmaap.mr.topic-6";
275 givenTopicBean(topicName);
277 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), any(), anyInt(), anyInt(), anyBoolean()))
278 .thenThrow(new ConfigDbException("fail"));
281 topicService.createTopic(dmaapContext, topicBean);
284 verifyZeroInteractions(createdTopic);
288 public void createTopic_shouldFailGracefully_whenTopicExistsExceptionOccurs() throws Exception {
290 String topicName = "org.onap.dmaap.mr.topic-7";
291 givenTopicBean(topicName);
293 when(dmaapKafkaMetaBroker.createTopic(eq(topicName), any(), anyString(), anyInt(), anyInt(), anyBoolean()))
294 .thenThrow(new Broker1.TopicExistsException("enfTopicNamePlusExtra"));
297 topicService.createTopic(dmaapContext, topicBean);
300 verifyZeroInteractions(createdTopic);
304 public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsZero() {
307 String defaultPropertyName = "propertyName";
308 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
311 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
314 assertEquals(6, extracted);
318 public void getValueOrDefault_shouldReturnGivenValue_whenGreaterThanZero() {
321 String defaultPropertyName = "propertyName";
324 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
327 assertEquals(value, extracted);
328 verify(topicService, never()).getPropertyFromAJSCmap(defaultPropertyName);
332 public void getValueOrDefault_shouldParseDeafultAndReturnIt_whenGivenValueIsNegative() {
335 String defaultPropertyName = "propertyName";
336 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("6");
339 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
342 assertEquals(6, extracted);
346 public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNotProvided() {
349 String defaultPropertyName = "propertyName";
350 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("");
353 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
356 assertEquals(1, extracted);
360 public void getValueOrDefault_shouldReturnOne_whenGivenValueIsZero_andDefaultNaN() {
363 String defaultPropertyName = "propertyName";
364 when(topicService.getPropertyFromAJSCmap(defaultPropertyName)).thenReturn("a");
367 int extracted = topicService.getValueOrDefault(value, defaultPropertyName);
370 assertEquals(1, extracted);
373 @Test(expected = TopicExistsException.class)
374 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
375 TopicExistsException, JSONException, ConfigDbException {
377 Assert.assertNotNull(topicService);
378 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
379 when(dmaapContext.getConfigReader()).thenReturn(configReader);
380 when(dmaapContext.getRequest()).thenReturn(httpServReq);
381 when(dmaapContext.getResponse()).thenReturn(httpServRes);
382 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
383 when(httpServReq.getMethod()).thenReturn("HEAD");
385 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
387 topicService.getTopic(dmaapContext, "topicName");
391 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
392 TopicExistsException, JSONException, ConfigDbException {
394 Assert.assertNotNull(topicService);
395 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
396 when(dmaapContext.getConfigReader()).thenReturn(configReader);
397 when(dmaapContext.getRequest()).thenReturn(httpServReq);
398 when(dmaapContext.getResponse()).thenReturn(httpServRes);
399 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
401 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
403 when(createdTopic.getName()).thenReturn("topicName");
404 when(createdTopic.getDescription()).thenReturn("topicDescription");
405 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
407 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
408 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
410 when(httpServReq.getMethod()).thenReturn("HEAD");
412 when(httpServRes.getOutputStream()).thenReturn(oStream);
414 topicService.getTopic(dmaapContext, "topicName");
417 @Test(expected = TopicExistsException.class)
418 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
419 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
421 Assert.assertNotNull(topicService);
423 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
424 when(dmaapContext.getConfigReader()).thenReturn(configReader);
425 when(dmaapContext.getRequest()).thenReturn(httpServReq);
426 when(dmaapContext.getResponse()).thenReturn(httpServRes);
427 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
428 when(httpServReq.getMethod()).thenReturn("HEAD");
430 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
432 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
437 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
438 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
440 Assert.assertNotNull(topicService);
442 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
443 when(dmaapContext.getConfigReader()).thenReturn(configReader);
444 when(dmaapContext.getRequest()).thenReturn(httpServReq);
445 when(dmaapContext.getResponse()).thenReturn(httpServRes);
446 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
447 when(httpServReq.getMethod()).thenReturn("HEAD");
449 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
450 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
451 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
454 @Test(expected = TopicExistsException.class)
455 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
456 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
458 Assert.assertNotNull(topicService);
460 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
461 when(dmaapContext.getConfigReader()).thenReturn(configReader);
462 when(dmaapContext.getRequest()).thenReturn(httpServReq);
463 when(dmaapContext.getResponse()).thenReturn(httpServRes);
464 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
465 when(httpServReq.getMethod()).thenReturn("HEAD");
467 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
469 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
474 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
475 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
477 Assert.assertNotNull(topicService);
479 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
480 when(dmaapContext.getConfigReader()).thenReturn(configReader);
481 when(dmaapContext.getRequest()).thenReturn(httpServReq);
482 when(dmaapContext.getResponse()).thenReturn(httpServRes);
483 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
484 when(httpServReq.getMethod()).thenReturn("HEAD");
486 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
488 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
490 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
494 public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
495 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
497 Assert.assertNotNull(topicService);
499 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
501 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
503 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
505 when(dmaapContext.getConfigReader()).thenReturn(configReader);
506 when(dmaapContext.getRequest()).thenReturn(httpServReq);
507 when(dmaapContext.getResponse()).thenReturn(httpServRes);
508 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
509 when(httpServReq.getMethod()).thenReturn("HEAD");
511 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
513 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
515 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
518 @Test(expected = TopicExistsException.class)
519 public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
520 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
522 Assert.assertNotNull(topicService);
524 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
526 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
528 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
530 when(dmaapContext.getConfigReader()).thenReturn(configReader);
531 when(dmaapContext.getRequest()).thenReturn(httpServReq);
532 when(dmaapContext.getResponse()).thenReturn(httpServRes);
533 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
534 when(httpServReq.getMethod()).thenReturn("HEAD");
536 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
538 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
540 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
544 public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedWithAAF_andTopicExists() throws Exception {
546 String topicName = "org.onap.dmaap.mr.topic-9";
547 when(topicService.isCadiEnabled()).thenReturn(true);
548 when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(true);
549 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
552 topicService.deleteTopic(dmaapContext, topicName);
555 verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
556 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
557 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
561 public void deleteTopic_shouldSkipAAFauthorization_whenTopicNameNotEnforced() throws Exception {
563 String topicName = "UNAUTHENTICATED.PRH.READY";
564 when(topicService.isCadiEnabled()).thenReturn(true);
565 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
568 topicService.deleteTopic(dmaapContext, topicName);
571 verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
572 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
576 public void deleteTopic_shouldDeleteTopic_whenUserAuthorizedInContext_andTopicExists() throws Exception {
578 String topicName = "org.onap.dmaap.mr.topic-10";
579 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
582 topicService.deleteTopic(dmaapContext, topicName);
585 verify(httpServReq, never()).isUserInRole(TOPIC_DELETE_PEM);
586 verify(topicService).respondOk(eq(dmaapContext), contains(topicName));
590 public void deleteTopic_shouldNotDeleteTopic_whenUserNotAuthorizedByAAF() throws Exception {
592 String topicName = "org.onap.dmaap.mr.topic-10";
593 thrown.expect(DMaaPAccessDeniedException.class);
595 when(topicService.isCadiEnabled()).thenReturn(true);
596 when(httpServReq.isUserInRole(TOPIC_DELETE_PEM)).thenReturn(false);
597 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(createdTopic);
600 topicService.deleteTopic(dmaapContext, topicName);
603 verify(httpServReq).isUserInRole(TOPIC_DELETE_PEM);
604 verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
605 verify(topicService, never()).getDmaapAuthenticatedUser(dmaapContext);
609 public void deleteTopic_shouldNotDeleteTopic_whenTopicDoesNotExist() throws Exception {
611 String topicName = "org.onap.dmaap.mr.topic-10";
612 thrown.expect(TopicExistsException.class);
614 when(dmaapKafkaMetaBroker.getTopic(topicName)).thenReturn(null);
617 topicService.deleteTopic(dmaapContext, topicName);
620 verify(topicService, never()).respondOk(eq(dmaapContext), anyString());
624 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
625 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
627 Assert.assertNotNull(topicService);
629 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
630 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
631 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
633 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
634 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
635 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
636 when(dmaapContext.getRequest()).thenReturn(httpServReq);
638 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
639 when(dmaapContext.getConfigReader()).thenReturn(configReader);
640 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
641 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
642 TopicBean topicBean = new TopicBean();
643 topicBean.setTopicName("enfTopicNamePlusExtra");
645 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
648 @Test(expected = TopicExistsException.class)
649 public void testPermitConsumerForTopic_nulltopic()
650 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
651 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
653 Assert.assertNotNull(topicService);
655 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
656 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
657 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
659 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
660 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
661 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
662 when(dmaapContext.getRequest()).thenReturn(httpServReq);
664 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
665 when(dmaapContext.getConfigReader()).thenReturn(configReader);
666 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
667 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
668 TopicBean topicBean = new TopicBean();
669 topicBean.setTopicName("enfTopicNamePlusExtra");
671 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
675 public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
676 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
678 Assert.assertNotNull(topicService);
680 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
681 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
682 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
684 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
685 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
686 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
687 when(dmaapContext.getRequest()).thenReturn(httpServReq);
689 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
690 when(dmaapContext.getConfigReader()).thenReturn(configReader);
691 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
692 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
693 TopicBean topicBean = new TopicBean();
694 topicBean.setTopicName("enfTopicNamePlusExtra");
696 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
699 @Test(expected = TopicExistsException.class)
700 public void testdenyConsumerForTopic_nulltopic()
701 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
702 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
704 Assert.assertNotNull(topicService);
706 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
707 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
708 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
710 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
711 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
712 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
713 when(dmaapContext.getRequest()).thenReturn(httpServReq);
715 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
716 when(dmaapContext.getConfigReader()).thenReturn(configReader);
717 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
718 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
719 TopicBean topicBean = new TopicBean();
720 topicBean.setTopicName("enfTopicNamePlusExtra");
722 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
727 public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
728 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
730 Assert.assertNotNull(topicService);
732 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
733 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
734 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
736 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
737 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
738 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
739 when(dmaapContext.getRequest()).thenReturn(httpServReq);
741 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
742 when(dmaapContext.getConfigReader()).thenReturn(configReader);
743 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
744 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
745 TopicBean topicBean = new TopicBean();
746 topicBean.setTopicName("enfTopicNamePlusExtra");
748 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
751 @Test(expected = TopicExistsException.class)
752 public void testPermitPublisherForTopic_nulltopic()
753 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
754 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
756 Assert.assertNotNull(topicService);
758 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
759 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
760 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
762 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
763 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
764 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
765 when(dmaapContext.getRequest()).thenReturn(httpServReq);
767 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
768 when(dmaapContext.getConfigReader()).thenReturn(configReader);
769 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
770 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
771 TopicBean topicBean = new TopicBean();
772 topicBean.setTopicName("enfTopicNamePlusExtra");
774 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
778 public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
779 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
781 Assert.assertNotNull(topicService);
783 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
784 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
785 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
787 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
788 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
789 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
790 when(dmaapContext.getRequest()).thenReturn(httpServReq);
791 when(dmaapContext.getResponse()).thenReturn(httpServRes);
793 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
794 when(dmaapContext.getConfigReader()).thenReturn(configReader);
795 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
796 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
797 TopicBean topicBean = new TopicBean();
798 topicBean.setTopicName("enfTopicNamePlusExtra");
800 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
804 @Test(expected = TopicExistsException.class)
805 public void testDenyPublisherForTopic_nulltopic()
806 throws DMaaPAccessDeniedException, CambriaApiException, IOException,
807 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
809 Assert.assertNotNull(topicService);
811 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
812 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
813 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
815 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
816 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
817 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
818 when(dmaapContext.getRequest()).thenReturn(httpServReq);
820 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
821 when(dmaapContext.getConfigReader()).thenReturn(configReader);
822 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
823 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
824 TopicBean topicBean = new TopicBean();
825 topicBean.setTopicName("enfTopicNamePlusExtra");
827 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
832 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
833 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
835 Assert.assertNotNull(topicService);
837 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
838 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
839 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
840 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
841 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
842 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
843 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
844 when(dmaapContext.getRequest()).thenReturn(httpServReq);
846 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
847 when(dmaapContext.getConfigReader()).thenReturn(configReader);
848 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
849 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
850 TopicBean topicBean = new TopicBean();
851 topicBean.setTopicName("enfTopicNamePlusExtra");
853 topicService.getAllTopics(dmaapContext);
857 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
858 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
860 Assert.assertNotNull(topicService);
862 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
863 //PowerMockito.mockStatic(AJSCPropertiesMap.class);
864 when(topicService.getPropertyFromAJSCmap("msgRtr.topicfactory.aaf")).thenReturn("hello");
865 //PowerMockito.mockStatic(DMaaPResponseBuilder.class);
866 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
867 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
868 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
869 when(dmaapContext.getRequest()).thenReturn(httpServReq);
871 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
872 when(dmaapContext.getConfigReader()).thenReturn(configReader);
873 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
874 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
875 TopicBean topicBean = new TopicBean();
876 topicBean.setTopicName("enfTopicNamePlusExtra");
878 topicService.getTopics(dmaapContext);