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");
144 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
146 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
149 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
150 when(dmaapContext.getRequest()).thenReturn(httpServReq);
151 when(dmaapContext.getResponse()).thenReturn(httpServRes);
152 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
153 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
154 when(dmaapContext.getConfigReader()).thenReturn(configReader);
156 TopicBean topicBean = new TopicBean();
157 topicBean.setTopicName("enfTopicNamePlusExtra");
158 topicService.createTopic(dmaapContext, topicBean);
162 public void testCreateTopicWithTopicNameNotEnforced()
163 throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException {
165 Assert.assertNotNull(topicService);
167 PowerMockito.mockStatic(PropertiesMapBean.class);
168 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
170 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
171 .thenReturn("enfTopicName");
172 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
174 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
177 when(dmaapContext.getRequest()).thenReturn(httpServReq);
178 when(dmaapContext.getResponse()).thenReturn(httpServRes);
180 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
181 when(httpServReq.getMethod()).thenReturn("HEAD");
183 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
184 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
185 when(dmaapContext.getConfigReader()).thenReturn(configReader);
186 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
188 when(nsaAcl.isActive()).thenReturn(true);
189 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
191 when(createdTopic.getName()).thenReturn("topicName");
192 when(createdTopic.getOwner()).thenReturn("Owner");
193 when(createdTopic.getDescription()).thenReturn("Description");
194 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
195 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
197 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
198 .thenReturn(createdTopic);
200 TopicBean topicBean = new TopicBean();
201 topicBean.setTopicName("NotEnforcedTopicName");
203 topicService.createTopic(dmaapContext, topicBean);
205 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
209 @Test(expected = NullPointerException.class)
210 public void testCreateTopicNoUserInContextAndNoAuthHeader()
211 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
213 Assert.assertNotNull(topicService);
215 PowerMockito.mockStatic(PropertiesMapBean.class);
217 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
218 .thenReturn("enfTopicName");
219 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
221 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
224 when(httpServReq.getHeader("Authorization")).thenReturn(null);
225 when(dmaapContext.getRequest()).thenReturn(httpServReq);
226 when(dmaapContext.getResponse()).thenReturn(httpServRes);
227 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
229 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
230 when(dmaapContext.getConfigReader()).thenReturn(configReader);
232 TopicBean topicBean = new TopicBean();
233 topicBean.setTopicName("enfTopicNamePlusExtra");
234 topicService.createTopic(dmaapContext, topicBean);
237 @Test(expected = NullPointerException.class)
238 public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
239 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
241 Assert.assertNotNull(topicService);
243 PowerMockito.mockStatic(PropertiesMapBean.class);
245 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
246 .thenReturn("enfTopicName");
247 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
249 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
252 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
253 when(dmaapContext.getRequest()).thenReturn(httpServReq);
254 when(dmaapContext.getResponse()).thenReturn(httpServRes);
255 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
257 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
258 when(dmaapContext.getConfigReader()).thenReturn(configReader);
260 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
261 // anyString())).thenReturn(false);
263 TopicBean topicBean = new TopicBean();
264 topicBean.setTopicName("enfTopicNamePlusExtra");
265 topicService.createTopic(dmaapContext, topicBean);
268 @Test(expected = TopicExistsException.class)
269 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
270 TopicExistsException, JSONException, ConfigDbException {
272 Assert.assertNotNull(topicService);
273 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
274 when(dmaapContext.getConfigReader()).thenReturn(configReader);
275 when(dmaapContext.getRequest()).thenReturn(httpServReq);
276 when(dmaapContext.getResponse()).thenReturn(httpServRes);
277 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
278 when(httpServReq.getMethod()).thenReturn("HEAD");
280 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
282 topicService.getTopic(dmaapContext, "topicName");
286 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
287 TopicExistsException, JSONException, ConfigDbException {
289 Assert.assertNotNull(topicService);
290 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
291 when(dmaapContext.getConfigReader()).thenReturn(configReader);
292 when(dmaapContext.getRequest()).thenReturn(httpServReq);
293 when(dmaapContext.getResponse()).thenReturn(httpServRes);
294 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
296 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
298 when(createdTopic.getName()).thenReturn("topicName");
299 when(createdTopic.getDescription()).thenReturn("topicDescription");
300 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
302 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
303 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
305 when(httpServReq.getMethod()).thenReturn("HEAD");
307 when(httpServRes.getOutputStream()).thenReturn(oStream);
309 topicService.getTopic(dmaapContext, "topicName");
312 @Test(expected = TopicExistsException.class)
313 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
314 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
316 Assert.assertNotNull(topicService);
318 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
319 when(dmaapContext.getConfigReader()).thenReturn(configReader);
320 when(dmaapContext.getRequest()).thenReturn(httpServReq);
321 when(dmaapContext.getResponse()).thenReturn(httpServRes);
322 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
323 when(httpServReq.getMethod()).thenReturn("HEAD");
325 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
327 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
332 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
333 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
335 Assert.assertNotNull(topicService);
337 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
338 when(dmaapContext.getConfigReader()).thenReturn(configReader);
339 when(dmaapContext.getRequest()).thenReturn(httpServReq);
340 when(dmaapContext.getResponse()).thenReturn(httpServRes);
341 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
342 when(httpServReq.getMethod()).thenReturn("HEAD");
344 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
345 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
346 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
349 @Test(expected = TopicExistsException.class)
350 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
351 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
353 Assert.assertNotNull(topicService);
355 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
356 when(dmaapContext.getConfigReader()).thenReturn(configReader);
357 when(dmaapContext.getRequest()).thenReturn(httpServReq);
358 when(dmaapContext.getResponse()).thenReturn(httpServRes);
359 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
360 when(httpServReq.getMethod()).thenReturn("HEAD");
362 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
364 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
369 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
370 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
372 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);
379 when(httpServReq.getMethod()).thenReturn("HEAD");
381 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
383 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
385 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
389 public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
390 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
392 Assert.assertNotNull(topicService);
394 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
396 PowerMockito.mockStatic(AJSCPropertiesMap.class);
398 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
399 .thenReturn("topicFactoryAAF");
401 when(dmaapContext.getConfigReader()).thenReturn(configReader);
402 when(dmaapContext.getRequest()).thenReturn(httpServReq);
403 when(dmaapContext.getResponse()).thenReturn(httpServRes);
404 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
405 when(httpServReq.getMethod()).thenReturn("HEAD");
407 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
409 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
411 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
414 @Test(expected=TopicExistsException.class)
415 public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
416 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
418 Assert.assertNotNull(topicService);
420 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
422 PowerMockito.mockStatic(AJSCPropertiesMap.class);
424 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
425 .thenReturn("topicFactoryAAF");
427 when(dmaapContext.getConfigReader()).thenReturn(configReader);
428 when(dmaapContext.getRequest()).thenReturn(httpServReq);
429 when(dmaapContext.getResponse()).thenReturn(httpServRes);
430 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
431 when(httpServReq.getMethod()).thenReturn("HEAD");
433 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
435 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
437 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
441 public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
442 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
444 Assert.assertNotNull(topicService);
446 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
447 PowerMockito.mockStatic(AJSCPropertiesMap.class);
448 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
449 .thenReturn("hello");
451 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
452 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
453 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
454 when(dmaapContext.getRequest()).thenReturn(httpServReq);
456 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
457 when(dmaapContext.getConfigReader()).thenReturn(configReader);
458 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
459 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
460 TopicBean topicBean = new TopicBean();
461 topicBean.setTopicName("enfTopicNamePlusExtra");
463 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
466 @Test(expected=TopicExistsException.class)
467 public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
468 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
470 Assert.assertNotNull(topicService);
472 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
473 PowerMockito.mockStatic(AJSCPropertiesMap.class);
474 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
475 .thenReturn("hello");
477 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
478 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
479 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
480 when(dmaapContext.getRequest()).thenReturn(httpServReq);
482 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
483 when(dmaapContext.getConfigReader()).thenReturn(configReader);
484 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
485 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
486 TopicBean topicBean = new TopicBean();
487 topicBean.setTopicName("enfTopicNamePlusExtra");
489 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
492 /*@Test(expected=DMaaPAccessDeniedException.class)
493 public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
494 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
496 Assert.assertNotNull(topicService);
498 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
499 PowerMockito.mockStatic(AJSCPropertiesMap.class);
500 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
501 .thenReturn("hello");
503 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
504 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
505 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
506 when(dmaapContext.getRequest()).thenReturn(httpServReq);
508 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
509 when(dmaapContext.getConfigReader()).thenReturn(configReader);
510 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
511 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
512 TopicBean topicBean = new TopicBean();
513 topicBean.setTopicName("enfTopicNamePlusExtra");
514 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
515 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
519 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
520 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
522 Assert.assertNotNull(topicService);
524 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
525 PowerMockito.mockStatic(AJSCPropertiesMap.class);
526 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
527 .thenReturn("hello");
529 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
530 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
531 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
532 when(dmaapContext.getRequest()).thenReturn(httpServReq);
534 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
535 when(dmaapContext.getConfigReader()).thenReturn(configReader);
536 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
537 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
538 TopicBean topicBean = new TopicBean();
539 topicBean.setTopicName("enfTopicNamePlusExtra");
541 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
544 @Test(expected=TopicExistsException.class)
545 public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
546 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
548 Assert.assertNotNull(topicService);
550 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
551 PowerMockito.mockStatic(AJSCPropertiesMap.class);
552 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
553 .thenReturn("hello");
555 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
556 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
557 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
558 when(dmaapContext.getRequest()).thenReturn(httpServReq);
560 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
561 when(dmaapContext.getConfigReader()).thenReturn(configReader);
562 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
563 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
564 TopicBean topicBean = new TopicBean();
565 topicBean.setTopicName("enfTopicNamePlusExtra");
567 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
571 public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
572 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
574 Assert.assertNotNull(topicService);
576 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
577 PowerMockito.mockStatic(AJSCPropertiesMap.class);
578 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
579 .thenReturn("hello");
581 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
582 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
583 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
584 when(dmaapContext.getRequest()).thenReturn(httpServReq);
586 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
587 when(dmaapContext.getConfigReader()).thenReturn(configReader);
588 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
589 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
590 TopicBean topicBean = new TopicBean();
591 topicBean.setTopicName("enfTopicNamePlusExtra");
593 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
596 @Test(expected=TopicExistsException.class)
597 public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
598 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
600 Assert.assertNotNull(topicService);
602 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
603 PowerMockito.mockStatic(AJSCPropertiesMap.class);
604 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
605 .thenReturn("hello");
607 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
608 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
609 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
610 when(dmaapContext.getRequest()).thenReturn(httpServReq);
612 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
613 when(dmaapContext.getConfigReader()).thenReturn(configReader);
614 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
615 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
616 TopicBean topicBean = new TopicBean();
617 topicBean.setTopicName("enfTopicNamePlusExtra");
619 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
624 public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
625 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
627 Assert.assertNotNull(topicService);
629 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
630 PowerMockito.mockStatic(AJSCPropertiesMap.class);
631 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
632 .thenReturn("hello");
634 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
635 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
636 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
637 when(dmaapContext.getRequest()).thenReturn(httpServReq);
639 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
640 when(dmaapContext.getConfigReader()).thenReturn(configReader);
641 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
642 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
643 TopicBean topicBean = new TopicBean();
644 topicBean.setTopicName("enfTopicNamePlusExtra");
646 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
649 @Test(expected=TopicExistsException.class)
650 public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
651 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
653 Assert.assertNotNull(topicService);
655 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
656 PowerMockito.mockStatic(AJSCPropertiesMap.class);
657 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
658 .thenReturn("hello");
660 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
661 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
662 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
663 when(dmaapContext.getRequest()).thenReturn(httpServReq);
665 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
666 when(dmaapContext.getConfigReader()).thenReturn(configReader);
667 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
668 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
669 TopicBean topicBean = new TopicBean();
670 topicBean.setTopicName("enfTopicNamePlusExtra");
672 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
676 public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
677 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
679 Assert.assertNotNull(topicService);
681 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
682 PowerMockito.mockStatic(AJSCPropertiesMap.class);
683 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
684 .thenReturn("hello");
686 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
687 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
688 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
689 when(dmaapContext.getRequest()).thenReturn(httpServReq);
690 when(dmaapContext.getResponse()).thenReturn(httpServRes);
692 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
693 when(dmaapContext.getConfigReader()).thenReturn(configReader);
694 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
695 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
696 TopicBean topicBean = new TopicBean();
697 topicBean.setTopicName("enfTopicNamePlusExtra");
699 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
702 @Test(expected=TopicExistsException.class)
703 public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
704 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
706 Assert.assertNotNull(topicService);
708 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
709 PowerMockito.mockStatic(AJSCPropertiesMap.class);
710 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
711 .thenReturn("hello");
713 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
714 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
715 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
716 when(dmaapContext.getRequest()).thenReturn(httpServReq);
718 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
719 when(dmaapContext.getConfigReader()).thenReturn(configReader);
720 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
721 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
722 TopicBean topicBean = new TopicBean();
723 topicBean.setTopicName("enfTopicNamePlusExtra");
725 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
729 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
730 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
732 Assert.assertNotNull(topicService);
734 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
735 PowerMockito.mockStatic(AJSCPropertiesMap.class);
736 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
737 .thenReturn("hello");
738 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
739 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
740 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
741 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
742 when(dmaapContext.getRequest()).thenReturn(httpServReq);
744 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
745 when(dmaapContext.getConfigReader()).thenReturn(configReader);
746 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
747 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
748 TopicBean topicBean = new TopicBean();
749 topicBean.setTopicName("enfTopicNamePlusExtra");
751 topicService.getAllTopics(dmaapContext);
755 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
756 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
758 Assert.assertNotNull(topicService);
760 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
761 PowerMockito.mockStatic(AJSCPropertiesMap.class);
762 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
763 .thenReturn("hello");
764 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
765 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
766 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
767 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
768 when(dmaapContext.getRequest()).thenReturn(httpServReq);
770 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
771 when(dmaapContext.getConfigReader()).thenReturn(configReader);
772 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
773 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
774 TopicBean topicBean = new TopicBean();
775 topicBean.setTopicName("enfTopicNamePlusExtra");
777 topicService.getTopics(dmaapContext);