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