47b351e98f02c804021ff377f793c1160286311d
[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.dmf.mr.CambriaApiException;\r
54 import com.att.dmf.mr.beans.DMaaPContext;\r
55 import com.att.dmf.mr.beans.DMaaPKafkaMetaBroker;\r
56 import com.att.dmf.mr.beans.TopicBean;\r
57 import com.att.dmf.mr.constants.CambriaConstants;\r
58 import com.att.dmf.mr.exception.DMaaPAccessDeniedException;\r
59 import com.att.dmf.mr.exception.DMaaPErrorMessages;\r
60 import com.att.dmf.mr.metabroker.Broker.TopicExistsException;\r
61 import com.att.dmf.mr.metabroker.Topic;\r
62 import com.att.dmf.mr.security.DMaaPAAFAuthenticator;\r
63 import com.att.dmf.mr.security.DMaaPAuthenticator;\r
64 import com.att.dmf.mr.security.DMaaPAuthenticatorImpl;\r
65 import com.att.dmf.mr.service.impl.TopicServiceImpl;\r
66 import com.att.dmf.mr.utils.ConfigurationReader;\r
67 import com.att.dmf.mr.utils.DMaaPResponseBuilder;\r
68 import com.att.nsa.configs.ConfigDbException;\r
69 import com.att.nsa.security.NsaAcl;\r
70 import com.att.nsa.security.NsaApiKey;\r
71 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
72 import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
73 \r
74 //@RunWith(MockitoJUnitRunner.class)\r
75 @RunWith(PowerMockRunner.class)\r
76 @PrepareForTest({ PropertiesMapBean.class, DMaaPAuthenticatorImpl.class,AJSCPropertiesMap.class,DMaaPResponseBuilder.class })\r
77 public class TopicServiceImplTest {\r
78 \r
79         TopicServiceImpl topicService;\r
80 \r
81         @Mock\r
82         private DMaaPErrorMessages errorMessages;\r
83 \r
84         @Mock\r
85         DMaaPContext dmaapContext;\r
86 \r
87         @Mock\r
88         ConfigurationReader configReader;\r
89 \r
90         @Mock\r
91         ServletOutputStream oStream;\r
92 \r
93         @Mock\r
94         DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;\r
95 \r
96         @Mock\r
97         DMaaPAAFAuthenticator dmaapAAFauthenticator;\r
98         @Mock\r
99         NsaApiKey user;\r
100 \r
101         @Mock\r
102         NsaSimpleApiKey nsaSimpleApiKey;\r
103 \r
104         @Mock\r
105         HttpServletRequest httpServReq;\r
106 \r
107         @Mock\r
108         HttpServletResponse httpServRes;\r
109 \r
110         @Mock\r
111         DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;\r
112 \r
113         @Mock\r
114         Topic createdTopic;\r
115 \r
116         @Mock\r
117         NsaAcl nsaAcl;\r
118 \r
119         @Mock\r
120         JSONObject jsonObj;\r
121 \r
122         @Mock\r
123         JSONArray jsonArray;\r
124 \r
125         @Before\r
126         public void setUp() {\r
127                 MockitoAnnotations.initMocks(this);\r
128                 topicService = new TopicServiceImpl();\r
129                 topicService.setErrorMessages(errorMessages);\r
130                 NsaSimpleApiKey user = new NsaSimpleApiKey("admin", "password");\r
131                 PowerMockito.mockStatic(DMaaPAuthenticatorImpl.class);\r
132                 PowerMockito.when(DMaaPAuthenticatorImpl.getAuthenticatedUser(dmaapContext)).thenReturn(user);\r
133         }\r
134 \r
135         @Test(expected = NullPointerException.class)\r
136         public void testCreateTopicWithEnforcedName()\r
137                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
138                 \r
139                 Assert.assertNotNull(topicService);\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(dmaapContext.getResponse()).thenReturn(httpServRes);\r
148                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
149                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
150                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
151 \r
152                 TopicBean topicBean = new TopicBean();\r
153                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
154                 topicService.createTopic(dmaapContext, topicBean);\r
155         }\r
156 \r
157         @Test\r
158         public void testCreateTopicWithTopicNameNotEnforced()\r
159                         throws DMaaPAccessDeniedException, CambriaApiException, ConfigDbException,IOException,TopicExistsException, com.att.dmf.mr.metabroker.Broker1.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 = NullPointerException.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(dmaapContext.getResponse()).thenReturn(httpServRes);\r
215                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
216 \r
217                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
218                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
219 \r
220                 TopicBean topicBean = new TopicBean();\r
221                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
222                 topicService.createTopic(dmaapContext, topicBean);\r
223         }\r
224 \r
225         @Test(expected = NullPointerException.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(dmaapContext.getResponse()).thenReturn(httpServRes);\r
239                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
240 \r
241                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
242                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
243 \r
244                 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,\r
245                 // anyString())).thenReturn(false);\r
246 \r
247                 TopicBean topicBean = new TopicBean();\r
248                 topicBean.setTopicName("enfTopicNamePlusExtra");\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                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
675 \r
676                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
677                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
678                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
679                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);\r
680                 TopicBean topicBean = new TopicBean();\r
681                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
682 \r
683                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;\r
684         }\r
685         \r
686         @Test(expected=TopicExistsException.class)\r
687         public void testDenyPublisherForTopic_nulltopic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
688                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
689 \r
690                 Assert.assertNotNull(topicService);\r
691 \r
692                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
693                 PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
694                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))\r
695                                 .thenReturn("hello");\r
696 \r
697                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
698                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
699                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
700                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
701 \r
702                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
703                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
704                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
705                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(null);\r
706                 TopicBean topicBean = new TopicBean();\r
707                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
708 \r
709                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.topic", "admin");;\r
710         }\r
711         \r
712         @Test\r
713         public void testGetAllTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
714                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
715 \r
716                 Assert.assertNotNull(topicService);\r
717 \r
718                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
719                 PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
720                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))\r
721                                 .thenReturn("hello");\r
722                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
723                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
724                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
725                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
726                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
727 \r
728                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
729                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
730                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
731                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);\r
732                 TopicBean topicBean = new TopicBean();\r
733                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
734 \r
735                 topicService.getAllTopics(dmaapContext);\r
736         }\r
737         \r
738         @Test\r
739         public void testGetTopics() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
740                         TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
741 \r
742                 Assert.assertNotNull(topicService);\r
743 \r
744                 // PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
745                 PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
746                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.topicfactory.aaf"))\r
747                                 .thenReturn("hello");\r
748                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
749                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
750                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
751                 when(httpServReq.getHeader("Authorization")).thenReturn("Admin");\r
752                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
753 \r
754                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
755                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
756                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
757                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.topic")).thenReturn(createdTopic);\r
758                 TopicBean topicBean = new TopicBean();\r
759                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
760 \r
761                 topicService.getTopics(dmaapContext);\r
762         }\r
763         \r
764 \r
765 \r
766 }\r