eb4ec57bf1f4f5a1cce0bddfe5b9654e1e38d5e1
[dmaap/messagerouter/messageservice.git] / src / test / java / org / onap / dmaap / service / MMRestServiceTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21  package org.onap.dmaap.service;
22
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Matchers.anyString;
26
27 import java.io.ByteArrayInputStream;
28
29 //import static org.mockito.Matchers.anyString;
30 //import static org.mockito.Mockito.when;
31
32 import java.io.IOException;
33 import java.io.InputStream;
34
35 import javax.servlet.ServletOutputStream;
36 import javax.servlet.http.HttpServletRequest;
37 import javax.servlet.http.HttpServletResponse;
38
39 import org.json.JSONArray;
40 import org.json.JSONException;
41 import org.json.JSONObject;
42 import org.junit.After;
43 import org.junit.Assert;
44 import org.junit.Before;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47 import org.mockito.InjectMocks;
48 import org.mockito.Mock;
49 import org.mockito.MockitoAnnotations;
50 import org.mockito.Spy;
51 import org.onap.dmaap.dmf.mr.CambriaApiException;
52 import org.onap.dmaap.dmf.mr.backends.ConsumerFactory.UnavailableException;
53 import org.onap.dmaap.dmf.mr.beans.DMaaPContext;
54 import org.onap.dmaap.dmf.mr.beans.DMaaPKafkaMetaBroker;
55 import org.onap.dmaap.dmf.mr.constants.CambriaConstants;
56 import org.onap.dmaap.dmf.mr.exception.DMaaPErrorMessages;
57 import org.onap.dmaap.dmf.mr.metabroker.Broker.TopicExistsException;
58 import org.onap.dmaap.dmf.mr.metabroker.Topic;
59 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticator;
60 import org.onap.dmaap.dmf.mr.security.DMaaPAAFAuthenticatorImpl;
61 import org.onap.dmaap.dmf.mr.security.DMaaPAuthenticator;
62 import org.onap.dmaap.dmf.mr.service.MMService;
63 import org.onap.dmaap.dmf.mr.utils.ConfigurationReader;
64 import org.onap.dmaap.mmagent.CreateMirrorMaker;
65 import org.onap.dmaap.mmagent.MirrorMaker;
66 import org.onap.dmaap.mmagent.UpdateMirrorMaker;
67 import org.powermock.api.mockito.PowerMockito;
68 import org.powermock.core.classloader.annotations.PowerMockIgnore;
69 import org.powermock.core.classloader.annotations.PrepareForTest;
70 import org.powermock.modules.junit4.PowerMockRunner;
71
72 import com.att.ajsc.beans.PropertiesMapBean;
73 import com.att.ajsc.filemonitor.AJSCPropertiesMap;
74 import com.att.nsa.configs.ConfigDbException;
75 import com.att.nsa.security.NsaAcl;
76 import com.att.nsa.security.NsaApiKey;
77 import com.att.nsa.security.ReadWriteSecuredResource.AccessDeniedException;
78 import com.att.nsa.security.db.simple.NsaSimpleApiKey;
79
80 //@RunWith(MockitoJUnitRunner.class)
81 @RunWith(PowerMockRunner.class)
82 @PowerMockIgnore("jdk.internal.reflect.*")
83 @PrepareForTest({ PropertiesMapBean.class, AJSCPropertiesMap.class })
84 public class MMRestServiceTest {
85
86         @InjectMocks
87         MMRestService mmRestService;
88
89         @Mock
90         private MMService mmservice;
91
92         @Mock
93         CreateMirrorMaker cMirroMaker;
94
95         @Mock
96         UpdateMirrorMaker uMirroMaker;
97
98         private TopicRestService service = new TopicRestService();
99         @Mock
100         private DMaaPErrorMessages errorMessages;
101
102         @Mock
103         DMaaPContext dmaapContext;
104
105         @Mock
106         ConfigurationReader configReader;
107
108         @Mock
109         ServletOutputStream oStream;
110
111         @Mock
112         DMaaPAuthenticator<NsaSimpleApiKey> dmaaPAuthenticator;
113
114         @Mock
115         MirrorMaker mMaker;
116
117         @Mock
118         DMaaPAAFAuthenticator dmaapAAFauthenticator;
119
120         @Mock
121         DMaaPAAFAuthenticatorImpl impl;
122
123         @Mock
124         NsaApiKey user;
125
126         @Mock
127         NsaSimpleApiKey nsaSimpleApiKey;
128
129         @Mock
130         HttpServletRequest httpServReq;
131
132         @Mock
133         HttpServletResponse httpServRes;
134
135         @Mock
136         InputStream iStream;
137
138         @Mock
139         DMaaPKafkaMetaBroker dmaapKafkaMetaBroker;
140
141         @Mock
142         Topic createdTopic;
143
144         @Mock
145         NsaAcl nsaAcl;
146
147         @Mock
148         JSONObject jsonObj;
149
150         @Mock
151         JSONArray jsonArray;
152
153         @Before
154         public void setUp()  {
155
156                 MockitoAnnotations.initMocks(this);
157         }
158
159         @After
160         public void tearDown()  {
161         }
162
163         @Test
164         public void testCallCreateMirrorMaker()  {
165                 prepareForTestCommon();
166
167                 // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
168                 // name:\"test\", consumer:\"test\", producer:\"test\",
169                 // whitelist:\"test\",status:\"test\" }}";
170                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
171                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
172                 try {
173                         mmRestService.callCreateMirrorMaker(inputSteam);
174                 } catch (Exception e) {
175                         assertTrue(true);
176                 }
177                 
178
179         }
180         @Test
181         public void testCallCreateMirrorMaker_error4()  {
182                 try {
183                         prepareForTestCommon();
184                 } catch (Exception e) {
185                         
186                 }
187
188                 // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
189                 // name:\"test\", consumer:\"test\", producer:\"test\",
190                 // whitelist:\"test\",status:\"test\" }}";
191                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
192                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
193                 try {
194                         mmRestService.callCreateMirrorMaker(inputSteam);
195                 } catch (Exception e) {
196                         assertTrue(true);
197                 }
198                 
199
200         }
201         @Test
202         public void testCallCreateMirrorMaker_3()  {
203                 prepareForTestCommon();
204
205                 // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
206                 // name:\"test\", consumer:\"test\", producer:\"test\",
207                 // whitelist:\"test\",status:\"test\" }}";
208                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"\",   consumer:\"test\",  producer:\"test\"}}";
209                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
210         assertTrue(true);
211
212         }
213         @Test
214         public void testCallCreateMirrorMaker_error2()  {
215                 prepareForTestCommon();
216
217                 // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
218                 // name:\"test\", consumer:\"test\", producer:\"test\",
219                 // whitelist:\"test\",status:\"test\" }}";
220                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",whitelist:\"test\"}}";
221                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
222                 try {
223                         mmRestService.callCreateMirrorMaker(inputSteam);
224                 } catch (Exception e) {
225                         assertTrue(true);
226                 }
227                 
228
229         }
230         
231         @Test
232         public void testCallCreateMirrorMaker_error1()  {
233                 prepareForTestCommon();
234
235                 // String sampleJson = ""{ messageID:\"test\", createMirrorMaker: {
236                 // name:\"test\", consumer:\"test\", producer:\"test\",
237                 // whitelist:\"test\",status:\"test\" }}";
238                 String sampleJson = "{ messageID:\"test\"}";
239                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
240                 try {
241                         mmRestService.callCreateMirrorMaker(inputSteam);
242                 } catch (Exception e) {
243                         assertTrue(true);
244                 }
245                 
246
247         }
248
249         @Test
250         public void testCallCreateMirrorMakerCreateAafPermissionError()  {
251                 prepareForTestCommon();
252
253                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
254                         .thenReturn(null);
255                 String sampleJson = "{ messageID:\"test\"}";
256                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
257                 try {
258                         mmRestService.callCreateMirrorMaker(inputSteam);
259                 } catch (Exception e) {
260                         assertTrue(true);
261                 }
262                 
263
264         }
265         
266         @Test
267         public void testCallListAllMirrorMaker()  {
268                 prepareForTestCommon();
269
270                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
271                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
272                 try {
273                         mmRestService.callListAllMirrorMaker(inputSteam);
274                 } catch (Exception e) {
275                         assertTrue(true);
276                 }
277                 
278         }
279
280         @Test
281         public void testCallListAllMirrorMakerPermissionError()  {
282                 prepareForTestCommon();
283                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
284                 .thenReturn(null);
285                 String sampleJson = "{ messageID:\"test\", createMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
286                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
287                 try {
288                         mmRestService.callListAllMirrorMaker(inputSteam);
289                 } catch (Exception e) {
290                         assertTrue(true);
291                 }
292                 
293         }
294         
295         @Test
296         public void testCallUpdateMirrorMaker()  {
297                 prepareForTestCommon();
298
299                 String sampleJson = "{ messageID:\"test\", updateMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
300                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
301                 try {
302                         mmRestService.callUpdateMirrorMaker(inputSteam);
303                 } catch (Exception e) {
304                         assertTrue(true);
305                 }
306                 
307         }
308         
309         @Test
310         public void testCallUpdateMirrorMaker_error1()  {
311                 prepareForTestCommon();
312
313                 String sampleJson = "{ messageID:\"test@1\", updateMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\"}}";
314                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
315                 try {
316                         mmRestService.callUpdateMirrorMaker(inputSteam);
317                 } catch (Exception e) {
318                         assertTrue(true);
319                 }
320                 
321         }
322         @Test
323         public void testCallUpdateMirrorMaker_error2()  {
324                 prepareForTestCommon();
325
326                 String sampleJson = "{ messageID:\"test\", updateMirrorMaker: {   name:\"\",   consumer:\"test\",  producer:\"test\"}}";
327                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
328                 try {
329                         mmRestService.callUpdateMirrorMaker(inputSteam);
330                 } catch (Exception e) {
331                         assertTrue(true);
332                 }
333                 
334         }
335         @Test
336         public void testCallUpdateMirrorMaker_error3() {
337                 prepareForTestCommon();
338
339                 String sampleJson = "{ messageID:\"test\", updateMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\"}}";
340                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
341                 try {
342                         mmRestService.callUpdateMirrorMaker(inputSteam);
343                 } catch (Exception e) {
344                         assertTrue(true);
345                 }
346                 
347         }
348         @Test
349         public void testCallUpdateMirrorMaker_error4()  {
350                 prepareForTestCommon();
351
352                 String sampleJson = "{ messageID:\"test\"}}";
353                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
354                 try {
355                         mmRestService.callUpdateMirrorMaker(inputSteam);
356                 } catch (Exception e) {
357                         assertTrue(true);
358                 }
359                 
360         }
361
362         @Test
363         public void testCallUpdateMirrorMakerAafPermissionError()  {
364                 prepareForTestCommon();
365
366                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
367                         .thenReturn(null);
368                 
369                 String sampleJson = "{ messageID:\"test\"}}";
370                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
371                 try {
372                         mmRestService.callUpdateMirrorMaker(inputSteam);
373                 } catch (Exception e) {
374                         assertTrue(true);
375                 }
376                 
377         }
378         
379         @Test
380         public void testCallDeleteMirrorMaker()  {
381                 prepareForTestCommon();
382
383                 String sampleJson = "{ messageID:\"test\", deleteMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
384                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
385                 try {
386                         mmRestService.callDeleteMirrorMaker(inputSteam);
387                 } catch (JSONException e) {
388                         assertTrue(true);
389                 } catch (Exception e) {
390                         assertTrue(true);
391                 }
392                 
393         }
394
395         
396         @Test
397         public void testCallDeleteMirrorMakerAafPermissionError() {
398                 prepareForTestCommon();
399                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
400                         .thenReturn(null);
401                 String sampleJson = "{ messageID:\"test\", deleteMirrorMaker: {   name:\"test\",   consumer:\"test\",  producer:\"test\",  whitelist:\"test\",status:\"test\" }}";
402                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
403                 try {
404                         mmRestService.callDeleteMirrorMaker(inputSteam);
405                 } catch (JSONException e) {
406                         assertTrue(true);
407                 } catch (Exception e) {
408                         assertTrue(true);
409                 }
410                 
411         }
412         
413         
414         @Test
415         public void testListWhiteList()  {
416                 prepareForTestCommon();
417
418                 String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
419                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
420                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
421
422                 try {
423                         PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
424                         mmRestService.listWhiteList(inputSteam);
425                 } catch (Exception e) {
426                         assertTrue(true);
427                 }
428                 
429         }
430
431         @Test
432         public void testListWhiteListAafPermissionError()  {
433                 prepareForTestCommon();
434
435                 String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
436                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
437                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
438
439                 try {
440                         PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
441                                 .thenReturn(null);
442                         mmRestService.listWhiteList(inputSteam);
443                 } catch (Exception e) {
444                         assertTrue(true);
445                 }
446                 
447         }
448
449         @Test
450         public void testListWhiteListCreatePermissionError()  {
451                 prepareForTestCommon();
452
453                 String sampleJson = "{ name:\"test\", namespace:\"test\"}}";
454                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
455                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
456
457                 try {
458                         PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
459                                 .thenReturn(null);
460                         mmRestService.listWhiteList(inputSteam);
461                 } catch (Exception e) {
462                         assertTrue(true);
463                 }
464                 
465         }
466         @Test
467         public void testListWhiteListJSONError()  {
468                 prepareForTestCommon();
469
470                 String sampleJson = "{ namespace:\"test\"}}";
471                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
472                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
473
474                 try {
475                         mmRestService.listWhiteList(inputSteam);
476                 } catch (Exception e) {
477                         assertTrue(true);
478                 }
479                 
480         }
481         
482         
483         
484         
485         @Test
486         public void testCreateWhiteList()  {
487                 prepareForTestCommon();
488                 
489                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
490                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
491
492                 try {
493                         mmRestService.createWhiteList(inputSteam);
494                 } catch (Exception e) {
495                         assertTrue(true);
496                 }
497                 
498         }
499
500         @Test
501         public void testCreateWhiteListCreatePermissionError()  {
502                 prepareForTestCommon();
503
504                 PowerMockito
505                         .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
506                         .thenReturn(null);
507                 
508                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
509                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
510
511                 try {
512                         mmRestService.createWhiteList(inputSteam);
513                 } catch (Exception e) {
514                         assertTrue(true);
515                 }
516                 
517         }
518         
519         @Test
520         public void testCreateWhiteListAafPermissionError()  {
521                 prepareForTestCommon();
522
523                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
524                         .thenReturn(null);
525                 
526                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
527                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
528
529                 try {
530                         mmRestService.createWhiteList(inputSteam);
531                 } catch (Exception e) {
532                         assertTrue(true);
533                 }
534                 
535         }       
536         
537         @Test
538         public void testCreateWhiteListJSONError()  {
539                 prepareForTestCommon();
540
541                 String sampleJson = "{ namespace:\"test\",   whitelistTopicName:\"test\"}}";
542                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
543
544                 try {
545                         mmRestService.createWhiteList(inputSteam);
546                 } catch (Exception e) {
547                         assertTrue(true);
548                 }
549                 
550         }       
551         
552         @Test
553         public void testDeleteWhiteList()  {
554                 prepareForTestCommon();
555
556                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
557                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
558                 try {
559                         mmRestService.deleteWhiteList(inputSteam);
560                 } catch (Exception e) {
561                         assertTrue(true);
562                 }
563                 
564         }
565
566         @Test
567         public void testDeleteWhiteListMirrorMakerPermissionError()  {
568                 prepareForTestCommon();
569                 PowerMockito
570                         .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
571                         .thenReturn(null);
572                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
573                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
574                 try {
575                         mmRestService.deleteWhiteList(inputSteam);
576                 } catch (Exception e) {
577                         assertTrue(true);
578                 }
579                 
580         }
581
582         
583         @Test
584         public void testDeleteWhiteListMirrorMakerAafPermissionError()  {
585                 prepareForTestCommon();
586                 PowerMockito
587                         .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
588                         .thenReturn(null);
589                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
590                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
591                 try {
592                         mmRestService.deleteWhiteList(inputSteam);
593                 } catch (Exception e) {
594                         assertTrue(true);
595                 }
596                 
597         }
598         
599         
600         @Test
601         public void testDeleteWhiteListJsonError()  {
602                 prepareForTestCommon();
603
604                 String sampleJson = "{ namespace:\"test\",   whitelistTopicName:\"test\"}}";
605                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
606                 try {
607                         mmRestService.deleteWhiteList(inputSteam);
608                 } catch (Exception e) {
609                         assertTrue(true);
610                 }
611                 
612         }       
613         
614         @Test
615         public void testDeleteWhiteListJsonFormattingError()  {
616                 prepareForTestCommon();
617
618                 String sampleJson = "{ : namespace:\"test\",   whitelistTopicName:\"test\"}}";
619                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
620                 try {
621                         mmRestService.deleteWhiteList(inputSteam);
622                 } catch (Exception e) {
623                         assertTrue(true);
624                 }
625                 
626         }
627         
628         @Test
629         public void testCallPubSubForWhitelist() {
630                 prepareForTestCommon();
631                 
632                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
633                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
634                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
635                 try {
636                         PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
637                         mmRestService.callPubSubForWhitelist("test123", dmaapContext, inputSteam, new JSONObject (sampleJson)) ;
638                 } catch (Exception e) {
639                         assertTrue(true);
640                 }
641         }
642         
643         @Test
644         public void testCallPubSub() {
645                 prepareForTestCommon();
646                 
647                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
648                 String msgSubscribe = "[{ messageID:\"test123\", listMirrorMaker:[ {name: \"test\"}]}]"; 
649                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
650                 try {
651                         PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(msgSubscribe);
652                         mmRestService.callPubSub("test123", dmaapContext, inputSteam, "test", false) ;
653                 } catch (Exception e) {
654                         assertTrue(true);
655                 }
656         }
657         
658         @Test
659         public void testCallPubSubForWhitelistNoMsgFromSubscribe() {
660                 prepareForTestCommon();
661                 
662                 String sampleJson = "{ name:\"test\", namespace:\"test\",   whitelistTopicName:\"test\"}}";
663                 InputStream inputSteam = new ByteArrayInputStream(sampleJson.getBytes());
664                 try {
665                         PowerMockito.when(mmservice.subscribe(any(), anyString(), anyString(), anyString())).thenReturn(null);
666                         mmRestService.callPubSubForWhitelist("test123", dmaapContext, inputSteam, new JSONObject (sampleJson)) ;
667                 } catch (Exception e) {
668                         assertTrue(true);
669                 }
670         }
671
672         @Test
673         public void testGetListMirrorMaker() {
674                 prepareForTestCommon();
675                 
676                 String sampleJson = "[{ messageID:\"test123\", listMirrorMaker:[\"test\"]}]"; 
677                 try {
678                         mmRestService.getListMirrorMaker(sampleJson, "test123");
679                 } catch (Exception e) {
680                         assertTrue(true);
681                 }               
682         }
683         
684         private void prepareForTestCommon()  {
685                 Assert.assertNotNull(mmRestService);
686
687                 PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
688                 PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
689                 PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);
690
691                 PowerMockito.mockStatic(AJSCPropertiesMap.class);
692
693                 assertTrue(true);
694
695                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeradmin.aaf"))
696                                 .thenReturn("admin");
697                 PowerMockito
698                                 .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf.create"))
699                                 .thenReturn("aafcreate");
700
701                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormakeruser.aaf"))
702                                 .thenReturn("admin");
703
704                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.timeout"))
705                                 .thenReturn("100");
706
707                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.topic"))
708                                 .thenReturn("mirrormaker.topic");
709
710                 PowerMockito
711                                 .when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumergroup"))
712                                 .thenReturn("mirrormaker.consumergroup");
713
714                 PowerMockito.when(AJSCPropertiesMap.getProperty(CambriaConstants.msgRtr_prop, "msgRtr.mirrormaker.consumerid"))
715                                 .thenReturn("mirrormaker.consumerid");
716
717                 PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
718
719                 PowerMockito.when(httpServReq.isUserInRole("admin")).thenReturn(true);
720
721                 // PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
722                 PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin.aaf")).thenReturn(true);
723                 PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
724                 PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Admin");
725                 PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "admin")).thenReturn(true);
726                 PowerMockito.when(dmaapAAFauthenticator.aafAuthentication(httpServReq, "aafcreatetest|create"))
727                                 .thenReturn(true);
728
729                 PowerMockito.when(cMirroMaker.getCreateMirrorMaker()).thenReturn(mMaker);
730
731                 PowerMockito.when(mMaker.getName()).thenReturn("mirroMakerName");
732                 PowerMockito.when(dmaapContext.getConfigReader()).thenReturn(configReader);
733                 PowerMockito.when(dmaapContext.getRequest()).thenReturn(httpServReq);
734                 PowerMockito.when(httpServReq.getHeader("Authorization")).thenReturn("Authorization");
735
736                 PowerMockito.when(dmaapContext.getResponse()).thenReturn(httpServRes);
737                 PowerMockito.when(configReader.getfMetaBroker()).thenReturn(dmaapKafkaMetaBroker);
738                 PowerMockito.when(httpServReq.getMethod()).thenReturn("HEAD");
739
740                 try {
741                         PowerMockito.when(dmaapKafkaMetaBroker.getTopic(anyString())).thenReturn(null);
742                 } catch (ConfigDbException e) {
743                         
744                 }
745         }
746
747 }