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