commiting code for test coverage
[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.InjectMocks;\r
46 import org.mockito.Mock;\r
47 import org.mockito.MockitoAnnotations;\r
48 import org.powermock.api.mockito.PowerMockito;\r
49 import org.powermock.core.classloader.annotations.PrepareForTest;\r
50 import org.powermock.modules.junit4.PowerMockRunner;\r
51 \r
52 import com.att.ajsc.beans.PropertiesMapBean;\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.utils.ConfigurationReader;\r
65 import com.att.nsa.cambria.utils.DMaaPResponseBuilder;\r
66 import com.att.nsa.configs.ConfigDbException;*/\r
67 import com.att.nsa.security.NsaAcl;\r
68 import com.att.nsa.security.NsaApiKey;\r
69 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;\r
70 import com.att.nsa.security.db.simple.NsaSimpleApiKey;\r
71 \r
72 //@RunWith(MockitoJUnitRunner.class)\r
73 /*@RunWith(PowerMockRunner.class)\r
74 @PrepareForTest({ PropertiesMapBean.class })*/\r
75 public class TopicServiceImplTest {/*\r
76 \r
77         @InjectMocks\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         }\r
128 \r
129         @Test(expected = DMaaPAccessDeniedException.class)\r
130         public void testCreateTopicWithEnforcedName()\r
131                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
132 \r
133                 Assert.assertNotNull(topicService);\r
134 \r
135                 PowerMockito.mockStatic(PropertiesMapBean.class);\r
136 \r
137                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
138                                 .thenReturn("enfTopicName");\r
139 \r
140                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
141                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
142                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
143                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
144                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
145 \r
146                 TopicBean topicBean = new TopicBean();\r
147                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
148 \r
149                 topicService.createTopic(dmaapContext, topicBean);\r
150         }\r
151 \r
152         @Test\r
153         public void testCreateTopicWithTopicNameNotEnforced()\r
154                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
155 \r
156                 Assert.assertNotNull(topicService);\r
157 \r
158                 PowerMockito.mockStatic(PropertiesMapBean.class);\r
159                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
160 \r
161                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
162                                 .thenReturn("enfTopicName");\r
163 \r
164                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
165                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
166 \r
167                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
168                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
169 \r
170                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
171                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
172                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
173                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
174 \r
175                 when(nsaAcl.isActive()).thenReturn(true);\r
176                 when(nsaAcl.getUsers()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));\r
177 \r
178                 when(createdTopic.getName()).thenReturn("topicName");\r
179                 when(createdTopic.getOwner()).thenReturn("Owner");\r
180                 when(createdTopic.getDescription()).thenReturn("Description");\r
181                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);\r
182                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);\r
183 \r
184                 when(dmaapKafkaMetaBroker.createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(), anyBoolean()))\r
185                                 .thenReturn(createdTopic);\r
186 \r
187                 TopicBean topicBean = new TopicBean();\r
188                 topicBean.setTopicName("NotEnforcedTopicName");\r
189 \r
190                 topicService.createTopic(dmaapContext, topicBean);\r
191 \r
192                 verify(dmaapKafkaMetaBroker, times(1)).createTopic(anyString(), anyString(), anyString(), anyInt(), anyInt(),\r
193                                 anyBoolean());\r
194         }\r
195 \r
196         @Test(expected = DMaaPAccessDeniedException.class)\r
197         public void testCreateTopicNoUserInContextAndNoAuthHeader()\r
198                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
199 \r
200                 Assert.assertNotNull(topicService);\r
201 \r
202                 PowerMockito.mockStatic(PropertiesMapBean.class);\r
203 \r
204                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
205                                 .thenReturn("enfTopicName");\r
206 \r
207                 when(httpServReq.getHeader("Authorization")).thenReturn(null);\r
208                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
209                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
210 \r
211                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
212                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
213 \r
214                 TopicBean topicBean = new TopicBean();\r
215                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
216 \r
217                 topicService.createTopic(dmaapContext, topicBean);\r
218         }\r
219 \r
220         @Test(expected = DMaaPAccessDeniedException.class)\r
221         public void testCreateTopicNoUserInContextAndAuthHeaderAndPermitted()\r
222                         throws DMaaPAccessDeniedException, CambriaApiException, IOException, TopicExistsException {\r
223 \r
224                 Assert.assertNotNull(topicService);\r
225 \r
226                 PowerMockito.mockStatic(PropertiesMapBean.class);\r
227 \r
228                 when(PropertiesMapBean.getProperty(CambriaConstants.msgRtr_prop, "enforced.topic.name.AAF"))\r
229                                 .thenReturn("enfTopicName");\r
230 \r
231                 when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");\r
232                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
233                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(null);\r
234 \r
235                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
236                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
237 \r
238                 // when(dmaapAAFauthenticator.aafAuthentication(httpServReq,\r
239                 // anyString())).thenReturn(false);\r
240 \r
241                 TopicBean topicBean = new TopicBean();\r
242                 topicBean.setTopicName("enfTopicNamePlusExtra");\r
243 \r
244                 topicService.createTopic(dmaapContext, topicBean);\r
245         }\r
246 \r
247         @Test(expected = TopicExistsException.class)\r
248         public void testGetTopics_null_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
249                         TopicExistsException, JSONException, ConfigDbException {\r
250 \r
251                 Assert.assertNotNull(topicService);\r
252                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
253                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
254                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
255                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
256                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
257                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
258 \r
259                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);\r
260 \r
261                 topicService.getTopic(dmaapContext, "topicName");\r
262         }\r
263 \r
264         @Test\r
265         public void testGetTopics_NonNull_topic() throws DMaaPAccessDeniedException, CambriaApiException, IOException,\r
266                         TopicExistsException, JSONException, ConfigDbException {\r
267 \r
268                 Assert.assertNotNull(topicService);\r
269                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
270                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
271                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
272                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
273                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
274 \r
275                 when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(createdTopic);\r
276 \r
277                 when(createdTopic.getName()).thenReturn("topicName");\r
278                 when(createdTopic.getDescription()).thenReturn("topicDescription");\r
279                 when(createdTopic.getOwners()).thenReturn(new HashSet<>(Arrays.asList("user1,user2".split(","))));\r
280 \r
281                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);\r
282                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);\r
283 \r
284                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
285 \r
286                 when(httpServRes.getOutputStream()).thenReturn(oStream);\r
287 \r
288                 topicService.getTopic(dmaapContext, "topicName");\r
289         }\r
290 \r
291         @Test(expected = TopicExistsException.class)\r
292         public void testGetPublishersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
293                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
294 \r
295                 Assert.assertNotNull(topicService);\r
296 \r
297                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
298                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
299                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
300                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
301                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
302                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
303 \r
304                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
305 \r
306                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");\r
307 \r
308         }\r
309 \r
310         @Test\r
311         public void testGetPublishersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
312                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
313 \r
314                 Assert.assertNotNull(topicService);\r
315 \r
316                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
317                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
318                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
319                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
320                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
321                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
322 \r
323                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
324                 when(createdTopic.getWriterAcl()).thenReturn(nsaAcl);\r
325                 topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");\r
326         }\r
327         \r
328         @Test(expected = TopicExistsException.class)\r
329         public void testGetConsumersByTopicName_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
330                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
331 \r
332                 Assert.assertNotNull(topicService);\r
333 \r
334                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
335                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
336                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
337                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
338                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
339                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
340 \r
341                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
342 \r
343                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");\r
344 \r
345         }\r
346 \r
347         @Test\r
348         public void testGetConsumersByTopicName_nonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
349                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
350 \r
351                 Assert.assertNotNull(topicService);\r
352 \r
353                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
354                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
355                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
356                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
357                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
358                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
359 \r
360                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
361                 \r
362                 when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);\r
363 \r
364                 topicService.getConsumersByTopicName(dmaapContext, "topicNamespace.name");\r
365         }\r
366         \r
367 //      @Test\r
368 //      public void testDeleteTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
369 //                      IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
370 //\r
371 //              Assert.assertNotNull(topicService);\r
372 //\r
373 //              PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
374 //              \r
375 //               PowerMockito.mockStatic(AJSCPropertiesMap.class);\r
376 //               \r
377 //               PowerMockito.when(AJSCPropertiesMap.\r
378 //                               getProperty(CambriaConstants.msgRtr_prop,"msgRtr.topicfactory.aaf")).thenReturn("topicFactoryAAF");\r
379 //              \r
380 //              \r
381 //              when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
382 //              when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
383 //              when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
384 //              when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
385 //              when(httpServReq.getMethod()).thenReturn("HEAD");\r
386 //\r
387 //              when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
388 //              \r
389 //              when(createdTopic.getReaderAcl()).thenReturn(nsaAcl);\r
390 //\r
391 //              topicService.getPublishersByTopicName(dmaapContext, "topicNamespace.name");\r
392 //      }\r
393 //      \r
394 //      \r
395 //      \r
396         \r
397         @Test(expected = TopicExistsException.class)\r
398         public void testPermitPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
399                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
400 \r
401                 Assert.assertNotNull(topicService);\r
402 \r
403                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
404                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
405                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
406                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
407                 \r
408                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
409                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
410                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
411                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
412                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
413                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
414 \r
415                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
416 \r
417                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");\r
418         }\r
419         \r
420         @Test\r
421         public void testPermitPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
422                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
423 \r
424                 Assert.assertNotNull(topicService);\r
425 \r
426                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
427                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
428                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
429                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
430                 \r
431                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
432                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
433                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
434                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
435                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
436                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
437 \r
438                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
439                 \r
440                 \r
441                 topicService.permitPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");\r
442         }\r
443         \r
444         \r
445         @Test(expected = TopicExistsException.class)\r
446         public void testDenyPublisherForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
447                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
448 \r
449                 Assert.assertNotNull(topicService);\r
450 \r
451                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
452                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
453                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
454                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
455                 \r
456                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
457                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
458                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
459                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
460                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
461                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
462 \r
463                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
464 \r
465                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");\r
466         }\r
467         \r
468         @Test\r
469         public void testDenyPublisherForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
470                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
471 \r
472                 Assert.assertNotNull(topicService);\r
473 \r
474                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
475                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
476                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
477                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
478                 \r
479                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
480                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
481                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
482                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
483                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
484                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
485 \r
486                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
487                 \r
488                 \r
489                 topicService.denyPublisherForTopic(dmaapContext, "topicNamespace.name", "producerId");\r
490         }\r
491         \r
492         @Test(expected = TopicExistsException.class)\r
493         public void testPermitConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
494                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
495 \r
496                 Assert.assertNotNull(topicService);\r
497 \r
498                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
499                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
500                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
501                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
502                 \r
503                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
504                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
505                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
506                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
507                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
508                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
509 \r
510                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
511 \r
512                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");\r
513         }\r
514         \r
515         @Test\r
516         public void testPermitConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
517                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
518 \r
519                 Assert.assertNotNull(topicService);\r
520 \r
521                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
522                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
523                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
524                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
525                 \r
526                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
527                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
528                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
529                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
530                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
531                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
532 \r
533                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
534                 \r
535                 \r
536                 topicService.permitConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");\r
537         }\r
538         \r
539         \r
540         @Test(expected = TopicExistsException.class)\r
541         public void testDenyConsumerForTopic_nullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
542                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
543 \r
544                 Assert.assertNotNull(topicService);\r
545 \r
546                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
547                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
548                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
549                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
550                 \r
551                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
552                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
553                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
554                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
555                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
556                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
557 \r
558                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(null);\r
559 \r
560                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");\r
561         }\r
562         \r
563         @Test\r
564         public void testDenyConsumerForTopic_NonNullTopic() throws DMaaPAccessDeniedException, CambriaApiException,\r
565                         IOException, TopicExistsException, JSONException, ConfigDbException, AccessDeniedException {\r
566 \r
567                 Assert.assertNotNull(topicService);\r
568 \r
569                 when(httpServReq.getHeader("AppName")).thenReturn("MyApp");\r
570                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
571                 when(configReader.getfSecurityManager()).thenReturn(dmaaPAuthenticator);\r
572                 when(dmaaPAuthenticator.authenticate(dmaapContext)).thenReturn(nsaSimpleApiKey);\r
573                 \r
574                 PowerMockito.mockStatic(DMaaPResponseBuilder.class);\r
575                 when(dmaapContext.getConfigReader()).thenReturn(configReader);\r
576                 when(dmaapContext.getRequest()).thenReturn(httpServReq);\r
577                 when(dmaapContext.getResponse()).thenReturn(httpServRes);\r
578                 when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);\r
579                 when(httpServReq.getMethod()).thenReturn("HEAD");\r
580 \r
581                 when(dmaapKafkaMetaBroker.getTopic("topicNamespace.name")).thenReturn(createdTopic);\r
582                 \r
583                 \r
584                 topicService.denyConsumerForTopic(dmaapContext, "topicNamespace.name", "consumerID");\r
585         }\r
586 */}\r