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.nsa.cambria.CambriaApiException;
\r
54 import com.att.nsa.cambria.beans.DMaaPContext;
\r
55 import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
\r
56 import com.att.nsa.cambria.beans.TopicBean;
\r
57 import com.att.nsa.cambria.constants.CambriaConstants;
\r
58 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
\r
59 import com.att.nsa.cambria.exception.DMaaPErrorMessages;
\r
60 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
\r
61 import com.att.nsa.cambria.metabroker.Topic;
\r
62 import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
\r
63 import com.att.nsa.cambria.security.DMaaPAuthenticator;
\r
64 import com.att.nsa.cambria.security.DMaaPAuthenticatorImpl;
\r
65 import com.att.nsa.cambria.utils.ConfigurationReader;
\r
66 import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
\r
67 import com.att.nsa.configs.ConfigDbException;
\r
68 import com.att.nsa.security.NsaAcl;
\r
69 import com.att.nsa.security.NsaApiKey;
\r
70 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
\r
71 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
\r
73 //@RunWith(MockitoJUnitRunner.class)
\r
74 @RunWith(PowerMockRunner.class)
\r
75 @PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })
\r
76 public class TopicServiceImplTest {
\r
78 TopicServiceImpl topicService;
\r
81 private DMaaPErrorMessages errorMessages;
\r
84 DMaaPContext dmaapContext;
\r
87 ConfigurationReader configReader;
\r
90 ServletOutputStream oStream;
\r
93 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
\r
96 DMaaPAAFAuthenticator dmaapAAFauthenticator;
\r
101 NsaSimpleApiKey nsaSimpleApiKey;
\r
104 HttpServletRequest httpServReq;
\r
107 HttpServletResponse httpServRes;
\r
110 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
\r
113 Topic createdTopic;
\r
119 JSONObject jsonObj;
\r
122 JSONArray jsonArray;
\r
125 public void setUp() {
\r
126 MockitoAnnotations.initMocks(this);
\r
127 topicService = new TopicServiceImpl();
\r
128 topicService.setErrorMessages(errorMessages);
\r
129 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
\r
130 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
\r
131 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
\r
134 @Test(expected = DMaaPAccessDeniedException.class)
\r
135 public void testCreateTopicWithEnforcedName()
\r
136 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
138 PowerMockito.when(DMaaPAuthenticatorImpl.isIgnoreAuth()).thenReturn(true);
\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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
148 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
149 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
151 TopicBean topicBean = new TopicBean();
\r
152 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
153 topicService.createTopic(dmaapContext, topicBean);
\r
157 public void testCreateTopicWithTopicNameNotEnforced()
\r
158 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
160 Assert.assertNotNull(topicService);
\r
162 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
163 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
165 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
166 .thenReturn("enfTopicName");
\r
168 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
169 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
171 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
172 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
174 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
175 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
176 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
177 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
179 when(nsaAcl.isActive()).thenReturn(true);
\r
180 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
182 when(createdTopic.getName()).thenReturn("topicName");
\r
183 when(createdTopic.getOwner()).thenReturn("Owner");
\r
184 when(createdTopic.getDescription()).thenReturn("Description");
\r
185 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
186 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
188 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
\r
189 .thenReturn(createdTopic);
\r
191 TopicBean topicBean = new TopicBean();
\r
192 topicBean.setTopicName("NotEnforcedTopicName");
\r
194 topicService.createTopic(dmaapContext, topicBean);
\r
196 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
\r
200 @Test(expected = DMaaPAccessDeniedException.class)
\r
201 public void testCreateTopicNoUserInContextAndNoAuthHeader()
\r
202 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
204 PowerMockito.when(DMaaPAuthenticatorImpl.isIgnoreAuth()).thenReturn(true);
\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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
216 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
217 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
219 TopicBean topicBean = new TopicBean();
\r
220 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
221 topicService.createTopic(dmaapContext, topicBean);
\r
224 @Test(expected = DMaaPAccessDeniedException.class)
\r
225 public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
\r
226 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
228 PowerMockito.when(DMaaPAuthenticatorImpl.isIgnoreAuth()).thenReturn(true);
\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(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
240 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
241 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
243 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
\r
244 // anyString())).thenReturn(false);
\r
246 TopicBean topicBean = new TopicBean();
\r
247 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
248 topicService.createTopic(dmaapContext, topicBean);
\r
251 @Test(expected = TopicExistsException.class)
\r
252 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
253 TopicExistsException, JSONException, ConfigDbException {
\r
255 Assert.assertNotNull(topicService);
\r
256 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
257 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
258 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
259 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
260 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
261 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
263 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
265 topicService.getTopic(dmaapContext, "topicName");
\r
269 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
270 TopicExistsException, JSONException, ConfigDbException {
\r
272 Assert.assertNotNull(topicService);
\r
273 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
274 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
275 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
276 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
277 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
279 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
\r
281 when(createdTopic.getName()).thenReturn("topicName");
\r
282 when(createdTopic.getDescription()).thenReturn("topicDescription");
\r
283 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
285 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
286 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
288 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
290 when(httpServRes.getOutputStream()).thenReturn(oStream);
\r
292 topicService.getTopic(dmaapContext, "topicName");
\r
295 @Test(expected = TopicExistsException.class)
\r
296 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
297 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
299 Assert.assertNotNull(topicService);
\r
301 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
302 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
303 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
304 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
305 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
306 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
308 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
310 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
315 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
316 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
318 Assert.assertNotNull(topicService);
\r
320 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
321 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
322 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
323 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
324 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
325 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
327 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
328 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
329 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
332 @Test(expected = TopicExistsException.class)
\r
333 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
334 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
336 Assert.assertNotNull(topicService);
\r
338 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
339 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
340 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
341 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
342 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
343 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
345 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
347 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
352 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
353 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
355 Assert.assertNotNull(topicService);
\r
357 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
358 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
359 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
360 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
361 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
362 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
364 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
366 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
368 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
372 public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
373 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
375 Assert.assertNotNull(topicService);
\r
377 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
379 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
381 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
382 .thenReturn("topicFactoryAAF");
\r
384 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
385 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
386 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
387 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
388 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
390 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
392 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
394 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
397 @Test(expected=TopicExistsException.class)
\r
398 public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
399 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
401 Assert.assertNotNull(topicService);
\r
403 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
405 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
407 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
408 .thenReturn("topicFactoryAAF");
\r
410 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
411 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
412 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
413 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
414 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
416 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
418 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
420 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
424 public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
425 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
427 Assert.assertNotNull(topicService);
\r
429 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
430 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
431 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
432 .thenReturn("hello");
\r
434 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
435 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
436 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
437 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
439 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
440 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
441 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
442 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
443 TopicBean topicBean = new TopicBean();
\r
444 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
446 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
\r
449 @Test(expected=TopicExistsException.class)
\r
450 public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
451 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
453 Assert.assertNotNull(topicService);
\r
455 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
456 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
457 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
458 .thenReturn("hello");
\r
460 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
461 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
462 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
463 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
465 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
466 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
467 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
468 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
\r
469 TopicBean topicBean = new TopicBean();
\r
470 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
472 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
\r
475 @Test(expected=DMaaPAccessDeniedException.class)
\r
476 public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
477 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
479 Assert.assertNotNull(topicService);
\r
481 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
482 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
483 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
484 .thenReturn("hello");
\r
486 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
487 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
488 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
489 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
491 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
492 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
493 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
494 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
495 TopicBean topicBean = new TopicBean();
\r
496 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
497 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
\r
498 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
\r
502 public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
503 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
505 Assert.assertNotNull(topicService);
\r
507 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
508 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
509 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
510 .thenReturn("hello");
\r
512 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
513 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
514 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
515 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
517 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
518 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
519 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
520 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
521 TopicBean topicBean = new TopicBean();
\r
522 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
524 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
527 @Test(expected=TopicExistsException.class)
\r
528 public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
529 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
531 Assert.assertNotNull(topicService);
\r
533 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
534 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
535 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
536 .thenReturn("hello");
\r
538 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
539 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
540 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
541 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
543 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
544 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
545 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
546 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
\r
547 TopicBean topicBean = new TopicBean();
\r
548 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
550 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
554 public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
555 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
557 Assert.assertNotNull(topicService);
\r
559 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
560 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
561 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
562 .thenReturn("hello");
\r
564 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
565 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
566 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
567 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
569 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
570 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
571 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
572 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
573 TopicBean topicBean = new TopicBean();
\r
574 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
576 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
579 @Test(expected=TopicExistsException.class)
\r
580 public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
581 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
583 Assert.assertNotNull(topicService);
\r
585 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
586 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
587 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
588 .thenReturn("hello");
\r
590 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
591 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
592 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
593 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
595 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
596 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
597 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
598 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
\r
599 TopicBean topicBean = new TopicBean();
\r
600 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
602 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
607 public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
608 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
610 Assert.assertNotNull(topicService);
\r
612 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
613 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
614 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
615 .thenReturn("hello");
\r
617 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
618 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
619 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
620 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
622 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
623 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
624 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
625 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
626 TopicBean topicBean = new TopicBean();
\r
627 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
629 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
632 @Test(expected=TopicExistsException.class)
\r
633 public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
634 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
636 Assert.assertNotNull(topicService);
\r
638 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
639 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
640 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
641 .thenReturn("hello");
\r
643 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
644 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
645 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
646 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
648 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
649 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
650 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
651 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
\r
652 TopicBean topicBean = new TopicBean();
\r
653 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
655 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
\r
659 public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
660 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
662 Assert.assertNotNull(topicService);
\r
664 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
665 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
666 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
667 .thenReturn("hello");
\r
669 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
670 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
671 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
672 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
674 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
675 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
676 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
677 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
678 TopicBean topicBean = new TopicBean();
\r
679 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
681 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
\r
684 @Test(expected=TopicExistsException.class)
\r
685 public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
686 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
688 Assert.assertNotNull(topicService);
\r
690 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
691 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
692 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
693 .thenReturn("hello");
\r
695 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
696 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
697 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
698 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
700 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
701 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
702 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
703 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
\r
704 TopicBean topicBean = new TopicBean();
\r
705 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
707 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
\r
711 public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
712 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
714 Assert.assertNotNull(topicService);
\r
716 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
717 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
718 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
719 .thenReturn("hello");
\r
720 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
721 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
722 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
723 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
724 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
726 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
727 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
728 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
729 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
730 TopicBean topicBean = new TopicBean();
\r
731 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
733 topicService.getAllTopics(dmaapContext);
\r
737 public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
738 TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
740 Assert.assertNotNull(topicService);
\r
742 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
743 PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
744 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
\r
745 .thenReturn("hello");
\r
746 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
747 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
748 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
749 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
\r
750 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
752 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
753 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
754 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
755 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
\r
756 TopicBean topicBean = new TopicBean();
\r
757 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
759 topicService.getTopics(dmaapContext);
\r