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.ClassRule;
\r
44 import org.junit.Rule;
\r
45 import org.junit.Test;
\r
46 import org.junit.runner.RunWith;
\r
47 import org.mockito.InjectMocks;
\r
48 import org.mockito.Mock;
\r
49 import org.mockito.MockitoAnnotations;
\r
50 import org.powermock.api.mockito.PowerMockito;
\r
51 import org.powermock.core.classloader.annotations.PrepareForTest;
\r
52 import org.powermock.modules.junit4.PowerMockRunner;
\r
53 import org.powermock.modules.junit4.rule.PowerMockRule;
\r
54 import org.springframework.beans.factory.annotation.Autowired;
\r
55 import org.springframework.test.context.ContextConfiguration;
\r
56 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
\r
58 import com.att.ajsc.beans.PropertiesMapBean;
\r
59 import com.att.nsa.cambria.CambriaApiException;
\r
60 import com.att.nsa.cambria.beans.DMaaPContext;
\r
61 import com.att.nsa.cambria.beans.DMaaPKafkaMetaBroker;
\r
62 import com.att.nsa.cambria.beans.TopicBean;
\r
63 import com.att.nsa.cambria.constants.CambriaConstants;
\r
64 import com.att.nsa.cambria.exception.DMaaPAccessDeniedException;
\r
65 import com.att.nsa.cambria.exception.DMaaPErrorMessages;
\r
66 import com.att.nsa.cambria.metabroker.Broker.TopicExistsException;
\r
67 import com.att.nsa.cambria.metabroker.Topic;
\r
68 import com.att.nsa.cambria.security.DMaaPAAFAuthenticator;
\r
69 import com.att.nsa.cambria.security.DMaaPAuthenticator;
\r
70 import com.att.nsa.cambria.utils.ConfigurationReader;
\r
71 import com.att.nsa.cambria.utils.DMaaPResponseBuilder;
\r
72 import com.att.nsa.configs.ConfigDbException;
\r
73 import com.att.nsa.security.NsaAcl;
\r
74 import com.att.nsa.security.NsaApiKey;
\r
75 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
\r
76 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
\r
78 //@RunWith(MockitoJUnitRunner.class)
\r
79 //@RunWith(PowerMockRunner.class)
\r
80 //@RunWith(SpringJUnit4ClassRunner.class)
\r
81 //@ContextConfiguration("classpath:/spring-context.xml")
\r
82 //@PrepareForTest({ PropertiesMapBean.class })
\r
83 public class TopicServiceImplTest {
\r
86 public PowerMockRule rule = new PowerMockRule();*/
\r
89 /*TopicServiceImpl topicService;
\r
92 private DMaaPErrorMessages errorMessages;
\r
95 DMaaPContext dmaapContext;
\r
98 ConfigurationReader configReader;
\r
101 ServletOutputStream oStream;
\r
104 DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
\r
107 DMaaPAAFAuthenticator dmaapAAFauthenticator;
\r
112 NsaSimpleApiKey nsaSimpleApiKey;
\r
115 HttpServletRequest httpServReq;
\r
118 HttpServletResponse httpServRes;
\r
121 DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
\r
124 Topic createdTopic;
\r
130 JSONObject jsonObj;
\r
133 JSONArray jsonArray;
\r
136 public void setUp() {
\r
137 MockitoAnnotations.initMocks(this);
\r
138 topicService = new TopicServiceImpl();
\r
139 topicService.setErrorMessages(errorMessages);
\r
142 @Test(expected = DMaaPAccessDeniedException.class)
\r
143 public void testCreateTopicWithEnforcedName()
\r
144 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
146 Assert.assertNotNull(topicService);
\r
148 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
150 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
151 .thenReturn("enfTopicName");
\r
153 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
154 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
155 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
156 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
157 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
159 TopicBean topicBean = new TopicBean();
\r
160 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
162 topicService.createTopic(dmaapContext, topicBean);
\r
166 public void testCreateTopicWithTopicNameNotEnforced()
\r
167 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
169 Assert.assertNotNull(topicService);
\r
171 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
172 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
174 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
175 .thenReturn("enfTopicName");
\r
177 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
178 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
180 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
181 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
183 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
184 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
185 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
186 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
188 when(nsaAcl.isActive()).thenReturn(true);
\r
189 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
191 when(createdTopic.getName()).thenReturn("topicName");
\r
192 when(createdTopic.getOwner()).thenReturn("Owner");
\r
193 when(createdTopic.getDescription()).thenReturn("Description");
\r
194 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
195 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
197 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
\r
198 .thenReturn(createdTopic);
\r
200 TopicBean topicBean = new TopicBean();
\r
201 topicBean.setTopicName("NotEnforcedTopicName");
\r
203 topicService.createTopic(dmaapContext, topicBean);
\r
205 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
\r
209 @Test(expected = DMaaPAccessDeniedException.class)
\r
210 public void testCreateTopicNoUserInContextAndNoAuthHeader()
\r
211 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
213 Assert.assertNotNull(topicService);
\r
215 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
217 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
218 .thenReturn("enfTopicName");
\r
220 when(httpServReq.getHeader("Authorization")).thenReturn(null);
\r
221 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
222 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
224 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
225 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
227 TopicBean topicBean = new TopicBean();
\r
228 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
230 topicService.createTopic(dmaapContext, topicBean);
\r
233 @Test(expected = DMaaPAccessDeniedException.class)
\r
234 public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
\r
235 throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
\r
237 Assert.assertNotNull(topicService);
\r
239 PowerMockito.mockStatic(PropertiesMapBean.class);
\r
241 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
\r
242 .thenReturn("enfTopicName");
\r
244 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
\r
245 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
246 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
\r
248 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
249 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
251 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
\r
252 // anyString())).thenReturn(false);
\r
254 TopicBean topicBean = new TopicBean();
\r
255 topicBean.setTopicName("enfTopicNamePlusExtra");
\r
257 topicService.createTopic(dmaapContext, topicBean);
\r
260 @Test(expected = TopicExistsException.class)
\r
261 public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
262 TopicExistsException, JSONException, ConfigDbException {
\r
264 Assert.assertNotNull(topicService);
\r
265 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
266 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
267 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
268 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
269 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
270 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
272 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
\r
274 topicService.getTopic(dmaapContext, "topicName");
\r
278 public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
\r
279 TopicExistsException, JSONException, ConfigDbException {
\r
281 Assert.assertNotNull(topicService);
\r
282 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
283 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
284 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
285 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
286 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
288 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
\r
290 when(createdTopic.getName()).thenReturn("topicName");
\r
291 when(createdTopic.getDescription()).thenReturn("topicDescription");
\r
292 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
\r
294 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
295 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
297 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
299 when(httpServRes.getOutputStream()).thenReturn(oStream);
\r
301 topicService.getTopic(dmaapContext, "topicName");
\r
304 @Test(expected = TopicExistsException.class)
\r
305 public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
306 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
308 Assert.assertNotNull(topicService);
\r
310 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
311 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
312 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
313 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
314 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
315 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
317 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
319 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
324 public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
325 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
327 Assert.assertNotNull(topicService);
\r
329 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
330 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
331 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
332 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
333 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
334 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
336 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
337 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
\r
338 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
341 @Test(expected = TopicExistsException.class)
\r
342 public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
343 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
345 Assert.assertNotNull(topicService);
\r
347 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
348 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
349 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
350 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
351 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
352 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
354 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
356 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
361 public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
362 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
364 Assert.assertNotNull(topicService);
\r
366 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
367 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
368 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
369 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
370 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
371 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
373 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
375 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
377 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
\r
381 // public void testDeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
382 // IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
384 // Assert.assertNotNull(topicService);
\r
386 // PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
388 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
\r
390 // PowerMockito.when(AJSCPropertiesMap.
\r
391 // getProperty(CambriaConstants.msgRtr_prop,"msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");
\r
394 // when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
395 // when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
396 // when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
397 // when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
398 // when(httpServReq.getMethod()).thenReturn("HEAD");
\r
400 // when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
402 // when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
\r
404 // topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
\r
410 @Test(expected = TopicExistsException.class)
\r
411 public void testPermitPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
412 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
414 Assert.assertNotNull(topicService);
\r
416 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
417 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
418 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
419 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
421 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
422 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
423 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
424 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
425 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
426 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
428 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
430 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
434 public void testPermitPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
435 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
437 Assert.assertNotNull(topicService);
\r
439 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
440 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
441 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
442 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
444 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
445 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
446 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
447 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
448 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
449 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
451 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
454 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
458 @Test(expected = TopicExistsException.class)
\r
459 public void testDenyPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
460 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
462 Assert.assertNotNull(topicService);
\r
464 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
465 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
466 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
467 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
469 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
470 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
471 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
472 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
473 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
474 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
476 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
478 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
482 public void testDenyPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
483 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
485 Assert.assertNotNull(topicService);
\r
487 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
488 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
489 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
490 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
492 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
493 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
494 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
495 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
496 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
497 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
499 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
502 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");
\r
505 @Test(expected = TopicExistsException.class)
\r
506 public void testPermitConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
507 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
509 Assert.assertNotNull(topicService);
\r
511 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
512 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
513 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
514 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
516 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
517 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
518 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
519 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
520 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
521 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
523 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
525 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
529 public void testPermitConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
530 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
532 Assert.assertNotNull(topicService);
\r
534 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
535 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
536 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
537 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
539 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
540 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
541 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
542 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
543 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
544 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
546 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
549 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
553 @Test(expected = TopicExistsException.class)
\r
554 public void testDenyConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
555 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
557 Assert.assertNotNull(topicService);
\r
559 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
560 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
561 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
562 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
564 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
565 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
566 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
567 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
568 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
569 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
571 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
\r
573 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r
577 public void testDenyConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
\r
578 IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
\r
580 Assert.assertNotNull(topicService);
\r
582 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
\r
583 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
584 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
\r
585 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
\r
587 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
\r
588 when(dmaapContext.getConfigReader()).thenReturn(configReader);
\r
589 when(dmaapContext.getRequest()).thenReturn(httpServReq);
\r
590 when(dmaapContext.getResponse()).thenReturn(httpServRes);
\r
591 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
\r
592 when(httpServReq.getMethod()).thenReturn("HEAD");
\r
594 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
\r
597 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");
\r