2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.mr.cambria.service.impl;
23 import static org.mockito.Matchers.anyBoolean;
24 import static org.mockito.Matchers.anyInt;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
30 import java.io.IOException;
31 import java.util.Arrays;
32 import java.util.HashSet;
34 import javax.servlet.ServletOutputStream;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
38 import org.json.JSONArray;
39 import org.json.JSONException;
40 import org.json.JSONObject;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.mockito.Mock;
46 import org.mockito.MockitoAnnotations;
47 import org.powermock.api.mockito.PowerMockito;
48 import org.powermock.core.classloader.annotations.PrepareForTest;
49 import org.powermock.modules.junit4.PowerMockRunner;
51 import com.att.ajsc.beans.PropertiesMapBean;
52 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
53 import org.onap.dmaap.dmf.mr.CambriaApiException;
54 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
55 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
56 import org.onap.dmaap.dmf.mr.beans.TopicBean;
57 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
58 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
59 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
60 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
61 import org.onap.dmaap.dmf.mr.metabroker.Topic;
62 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
63 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
64 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
65 import org.onap.dmaap.dmf.mr.service.impl.TopicServiceImpl;
66 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
67 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
68 import com.att.nsa.configs.ConfigDbException;
69 import com.att.nsa.security.NsaAcl;
70 import com.att.nsa.security.NsaApiKey;
71 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
72 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
74 //@RunWith(MockitoJUnitRunner.class)
75 @RunWith(PowerMockRunner.class)
76 @PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })
77 public class TopicServiceImplTest {
79 TopicServiceImpl topicService;
82 private DMaaPErrorMessages errorMessages;
85 DMaaPContext dmaapContext;
88 ConfigurationReader configReader;
91 ServletOutputStream oStream;
94 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
97 DMaaPAAFAuthenticator dmaapAAFauthenticator;
102 NsaSimpleApiKey nsaSimpleApiKey;
105 HttpServletRequest httpServReq;
108 HttpServletResponse httpServRes;
111 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
126 public void setUp() {
127 MockitoAnnotations.initMocks(this);
128 topicService = new TopicServiceImpl();
129 topicService.setErrorMessages(errorMessages);
130 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
131 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
132 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
135 @Test(expected = NullPointerException.class)
136 public void testCreateTopicWithEnforcedName()
137 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
139 Assert.assertNotNull(topicService);
140 PowerMockito.mockStatic(PropertiesMapBean.class);
142 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
143 .thenReturn("enfTopicName");
145 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
146 when(dmaapContext.getRequest()).thenReturn(httpServReq);
147 when(dmaapContext.getResponse()).thenReturn(httpServRes);
148 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
149 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
150 when(dmaapContext.getConfigReader()).thenReturn(configReader);
152 TopicBean topicBean = new TopicBean();
153 topicBean.setTopicName("enfTopicNamePlusExtra");
154 topicService.createTopic(dmaapContext, topicBean);
158 public void testCreateTopicWithTopicNameNotEnforced()
159 throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException {
161 Assert.assertNotNull(topicService);
163 PowerMockito.mockStatic(PropertiesMapBean.class);
164 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
166 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
167 .thenReturn("enfTopicName");
169 when(dmaapContext.getRequest()).thenReturn(httpServReq);
170 when(dmaapContext.getResponse()).thenReturn(httpServRes);
172 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
173 when(httpServReq.getMethod()).thenReturn("HEAD");
175 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
176 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
177 when(dmaapContext.getConfigReader()).thenReturn(configReader);
178 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
180 when(nsaAcl.isActive()).thenReturn(true);
181 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
183 when(createdTopic.getName()).thenReturn("topicName");
184 when(createdTopic.getOwner()).thenReturn("Owner");
185 when(createdTopic.getDescription()).thenReturn("Description");
186 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
187 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
189 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
190 .thenReturn(createdTopic);
192 TopicBean topicBean = new TopicBean();
193 topicBean.setTopicName("NotEnforcedTopicName");
195 topicService.createTopic(dmaapContext, topicBean);
197 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
201 @Test(expected = NullPointerException.class)
202 public void testCreateTopicNoUserInContextAndNoAuthHeader()
203 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
205 Assert.assertNotNull(topicService);
207 PowerMockito.mockStatic(PropertiesMapBean.class);
209 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
210 .thenReturn("enfTopicName");
212 when(httpServReq.getHeader("Authorization")).thenReturn(null);
213 when(dmaapContext.getRequest()).thenReturn(httpServReq);
214 when(dmaapContext.getResponse()).thenReturn(httpServRes);
215 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
217 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
218 when(dmaapContext.getConfigReader()).thenReturn(configReader);
220 TopicBean topicBean = new TopicBean();
221 topicBean.setTopicName("enfTopicNamePlusExtra");
222 topicService.createTopic(dmaapContext, topicBean);
225 @Test(expected = NullPointerException.class)
226 public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
227 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
229 Assert.assertNotNull(topicService);
231 PowerMockito.mockStatic(PropertiesMapBean.class);
233 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
234 .thenReturn("enfTopicName");
236 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
237 when(dmaapContext.getRequest()).thenReturn(httpServReq);
238 when(dmaapContext.getResponse()).thenReturn(httpServRes);
239 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
241 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
242 when(dmaapContext.getConfigReader()).thenReturn(configReader);
244 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
245 // anyString())).thenReturn(false);
247 TopicBean topicBean = new TopicBean();
248 topicBean.setTopicName("enfTopicNamePlusExtra");
249 topicService.createTopic(dmaapContext, topicBean);
252 @Test(expected = TopicExistsException.class)
253 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
254 TopicExistsException, JSONException, ConfigDbException {
256 Assert.assertNotNull(topicService);
257 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
258 when(dmaapContext.getConfigReader()).thenReturn(configReader);
259 when(dmaapContext.getRequest()).thenReturn(httpServReq);
260 when(dmaapContext.getResponse()).thenReturn(httpServRes);
261 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
262 when(httpServReq.getMethod()).thenReturn("HEAD");
264 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
266 topicService.getTopic(dmaapContext, "topicName");
270 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
271 TopicExistsException, JSONException, ConfigDbException {
273 Assert.assertNotNull(topicService);
274 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
275 when(dmaapContext.getConfigReader()).thenReturn(configReader);
276 when(dmaapContext.getRequest()).thenReturn(httpServReq);
277 when(dmaapContext.getResponse()).thenReturn(httpServRes);
278 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
280 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
282 when(createdTopic.getName()).thenReturn("topicName");
283 when(createdTopic.getDescription()).thenReturn("topicDescription");
284 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
286 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
287 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
289 when(httpServReq.getMethod()).thenReturn("HEAD");
291 when(httpServRes.getOutputStream()).thenReturn(oStream);
293 topicService.getTopic(dmaapContext, "topicName");
296 @Test(expected = TopicExistsException.class)
297 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
298 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
300 Assert.assertNotNull(topicService);
302 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
303 when(dmaapContext.getConfigReader()).thenReturn(configReader);
304 when(dmaapContext.getRequest()).thenReturn(httpServReq);
305 when(dmaapContext.getResponse()).thenReturn(httpServRes);
306 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
307 when(httpServReq.getMethod()).thenReturn("HEAD");
309 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
311 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
316 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
317 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
319 Assert.assertNotNull(topicService);
321 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
322 when(dmaapContext.getConfigReader()).thenReturn(configReader);
323 when(dmaapContext.getRequest()).thenReturn(httpServReq);
324 when(dmaapContext.getResponse()).thenReturn(httpServRes);
325 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
326 when(httpServReq.getMethod()).thenReturn("HEAD");
328 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
329 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
330 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
333 @Test(expected = TopicExistsException.class)
334 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
335 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
337 Assert.assertNotNull(topicService);
339 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
340 when(dmaapContext.getConfigReader()).thenReturn(configReader);
341 when(dmaapContext.getRequest()).thenReturn(httpServReq);
342 when(dmaapContext.getResponse()).thenReturn(httpServRes);
343 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
344 when(httpServReq.getMethod()).thenReturn("HEAD");
346 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
348 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
353 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
354 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
356 Assert.assertNotNull(topicService);
358 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
359 when(dmaapContext.getConfigReader()).thenReturn(configReader);
360 when(dmaapContext.getRequest()).thenReturn(httpServReq);
361 when(dmaapContext.getResponse()).thenReturn(httpServRes);
362 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
363 when(httpServReq.getMethod()).thenReturn("HEAD");
365 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
367 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
369 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
373 public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
374 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
376 Assert.assertNotNull(topicService);
378 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
380 PowerMockito.mockStatic(AJSCPropertiesMap.class);
382 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
383 .thenReturn("topicFactoryAAF");
385 when(dmaapContext.getConfigReader()).thenReturn(configReader);
386 when(dmaapContext.getRequest()).thenReturn(httpServReq);
387 when(dmaapContext.getResponse()).thenReturn(httpServRes);
388 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
389 when(httpServReq.getMethod()).thenReturn("HEAD");
391 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
393 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
395 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
398 @Test(expected=TopicExistsException.class)
399 public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
400 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
402 Assert.assertNotNull(topicService);
404 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
406 PowerMockito.mockStatic(AJSCPropertiesMap.class);
408 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
409 .thenReturn("topicFactoryAAF");
411 when(dmaapContext.getConfigReader()).thenReturn(configReader);
412 when(dmaapContext.getRequest()).thenReturn(httpServReq);
413 when(dmaapContext.getResponse()).thenReturn(httpServRes);
414 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
415 when(httpServReq.getMethod()).thenReturn("HEAD");
417 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
419 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
421 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
425 public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
426 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
428 Assert.assertNotNull(topicService);
430 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
431 PowerMockito.mockStatic(AJSCPropertiesMap.class);
432 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
433 .thenReturn("hello");
435 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
436 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
437 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
438 when(dmaapContext.getRequest()).thenReturn(httpServReq);
440 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
441 when(dmaapContext.getConfigReader()).thenReturn(configReader);
442 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
443 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
444 TopicBean topicBean = new TopicBean();
445 topicBean.setTopicName("enfTopicNamePlusExtra");
447 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
450 @Test(expected=TopicExistsException.class)
451 public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
452 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
454 Assert.assertNotNull(topicService);
456 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
457 PowerMockito.mockStatic(AJSCPropertiesMap.class);
458 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
459 .thenReturn("hello");
461 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
462 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
463 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
464 when(dmaapContext.getRequest()).thenReturn(httpServReq);
466 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
467 when(dmaapContext.getConfigReader()).thenReturn(configReader);
468 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
469 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
470 TopicBean topicBean = new TopicBean();
471 topicBean.setTopicName("enfTopicNamePlusExtra");
473 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
476 /*@Test(expected=DMaaPAccessDeniedException.class)
477 public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
478 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
480 Assert.assertNotNull(topicService);
482 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
483 PowerMockito.mockStatic(AJSCPropertiesMap.class);
484 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
485 .thenReturn("hello");
487 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
488 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
489 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
490 when(dmaapContext.getRequest()).thenReturn(httpServReq);
492 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
493 when(dmaapContext.getConfigReader()).thenReturn(configReader);
494 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
495 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
496 TopicBean topicBean = new TopicBean();
497 topicBean.setTopicName("enfTopicNamePlusExtra");
498 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
499 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
503 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
504 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
506 Assert.assertNotNull(topicService);
508 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
509 PowerMockito.mockStatic(AJSCPropertiesMap.class);
510 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
511 .thenReturn("hello");
513 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
514 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
515 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
516 when(dmaapContext.getRequest()).thenReturn(httpServReq);
518 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
519 when(dmaapContext.getConfigReader()).thenReturn(configReader);
520 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
521 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
522 TopicBean topicBean = new TopicBean();
523 topicBean.setTopicName("enfTopicNamePlusExtra");
525 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
528 @Test(expected=TopicExistsException.class)
529 public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
530 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
532 Assert.assertNotNull(topicService);
534 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
535 PowerMockito.mockStatic(AJSCPropertiesMap.class);
536 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
537 .thenReturn("hello");
539 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
540 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
541 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
542 when(dmaapContext.getRequest()).thenReturn(httpServReq);
544 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
545 when(dmaapContext.getConfigReader()).thenReturn(configReader);
546 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
547 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
548 TopicBean topicBean = new TopicBean();
549 topicBean.setTopicName("enfTopicNamePlusExtra");
551 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
555 public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
556 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
558 Assert.assertNotNull(topicService);
560 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
561 PowerMockito.mockStatic(AJSCPropertiesMap.class);
562 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
563 .thenReturn("hello");
565 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
566 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
567 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
568 when(dmaapContext.getRequest()).thenReturn(httpServReq);
570 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
571 when(dmaapContext.getConfigReader()).thenReturn(configReader);
572 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
573 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
574 TopicBean topicBean = new TopicBean();
575 topicBean.setTopicName("enfTopicNamePlusExtra");
577 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
580 @Test(expected=TopicExistsException.class)
581 public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
582 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
584 Assert.assertNotNull(topicService);
586 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
587 PowerMockito.mockStatic(AJSCPropertiesMap.class);
588 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
589 .thenReturn("hello");
591 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
592 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
593 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
594 when(dmaapContext.getRequest()).thenReturn(httpServReq);
596 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
597 when(dmaapContext.getConfigReader()).thenReturn(configReader);
598 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
599 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
600 TopicBean topicBean = new TopicBean();
601 topicBean.setTopicName("enfTopicNamePlusExtra");
603 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
608 public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
609 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
611 Assert.assertNotNull(topicService);
613 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
614 PowerMockito.mockStatic(AJSCPropertiesMap.class);
615 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
616 .thenReturn("hello");
618 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
619 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
620 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
621 when(dmaapContext.getRequest()).thenReturn(httpServReq);
623 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
624 when(dmaapContext.getConfigReader()).thenReturn(configReader);
625 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
626 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
627 TopicBean topicBean = new TopicBean();
628 topicBean.setTopicName("enfTopicNamePlusExtra");
630 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
633 @Test(expected=TopicExistsException.class)
634 public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
635 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
637 Assert.assertNotNull(topicService);
639 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
640 PowerMockito.mockStatic(AJSCPropertiesMap.class);
641 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
642 .thenReturn("hello");
644 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
645 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
646 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
647 when(dmaapContext.getRequest()).thenReturn(httpServReq);
649 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
650 when(dmaapContext.getConfigReader()).thenReturn(configReader);
651 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
652 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
653 TopicBean topicBean = new TopicBean();
654 topicBean.setTopicName("enfTopicNamePlusExtra");
656 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
660 public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
661 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
663 Assert.assertNotNull(topicService);
665 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
666 PowerMockito.mockStatic(AJSCPropertiesMap.class);
667 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
668 .thenReturn("hello");
670 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
671 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
672 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
673 when(dmaapContext.getRequest()).thenReturn(httpServReq);
674 when(dmaapContext.getResponse()).thenReturn(httpServRes);
676 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
677 when(dmaapContext.getConfigReader()).thenReturn(configReader);
678 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
679 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
680 TopicBean topicBean = new TopicBean();
681 topicBean.setTopicName("enfTopicNamePlusExtra");
683 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
686 @Test(expected=TopicExistsException.class)
687 public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
688 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
690 Assert.assertNotNull(topicService);
692 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
693 PowerMockito.mockStatic(AJSCPropertiesMap.class);
694 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
695 .thenReturn("hello");
697 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
698 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
699 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
700 when(dmaapContext.getRequest()).thenReturn(httpServReq);
702 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
703 when(dmaapContext.getConfigReader()).thenReturn(configReader);
704 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
705 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
706 TopicBean topicBean = new TopicBean();
707 topicBean.setTopicName("enfTopicNamePlusExtra");
709 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
713 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
714 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
716 Assert.assertNotNull(topicService);
718 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
719 PowerMockito.mockStatic(AJSCPropertiesMap.class);
720 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
721 .thenReturn("hello");
722 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
723 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
724 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
725 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
726 when(dmaapContext.getRequest()).thenReturn(httpServReq);
728 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
729 when(dmaapContext.getConfigReader()).thenReturn(configReader);
730 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
731 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
732 TopicBean topicBean = new TopicBean();
733 topicBean.setTopicName("enfTopicNamePlusExtra");
735 topicService.getAllTopics(dmaapContext);
739 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
740 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
742 Assert.assertNotNull(topicService);
744 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
745 PowerMockito.mockStatic(AJSCPropertiesMap.class);
746 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
747 .thenReturn("hello");
748 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
749 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
750 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
751 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
752 when(dmaapContext.getRequest()).thenReturn(httpServReq);
754 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
755 when(dmaapContext.getConfigReader()).thenReturn(configReader);
756 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
757 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
758 TopicBean topicBean = new TopicBean();
759 topicBean.setTopicName("enfTopicNamePlusExtra");
761 topicService.getTopics(dmaapContext);