add configurable default partitions and replicas
[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                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
145                 .thenReturn("1");
146                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
147                 .thenReturn("1");
148
149                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
150                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
151                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
152                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
153                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
154                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
155
156                 TopicBean topicBean = new TopicBean();
157                 topicBean.setTopicName("enfTopicNamePlusExtra");
158                 topicService.createTopic(dmaapContext, topicBean);
159         }
160
161         @Test
162         public void testCreateTopicWithTopicNameNotEnforced()
163                         throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, org.onap.dmaap.dmf.mr.metabroker.Broker1.TopicExistsException {
164
165                 Assert.assertNotNull(topicService);
166
167                 PowerMockito.mockStatic(PropertiesMapBean.class);
168                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
169
170                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
171                                 .thenReturn("enfTopicName");
172                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
173                 .thenReturn("1");
174                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
175                 .thenReturn("1");
176                 
177                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
178                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
179
180                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
181                 when(httpServReq.getMethod()).thenReturn("HEAD");
182
183                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);
184                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
185                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
186                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
187
188                 when(nsaAcl.isActive()).thenReturn(true);
189                 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
190
191                 when(createdTopic.getName()).thenReturn("topicName");
192                 when(createdTopic.getOwner()).thenReturn("Owner");
193                 when(createdTopic.getDescription()).thenReturn("Description");
194                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
195                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
196
197                 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))
198                                 .thenReturn(createdTopic);
199
200                 TopicBean topicBean = new TopicBean();
201                 topicBean.setTopicName("NotEnforcedTopicName");
202
203                 topicService.createTopic(dmaapContext, topicBean);
204
205                 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),
206                                 anyBoolean());
207         }
208
209         @Test(expected = NullPointerException.class)
210         public void testCreateTopicNoUserInContextAndNoAuthHeader()
211                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
212                 
213                 Assert.assertNotNull(topicService);
214
215                 PowerMockito.mockStatic(PropertiesMapBean.class);
216
217                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
218                                 .thenReturn("enfTopicName");
219                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
220                 .thenReturn("1");
221                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
222                 .thenReturn("1");
223
224                 when(httpServReq.getHeader("Authorization")).thenReturn(null);
225                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
226                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
227                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
228
229                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
230                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
231
232                 TopicBean topicBean = new TopicBean();
233                 topicBean.setTopicName("enfTopicNamePlusExtra");
234                 topicService.createTopic(dmaapContext, topicBean);
235         }
236
237         @Test(expected = NullPointerException.class)
238         public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()
239                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {
240                 
241                 Assert.assertNotNull(topicService);
242
243                 PowerMockito.mockStatic(PropertiesMapBean.class);
244
245                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))
246                                 .thenReturn("enfTopicName");
247                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.partitions"))
248                 .thenReturn("1");
249                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "default.replicas"))
250                 .thenReturn("1");
251
252                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
253                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
254                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
255                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
256
257                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
258                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
259
260                 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,
261                 // anyString())).thenReturn(false);
262
263                 TopicBean topicBean = new TopicBean();
264                 topicBean.setTopicName("enfTopicNamePlusExtra");
265                 topicService.createTopic(dmaapContext, topicBean);
266         }
267
268         @Test(expected = TopicExistsException.class)
269         public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
270                         TopicExistsException, JSONException, ConfigDbException {
271
272                 Assert.assertNotNull(topicService);
273                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
274                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
275                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
276                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
277                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
278                 when(httpServReq.getMethod()).thenReturn("HEAD");
279
280                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
281
282                 topicService.getTopic(dmaapContext, "topicName");
283         }
284
285         @Test
286         public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
287                         TopicExistsException, JSONException, ConfigDbException {
288
289                 Assert.assertNotNull(topicService);
290                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
291                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
292                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
293                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
294                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
295
296                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);
297
298                 when(createdTopic.getName()).thenReturn("topicName");
299                 when(createdTopic.getDescription()).thenReturn("topicDescription");
300                 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));
301
302                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
303                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
304
305                 when(httpServReq.getMethod()).thenReturn("HEAD");
306
307                 when(httpServRes.getOutputStream()).thenReturn(oStream);
308
309                 topicService.getTopic(dmaapContext, "topicName");
310         }
311
312         @Test(expected = TopicExistsException.class)
313         public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
314                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
315
316                 Assert.assertNotNull(topicService);
317
318                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
319                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
320                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
321                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
322                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
323                 when(httpServReq.getMethod()).thenReturn("HEAD");
324
325                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
326
327                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
328
329         }
330
331         @Test
332         public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
333                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
334
335                 Assert.assertNotNull(topicService);
336
337                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
338                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
339                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
340                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
341                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
342                 when(httpServReq.getMethod()).thenReturn("HEAD");
343
344                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
345                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);
346                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
347         }
348
349         @Test(expected = TopicExistsException.class)
350         public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
351                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
352
353                 Assert.assertNotNull(topicService);
354
355                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
356                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
357                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
358                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
359                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
360                 when(httpServReq.getMethod()).thenReturn("HEAD");
361
362                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
363
364                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
365
366         }
367
368         @Test
369         public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,
370                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
371
372                 Assert.assertNotNull(topicService);
373
374                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
375                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
376                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
377                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
378                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
379                 when(httpServReq.getMethod()).thenReturn("HEAD");
380
381                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
382
383                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
384
385                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");
386         }
387
388         @Test
389         public void testGetPublishersByTopicName() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
390                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
391
392                 Assert.assertNotNull(topicService);
393
394                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
395
396                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
397
398                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
399                                 .thenReturn("topicFactoryAAF");
400
401                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
402                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
403                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
404                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
405                 when(httpServReq.getMethod()).thenReturn("HEAD");
406
407                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);
408
409                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
410
411                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
412         }
413         
414         @Test(expected=TopicExistsException.class)
415         public void testGetPublishersByTopicNameError() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
416                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
417
418                 Assert.assertNotNull(topicService);
419
420                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
421
422                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
423
424                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
425                                 .thenReturn("topicFactoryAAF");
426
427                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
428                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
429                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
430                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
431                 when(httpServReq.getMethod()).thenReturn("HEAD");
432
433                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);
434
435                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);
436
437                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");
438         }
439
440         @Test
441         public void testdeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
442                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
443
444                 Assert.assertNotNull(topicService);
445
446                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
447                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
448                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
449                                 .thenReturn("hello");
450
451                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
452                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
453                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
454                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
455
456                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
457                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
458                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
459                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
460                 TopicBean topicBean = new TopicBean();
461                 topicBean.setTopicName("enfTopicNamePlusExtra");
462
463                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
464         }
465         
466         @Test(expected=TopicExistsException.class)
467         public void testdeleteTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
468                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
469
470                 Assert.assertNotNull(topicService);
471
472                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
473                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
474                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
475                                 .thenReturn("hello");
476
477                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
478                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
479                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
480                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
481
482                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
483                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
484                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
485                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
486                 TopicBean topicBean = new TopicBean();
487                 topicBean.setTopicName("enfTopicNamePlusExtra");
488
489                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
490         }
491         
492         /*@Test(expected=DMaaPAccessDeniedException.class)
493         public void testdeleteTopic_authHeader() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
494                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
495
496                 Assert.assertNotNull(topicService);
497
498                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
499                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
500                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
501                                 .thenReturn("hello");
502
503                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
504                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
505                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
506                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
507
508                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
509                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
510                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
511                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
512                 TopicBean topicBean = new TopicBean();
513                 topicBean.setTopicName("enfTopicNamePlusExtra");
514                 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(null);
515                 topicService.deleteTopic(dmaapContext, "topicNamespace.topic");
516         }*/
517         
518         @Test
519         public void testPermitConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
520                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
521
522                 Assert.assertNotNull(topicService);
523
524                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
525                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
526                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
527                                 .thenReturn("hello");
528
529                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
530                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
531                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
532                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
533
534                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
535                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
536                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
537                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
538                 TopicBean topicBean = new TopicBean();
539                 topicBean.setTopicName("enfTopicNamePlusExtra");
540
541                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
542         }
543         
544         @Test(expected=TopicExistsException.class)
545         public void testPermitConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
546                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
547
548                 Assert.assertNotNull(topicService);
549
550                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
551                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
552                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
553                                 .thenReturn("hello");
554
555                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
556                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
557                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
558                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
559
560                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
561                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
562                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
563                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
564                 TopicBean topicBean = new TopicBean();
565                 topicBean.setTopicName("enfTopicNamePlusExtra");
566
567                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
568         }
569         
570         @Test
571         public void testdenyConsumerForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
572                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
573
574                 Assert.assertNotNull(topicService);
575
576                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
577                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
578                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
579                                 .thenReturn("hello");
580
581                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
582                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
583                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
584                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
585
586                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
587                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
588                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
589                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
590                 TopicBean topicBean = new TopicBean();
591                 topicBean.setTopicName("enfTopicNamePlusExtra");
592
593                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
594         }
595         
596         @Test(expected=TopicExistsException.class)
597         public void testdenyConsumerForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
598                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
599
600                 Assert.assertNotNull(topicService);
601
602                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
603                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
604                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
605                                 .thenReturn("hello");
606
607                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
608                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
609                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
610                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
611
612                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
613                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
614                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
615                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
616                 TopicBean topicBean = new TopicBean();
617                 topicBean.setTopicName("enfTopicNamePlusExtra");
618
619                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.topic", "admin");
620         }
621         
622         
623         @Test
624         public void testPermitPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
625                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
626
627                 Assert.assertNotNull(topicService);
628
629                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
630                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
631                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
632                                 .thenReturn("hello");
633
634                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
635                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
636                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
637                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
638
639                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
640                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
641                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
642                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
643                 TopicBean topicBean = new TopicBean();
644                 topicBean.setTopicName("enfTopicNamePlusExtra");
645
646                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
647         }
648         
649         @Test(expected=TopicExistsException.class)
650         public void testPermitPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
651                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
652
653                 Assert.assertNotNull(topicService);
654
655                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
656                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
657                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
658                                 .thenReturn("hello");
659
660                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
661                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
662                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
663                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
664
665                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
666                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
667                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
668                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
669                 TopicBean topicBean = new TopicBean();
670                 topicBean.setTopicName("enfTopicNamePlusExtra");
671
672                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");
673         }
674         
675         @Test
676         public void testDenyPublisherForTopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
677                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
678
679                 Assert.assertNotNull(topicService);
680
681                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
682                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
683                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
684                                 .thenReturn("hello");
685
686                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
687                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
688                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
689                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
690                 when(dmaapContext.getResponse()).thenReturn(httpServRes);
691
692                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
693                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
694                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
695                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
696                 TopicBean topicBean = new TopicBean();
697                 topicBean.setTopicName("enfTopicNamePlusExtra");
698
699                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
700         }
701         
702         @Test(expected=TopicExistsException.class)
703         public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
704                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
705
706                 Assert.assertNotNull(topicService);
707
708                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
709                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
710                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
711                                 .thenReturn("hello");
712
713                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
714                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
715                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
716                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
717
718                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
719                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
720                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
721                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);
722                 TopicBean topicBean = new TopicBean();
723                 topicBean.setTopicName("enfTopicNamePlusExtra");
724
725                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;
726         }
727         
728         @Test
729         public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
730                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
731
732                 Assert.assertNotNull(topicService);
733
734                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
735                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
736                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
737                                 .thenReturn("hello");
738                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
739                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
740                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
741                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
742                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
743
744                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
745                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
746                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
747                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
748                 TopicBean topicBean = new TopicBean();
749                 topicBean.setTopicName("enfTopicNamePlusExtra");
750
751                 topicService.getAllTopics(dmaapContext);
752         }
753         
754         @Test
755         public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,
756                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {
757
758                 Assert.assertNotNull(topicService);
759
760                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);
761                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
762                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))
763                                 .thenReturn("hello");
764                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);
765                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);
766                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");
767                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
768                 when(dmaapContext.getRequest()).thenReturn(httpServReq);
769
770                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);
771                 when(dmaapContext.getConfigReader()).thenReturn(configReader);
772                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
773                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);
774                 TopicBean topicBean = new TopicBean();
775                 topicBean.setTopicName("enfTopicNamePlusExtra");
776
777                 topicService.getTopics(dmaapContext);
778         }
779         
780
781
782 }