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