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