e5d32330e433220b6e3c370562ef522c9ab1461e
[dmaap/messagerouter/msgrtr.git] / src / test / java / org / onap / dmaap / mr / cambria / service / impl / TopicServiceImplTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21  package org.onap.dmaap.mr.cambria.service.impl;
22
23 import static org.mockito.Matchers.anyBoolean;
24 import static org.mockito.Matchers.anyInt;
25 import static org.mockito.Matchers.anyString;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
29
30 import java.io.IOException;
31 import java.util.Arrays;
32 import java.util.HashSet;
33
34 import javax.servlet.ServletOutputStream;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37
38 import org.json.JSONArray;
39 import org.json.JSONException;
40 import org.json.JSONObject;
41 import org.junit.Assert;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.junit.runner.RunWith;
45 import org.mockito.Mock;
46 import org.mockito.MockitoAnnotations;
47 import org.powermock.api.mockito.PowerMockito;
48 import org.powermock.core.classloader.annotations.PrepareForTest;
49 import org.powermock.modules.junit4.PowerMockRunner;
50
51 import com.att.ajsc.beans.PropertiesMapBean;
52 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
53 import org.onap.dmaap.dmf.mr.CambriaApiException;
54 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
55 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
56 import org.onap.dmaap.dmf.mr.beans.TopicBean;
57 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
58 import org.onap.dmaap.dmf.mr.exception.DMaaPAccessDeniedException;
59 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
60 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
61 import org.onap.dmaap.dmf.mr.metabroker.Topic;
62 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
63 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
64 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticatorImpl;
65 import org.onap.dmaap.dmf.mr.service.impl.TopicServiceImpl;
66 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
67 import org.onap.dmaap.dmf.mr.utils.DMaaPResponseBuilder;
68 import com.att.nsa.configs.ConfigDbException;
69 import com.att.nsa.security.NsaAcl;
70 import com.att.nsa.security.NsaApiKey;
71 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
72 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
73
74 //@RunWith(MockitoJUnitRunner.class)
75 @RunWith(PowerMockRunner.class)
76 @PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })
77 public class TopicServiceImplTest {
78
79         TopicServiceImpl topicService;
80
81         @Mock
82         private DMaaPErrorMessages errorMessages;
83
84         @Mock
85         DMaaPContext dmaapContext;
86
87         @Mock
88         ConfigurationReader configReader;
89
90         @Mock
91         ServletOutputStream oStream;
92
93         @Mock
94         DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
95
96         @Mock
97         DMaaPAAFAuthenticator dmaapAAFauthenticator;
98         @Mock
99         NsaApiKey user;
100
101         @Mock
102         NsaSimpleApiKey nsaSimpleApiKey;
103
104         @Mock
105         HttpServletRequest httpServReq;
106
107         @Mock
108         HttpServletResponse httpServRes;
109
110         @Mock
111         DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
112
113         @Mock
114         Topic createdTopic;
115
116         @Mock
117         NsaAcl nsaAcl;
118
119         @Mock
120         JSONObject jsonObj;
121
122         @Mock
123         JSONArray jsonArray;
124
125         @Before
126         public void setUp() {
127                 MockitoAnnotations.initMocks(this);
128                 topicService = new TopicServiceImpl();
129                 topicService.setErrorMessages(errorMessages);
130                 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");
131                 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);
132                 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);
133         }
134
135         @Test(expected = NullPointerException.class)
136         public void testCreateTopicWithEnforcedName()
137                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
138                 
139                 Assert.assertNotNull(topicService);
140                 PowerMockito.mockStatic(PropertiesMapBean.class);
141
142                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
143                                 .thenReturn("enfTopicName");
144
145                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
146                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
147                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
148                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
149                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
150                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
151
152                 TopicBean topicBean = new TopicBean();
153                 topicBean.setTopicName("enfTopicNamePlusExtra");
154                 topicService.createTopic(dmaapContext, topicBean);
155         }
156
157         @Test
158         public void testCreateTopicWithTopicNameNotEnforced()
159                         throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException {
160
161                 Assert.assertNotNull(topicService);
162
163                 PowerMockito.mockStatic(PropertiesMapBean.class);
164                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
165
166                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
167                                 .thenReturn("enfTopicName");
168
169                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
170                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
171
172                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
173                 when(httpServReq.getMethod()).thenReturn("HEAD");
174
175                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
176                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
177                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
178                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
179
180                 when(nsaAcl.isActive()).thenReturn(true);
181                 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
182
183                 when(createdTopic.getName()).thenReturn("topicName");
184                 when(createdTopic.getOwner()).thenReturn("Owner");
185                 when(createdTopic.getDescription()).thenReturn("Description");
186                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
187                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
188
189                 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
190                                 .thenReturn(createdTopic);
191
192                 TopicBean topicBean = new TopicBean();
193                 topicBean.setTopicName("NotEnforcedTopicName");
194
195                 topicService.createTopic(dmaapContext, topicBean);
196
197                 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
198                                 anyBoolean());
199         }
200
201         @Test(expected = NullPointerException.class)
202         public void testCreateTopicNoUserInContextAndNoAuthHeader()
203                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
204                 
205                 Assert.assertNotNull(topicService);
206
207                 PowerMockito.mockStatic(PropertiesMapBean.class);
208
209                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
210                                 .thenReturn("enfTopicName");
211
212                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
213                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
214                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
215                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
216
217                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
218                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
219
220                 TopicBean topicBean = new TopicBean();
221                 topicBean.setTopicName("enfTopicNamePlusExtra");
222                 topicService.createTopic(dmaapContext, topicBean);
223         }
224
225         @Test(expected = NullPointerException.class)
226         public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
227                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
228                 
229                 Assert.assertNotNull(topicService);
230
231                 PowerMockito.mockStatic(PropertiesMapBean.class);
232
233                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
234                                 .thenReturn("enfTopicName");
235
236                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
237                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
238                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
239                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
240
241                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
242                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
243
244                 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
245                 // anyString())).thenReturn(false);
246
247                 TopicBean topicBean = new TopicBean();
248                 topicBean.setTopicName("enfTopicNamePlusExtra");
249                 topicService.createTopic(dmaapContext, topicBean);
250         }
251
252         @Test(expected = TopicExistsException.class)
253         public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
254                         TopicExistsException, JSONException, ConfigDbException {
255
256                 Assert.assertNotNull(topicService);
257                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
258                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
259                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
260                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
261                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
262                 when(httpServReq.getMethod()).thenReturn("HEAD");
263
264                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
265
266                 topicService.getTopic(dmaapContext, "topicName");
267         }
268
269         @Test
270         public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
271                         TopicExistsException, JSONException, ConfigDbException {
272
273                 Assert.assertNotNull(topicService);
274                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
275                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
276                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
277                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
278                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
279
280                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
281
282                 when(createdTopic.getName()).thenReturn("topicName");
283                 when(createdTopic.getDescription()).thenReturn("topicDescription");
284                 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
285
286                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
287                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
288
289                 when(httpServReq.getMethod()).thenReturn("HEAD");
290
291                 when(httpServRes.getOutputStream()).thenReturn(oStream);
292
293                 topicService.getTopic(dmaapContext, "topicName");
294         }
295
296         @Test(expected = TopicExistsException.class)
297         public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
298                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
299
300                 Assert.assertNotNull(topicService);
301
302                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
303                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
304                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
305                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
306                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
307                 when(httpServReq.getMethod()).thenReturn("HEAD");
308
309                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
310
311                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
312
313         }
314
315         @Test
316         public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
317                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
318
319                 Assert.assertNotNull(topicService);
320
321                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
322                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
323                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
324                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
325                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
326                 when(httpServReq.getMethod()).thenReturn("HEAD");
327
328                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
329                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
330                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
331         }
332
333         @Test(expected = TopicExistsException.class)
334         public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
335                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
336
337                 Assert.assertNotNull(topicService);
338
339                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
340                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
341                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
342                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
343                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
344                 when(httpServReq.getMethod()).thenReturn("HEAD");
345
346                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
347
348                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
349
350         }
351
352         @Test
353         public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
354                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
355
356                 Assert.assertNotNull(topicService);
357
358                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
359                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
360                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
361                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
362                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
363                 when(httpServReq.getMethod()).thenReturn("HEAD");
364
365                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
366
367                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
368
369                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
370         }
371
372         @Test
373         public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
374                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
375
376                 Assert.assertNotNull(topicService);
377
378                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
379
380                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
381
382                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
383                                 .thenReturn("topicFactoryAAF");
384
385                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
386                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
387                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
388                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
389                 when(httpServReq.getMethod()).thenReturn("HEAD");
390
391                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
392
393                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
394
395                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
396         }
397         
398         @Test(expected=TopicExistsException.class)
399         public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
400                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
401
402                 Assert.assertNotNull(topicService);
403
404                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
405
406                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
407
408                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
409                                 .thenReturn("topicFactoryAAF");
410
411                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
412                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
413                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
414                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
415                 when(httpServReq.getMethod()).thenReturn("HEAD");
416
417                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
418
419                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
420
421                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
422         }
423
424         @Test
425         public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
426                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
427
428                 Assert.assertNotNull(topicService);
429
430                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
431                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
432                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
433                                 .thenReturn("hello");
434
435                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
436                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
437                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
438                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
439
440                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
441                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
442                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
443                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
444                 TopicBean topicBean = new TopicBean();
445                 topicBean.setTopicName("enfTopicNamePlusExtra");
446
447                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
448         }
449         
450         @Test(expected=TopicExistsException.class)
451         public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
452                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
453
454                 Assert.assertNotNull(topicService);
455
456                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
457                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
458                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
459                                 .thenReturn("hello");
460
461                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
462                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
463                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
464                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
465
466                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
467                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
468                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
469                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
470                 TopicBean topicBean = new TopicBean();
471                 topicBean.setTopicName("enfTopicNamePlusExtra");
472
473                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
474         }
475         
476         /*@Test(expected=DMaaPAccessDeniedException.class)
477         public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
478                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
479
480                 Assert.assertNotNull(topicService);
481
482                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
483                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
484                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
485                                 .thenReturn("hello");
486
487                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
488                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
489                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
490                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
491
492                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
493                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
494                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
495                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
496                 TopicBean topicBean = new TopicBean();
497                 topicBean.setTopicName("enfTopicNamePlusExtra");
498                 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
499                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
500         }*/
501         
502         @Test
503         public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
504                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
505
506                 Assert.assertNotNull(topicService);
507
508                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
509                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
510                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
511                                 .thenReturn("hello");
512
513                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
514                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
515                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
516                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
517
518                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
519                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
520                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
521                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
522                 TopicBean topicBean = new TopicBean();
523                 topicBean.setTopicName("enfTopicNamePlusExtra");
524
525                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
526         }
527         
528         @Test(expected=TopicExistsException.class)
529         public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
530                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
531
532                 Assert.assertNotNull(topicService);
533
534                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
535                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
536                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
537                                 .thenReturn("hello");
538
539                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
540                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
541                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
542                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
543
544                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
545                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
546                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
547                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
548                 TopicBean topicBean = new TopicBean();
549                 topicBean.setTopicName("enfTopicNamePlusExtra");
550
551                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
552         }
553         
554         @Test
555         public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
556                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
557
558                 Assert.assertNotNull(topicService);
559
560                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
561                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
562                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
563                                 .thenReturn("hello");
564
565                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
566                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
567                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
568                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
569
570                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
571                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
572                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
573                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
574                 TopicBean topicBean = new TopicBean();
575                 topicBean.setTopicName("enfTopicNamePlusExtra");
576
577                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
578         }
579         
580         @Test(expected=TopicExistsException.class)
581         public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
582                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
583
584                 Assert.assertNotNull(topicService);
585
586                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
587                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
588                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
589                                 .thenReturn("hello");
590
591                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
592                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
593                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
594                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
595
596                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
597                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
598                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
599                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
600                 TopicBean topicBean = new TopicBean();
601                 topicBean.setTopicName("enfTopicNamePlusExtra");
602
603                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
604         }
605         
606         
607         @Test
608         public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
609                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
610
611                 Assert.assertNotNull(topicService);
612
613                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
614                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
615                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
616                                 .thenReturn("hello");
617
618                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
619                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
620                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
621                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
622
623                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
624                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
625                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
626                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
627                 TopicBean topicBean = new TopicBean();
628                 topicBean.setTopicName("enfTopicNamePlusExtra");
629
630                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
631         }
632         
633         @Test(expected=TopicExistsException.class)
634         public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
635                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
636
637                 Assert.assertNotNull(topicService);
638
639                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
640                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
641                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
642                                 .thenReturn("hello");
643
644                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
645                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
646                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
647                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
648
649                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
650                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
651                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
652                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
653                 TopicBean topicBean = new TopicBean();
654                 topicBean.setTopicName("enfTopicNamePlusExtra");
655
656                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
657         }
658         
659         @Test
660         public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
661                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
662
663                 Assert.assertNotNull(topicService);
664
665                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
666                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
667                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
668                                 .thenReturn("hello");
669
670                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
671                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
672                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
673                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
674                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
675
676                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
677                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
678                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
679                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
680                 TopicBean topicBean = new TopicBean();
681                 topicBean.setTopicName("enfTopicNamePlusExtra");
682
683                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
684         }
685         
686         @Test(expected=TopicExistsException.class)
687         public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
688                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
689
690                 Assert.assertNotNull(topicService);
691
692                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
693                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
694                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
695                                 .thenReturn("hello");
696
697                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
698                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
699                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
700                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
701
702                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
703                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
704                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
705                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
706                 TopicBean topicBean = new TopicBean();
707                 topicBean.setTopicName("enfTopicNamePlusExtra");
708
709                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
710         }
711         
712         @Test
713         public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
714                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
715
716                 Assert.assertNotNull(topicService);
717
718                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
719                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
720                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
721                                 .thenReturn("hello");
722                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
723                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
724                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
725                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
726                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
727
728                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
729                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
730                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
731                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
732                 TopicBean topicBean = new TopicBean();
733                 topicBean.setTopicName("enfTopicNamePlusExtra");
734
735                 topicService.getAllTopics(dmaapContext);
736         }
737         
738         @Test
739         public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
740                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
741
742                 Assert.assertNotNull(topicService);
743
744                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
745                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
746                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
747                                 .thenReturn("hello");
748                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
749                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
750                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
751                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
752                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
753
754                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
755                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
756                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
757                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
758                 TopicBean topicBean = new TopicBean();
759                 topicBean.setTopicName("enfTopicNamePlusExtra");
760
761                 topicService.getTopics(dmaapContext);
762         }
763         
764
765
766 }