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