Security/ Package Name changes
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / controller / RoleManageControllerTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalapp.portal.controller;
39
40 import static org.junit.Assert.assertEquals;
41
42 import java.io.PrintWriter;
43 import java.io.StringWriter;
44 import java.util.ArrayList;
45 import java.util.HashMap;
46 import java.util.List;
47 import java.util.Map;
48 import java.util.SortedSet;
49 import java.util.TreeSet;
50
51 import javax.servlet.http.HttpServletRequest;
52 import javax.servlet.http.HttpServletResponse;
53
54 import org.junit.Before;
55 import org.junit.Test;
56 import org.mockito.InjectMocks;
57 import org.mockito.Matchers;
58 import org.mockito.Mock;
59 import org.mockito.Mockito;
60 import org.mockito.MockitoAnnotations;
61 import org.onap.portalapp.controller.core.RoleController;
62 import org.onap.portalapp.controller.core.RoleFunctionListController;
63 import org.onap.portalapp.controller.core.RoleListController;
64 import org.onap.portalapp.portal.core.MockEPUser;
65 import org.onap.portalapp.portal.domain.CentralV2RoleFunction;
66 import org.onap.portalapp.portal.domain.EPApp;
67 import org.onap.portalapp.portal.domain.EPUser;
68 import org.onap.portalapp.portal.ecomp.model.PortalRestResponse;
69 import org.onap.portalapp.portal.ecomp.model.PortalRestStatusEnum;
70 import org.onap.portalapp.portal.framework.MockitoTestSuite;
71 import org.onap.portalapp.portal.service.AdminRolesService;
72 import org.onap.portalapp.portal.service.EPAppService;
73 import org.onap.portalapp.portal.service.ExternalAccessRolesService;
74 import org.onap.portalapp.portal.transport.CentralV2Role;
75 import org.onap.portalapp.portal.transport.ExternalRequestFieldsValidator;
76 import org.onap.portalapp.util.EPUserUtils;
77 import org.onap.portalsdk.core.service.AuditService;
78 import org.springframework.http.HttpStatus;
79 import org.springframework.http.ResponseEntity;
80 import org.springframework.web.servlet.ModelAndView;
81
82 public class RoleManageControllerTest {
83
84         @Mock
85          RoleController roleController;
86
87         @Mock
88     RoleListController roleListController;
89
90         @Mock
91     RoleFunctionListController roleFunctionListController;
92
93
94         @Mock
95         ExternalAccessRolesService externalAccessRolesService;
96         @Mock
97         EPUserUtils ePUserUtils = new EPUserUtils();
98         
99         @Mock
100         ExternalAccessRolesService externalAccessRolesService1 = null;
101         
102         @InjectMocks
103         RoleManageController roleManageController = new RoleManageController(); 
104         
105         @Mock
106         EPAppService appService;
107
108         @Mock
109         AuditService auditService;
110         
111         @Mock
112         AdminRolesService adminRolesService;
113         
114         @Before
115         public void setup() {
116                 MockitoAnnotations.initMocks(this);
117         }
118
119         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
120
121         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
122         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
123         NullPointerException nullPointerException = new NullPointerException();
124         MockEPUser mockUser = new MockEPUser();
125         
126         
127         @Test
128         public void removeRoleRoleFunctionTest() throws Exception
129         {
130                 
131                 ModelAndView modelandView = new ModelAndView("login.htm");
132                 Mockito.when(roleController.removeRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
133                 ModelAndView expectedModelandView =     roleManageController.removeRoleRoleFunction(mockedRequest, mockedResponse);
134                 assertEquals(expectedModelandView, modelandView);
135         }
136         
137         @Test
138         public void addRoleRoRoleFunctionTest() throws Exception
139         {
140                 ModelAndView modelandView = new ModelAndView("login.htm");
141                 Mockito.when(roleController.addRoleFunction(mockedRequest, mockedResponse)).thenReturn(modelandView);
142                 ModelAndView expectedModelandView =     roleManageController.addRoleRoRoleFunction(mockedRequest, mockedResponse);
143                 assertEquals(expectedModelandView, modelandView);
144         }
145         
146         @Test
147         public void removeChildRoleTest() throws Exception
148         {
149                 ModelAndView modelandView = new ModelAndView("login.htm");
150                 Mockito.when(roleController.removeChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
151                 ModelAndView expectedModelandView =     roleManageController.removeChildRole(mockedRequest, mockedResponse);
152                 assertEquals(expectedModelandView, modelandView);
153         }
154         
155         
156         @Test
157         public void getRoleIfRoleIdNullTest() throws Exception
158         {
159                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
160                 CentralV2Role answer = new CentralV2Role();
161                 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
162                 List<CentralV2RoleFunction> finalRoleFunctionList = new ArrayList<>();
163                 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList);
164                 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(null);
165                 StringWriter sw = new StringWriter();
166                 PrintWriter writer = new PrintWriter(sw);
167                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);    
168                 List<EPApp> appList = new ArrayList<>();
169                 appList.add(CentralApp());
170                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
171                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
172                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
173            roleManageController.getRole(mockedRequest, mockedResponse, (long)1,null);
174           
175 }
176         
177         @Test(expected = Exception.class)
178         public void getRoleExceptionTest() throws Exception
179         {
180                 Mockito.when(appService.getApp((long) 1)).thenReturn(mockApp());
181                 CentralV2Role answer = new CentralV2Role();
182                 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
183                 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenThrow(nullPointerException);
184            roleManageController.getRole(mockedRequest, mockedResponse, (long)1,null);
185           
186 }
187         @Test
188         public void getRoleIfRoleIdNotNullTest() throws Exception
189         {
190                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
191                 CentralV2Role answer = new CentralV2Role();
192                 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(answer);
193                 List<CentralV2RoleFunction> finalRoleFunctionList = new ArrayList<>();
194                 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(finalRoleFunctionList);
195                 StringWriter sw = new StringWriter();
196                 PrintWriter writer = new PrintWriter(sw);
197                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);    
198                 CentralV2Role currentRole = new CentralV2Role();
199             SortedSet<CentralV2Role> parentRoles = new TreeSet<>();
200                 CentralV2Role centralV2Role = new CentralV2Role();
201                 centralV2Role.setName("test");     
202                 parentRoles.add(centralV2Role);
203                 currentRole.setParentRoles(parentRoles);
204                 Mockito.when(externalAccessRolesService.getRoleInfo((long) 1, "test")).thenReturn(currentRole);
205                 List<CentralV2Role> availableChildRoles = new ArrayList<>();
206                 availableChildRoles.add(currentRole);
207                 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(availableChildRoles);
208                 List<EPApp> appList = new ArrayList<>();
209                 appList.add(CentralApp());
210                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
211                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
212                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
213            roleManageController.getRole(mockedRequest, mockedResponse, (long)1,(long)1);
214 }
215         
216         public EPApp mockApp()
217         {
218                 EPApp app = new EPApp();
219
220                 app.setName("Test");
221                 app.setImageUrl("test");
222                 app.setDescription("test");
223                 app.setNotes("test");
224                 app.setUrl("test");
225                 app.setId((long) 1);
226                 app.setAppRestEndpoint("test");
227                 app.setAlternateUrl("test");
228                 app.setName("test");
229                 app.setMlAppName("test");
230                 app.setMlAppAdminId("test");
231                 app.setUsername("test");
232                 app.setAppPassword("test");
233                 app.setOpen(false);
234                 app.setEnabled(false);
235                 app.setUebKey("test");
236                 app.setUebSecret("test");
237                 app.setUebTopicName("test");
238                 app.setAppType(1);
239                 return app;
240                 
241         }
242         @Test
243         public void getRolesTest() throws Exception {
244                 EPApp app = mockApp();
245                 app.setCentralAuth(true);
246                 List<CentralV2Role> answer = new ArrayList<>();
247                 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
248                 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenReturn(answer);
249                 StringWriter sw = new StringWriter();
250                 PrintWriter writer = new PrintWriter(sw);
251                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
252                 List<EPApp> appList = new ArrayList<>();
253                 appList.add(CentralApp());
254                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
255                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
256                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
257                 roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1);
258         }
259
260         @Test
261         public void getRolesExceptionTest() throws Exception {
262                 EPApp app = CentralApp();
263                 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
264                 Mockito.when(externalAccessRolesService.getRolesForApp("test")).thenThrow(new java.lang.Exception());
265                 roleManageController.getRoles(mockedRequest, mockedResponse, (long) 1);
266
267         }
268
269         @Test
270         public void getRoleFunctionListTest() throws Exception {
271                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
272                 List<CentralV2RoleFunction> answer = new ArrayList<>();
273                 Mockito.when(externalAccessRolesService.getRoleFuncList("test")).thenReturn(answer);
274                 StringWriter sw = new StringWriter();
275                 PrintWriter writer = new PrintWriter(sw);
276                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
277                 List<EPApp> appList = new ArrayList<>();
278                 appList.add(CentralApp());
279                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
280                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
281                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
282                 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1);
283         }
284
285         @Test(expected = Exception.class)
286         public void getRoleFunctionListExceptionTest() throws Exception {
287                 Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp());
288                 roleManageController.getRoleFunctionList(mockedRequest, mockedResponse, (long) 1);
289         }
290
291         @Test
292         public void saveRoleFunctionTest() throws Exception {
293                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
294                 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
295                 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
296                 addNewFunc.setCode("Test");
297                 addNewFunc.setName("Test");
298                 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
299                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
300                 Mockito.when(externalAccessRolesService.saveCentralRoleFunction(Matchers.anyObject(), Matchers.anyObject()))
301                                 .thenReturn(true);
302                 EPUser user = mockUser.mockEPUser();
303                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
304                 List<EPUser> userList = new ArrayList<>();
305                 userList.add(user);
306                 List<EPApp> appList = new ArrayList<>();
307                 appList.add(CentralApp());
308                 Mockito.when(externalAccessRolesService.getUser("guestT")).thenReturn(userList);
309                 StringWriter sw = new StringWriter();
310                 PrintWriter writer = new PrintWriter(sw);
311                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
312                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
313                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
314                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
315                 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
316         }
317
318         @Test
319         public void saveRoleFunctionExceptionTest() throws Exception {
320                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
321                 Mockito.doNothing().when(roleFunctionListController).saveRoleFunction(mockedRequest, mockedResponse, "test");
322                 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
323                 addNewFunc.setCode("Test");
324                 addNewFunc.setName("Test");
325                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(null);
326                 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
327         }
328
329         @Test
330         public void saveRoleFunctionIfAppNotCentralizedTest() throws Exception {
331                 CentralV2RoleFunction addNewFunc = new CentralV2RoleFunction();
332                 addNewFunc.setCode("Test");
333                 addNewFunc.setName("Test");
334                 Mockito.when(appService.getApp((long) 1)).thenReturn(NonCentralApp());
335                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
336                 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
337         }
338
339         @Test
340         public void removeRoleFunctionTest() throws Exception {
341                 EPUser user = mockUser.mockEPUser();
342                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
343                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
344                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
345                 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
346                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
347                 StringWriter sw = new StringWriter();
348                 PrintWriter writer = new PrintWriter(sw);
349                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
350                 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
351                                 .thenReturn(true);
352                 List<EPApp> appList = new ArrayList<>();
353                 appList.add(CentralApp());
354                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
355                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
356                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
357                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
358         }
359
360         @Test
361         public void removeRoleFunctionExceptionTest() throws Exception {
362                 EPUser user = mockUser.mockEPUser();
363                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
364                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
365                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
366                 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
367                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
368                 StringWriter sw = new StringWriter();
369                 PrintWriter writer = new PrintWriter(sw);
370                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
371                 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
372                                 .thenReturn(false);
373                 List<EPApp> appList = new ArrayList<>();
374                 appList.add(CentralApp());
375                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
376                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
377                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
378                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
379         }
380
381         @Test
382         public void removeRoleFunctionIfAppNotCentralizedTest() throws Exception {
383                 EPApp app = mockApp();
384                 app.setCentralAuth(false);
385                 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
386                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
387                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
388         }
389
390         @Test
391         public void syncRolesTest() throws Exception {
392                 EPApp app = mockApp();
393                 app.setId((long) 1);
394                 EPUser user = mockUser.mockEPUser();
395                 Mockito.when(appService.getApp(1l)).thenReturn(app);
396                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
397                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
398                 Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
399                 List<EPApp> appList = new ArrayList<>();
400                 appList.add(CentralApp());
401                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
402                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
403                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
404                 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
405                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
406                 portalRestResponse.setMessage("Sync roles completed successfully!");
407                 portalRestResponse.setResponse("Success");
408                 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
409                 assertEquals(portalRestResponse, actual);
410         }
411
412         @Test
413         public void syncRolesException() throws Exception {
414                 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
415                 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
416                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
417                 portalRestResponse.setMessage(null);
418                 portalRestResponse.setResponse("Failed");
419                 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
420                 assertEquals(portalRestResponse, actual);
421         }
422         
423         @Test
424         public void syncRolesFunctionsTest() throws Exception {
425                 EPApp app = mockApp();
426                 app.setId((long) 1);
427                 EPUser user = mockUser.mockEPUser();
428                 Mockito.when(appService.getApp(1l)).thenReturn(app);
429                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
430                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
431                 Mockito.doNothing().when(externalAccessRolesService).syncRoleFunctionFromExternalAccessSystem(app);
432                 List<EPApp> appList = new ArrayList<>();
433                 appList.add(CentralApp());
434                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
435                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
436                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
437                 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
438                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
439                 portalRestResponse.setMessage("Sync Functions completed successfully!");
440                 portalRestResponse.setResponse("Success");
441                 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
442                 assertEquals(portalRestResponse, actual);
443         }
444
445         @Test
446         public void syncRolesFunctionsException() throws Exception {
447                 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
448                 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
449                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
450                 portalRestResponse.setMessage(null);
451                 portalRestResponse.setResponse("Failed");
452                 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
453                 assertEquals(portalRestResponse, actual);
454         }
455         
456         @Test
457         public void addeChildRoleTest() throws Exception
458         {
459                 ModelAndView modelandView = new ModelAndView("login.htm");
460                 Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
461                 ModelAndView expectedModelandView =     roleManageController.addChildRole(mockedRequest, mockedResponse);
462                 assertEquals(expectedModelandView, modelandView);
463         }
464         
465         @Test
466         public void removeRoleTest() throws Exception {
467                 List<EPUser> epuserList = new ArrayList<>();
468                 List<EPApp> appList = new ArrayList<>();
469                 appList.add(CentralApp());
470                 EPUser user = mockUser.mockEPUser();
471                 epuserList.add(user);
472                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
473                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
474                 StringWriter sw = new StringWriter();
475                 PrintWriter writer = new PrintWriter(sw);
476                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
477                 ExternalRequestFieldsValidator res = new ExternalRequestFieldsValidator(true, "success");
478                 Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(), Matchers.anyString(),
479                                 Matchers.anyString())).thenReturn(res);
480                 Mockito.when(externalAccessRolesService.getUser(Matchers.anyString())).thenReturn(epuserList);
481                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
482                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
483                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
484                 Map<String, Object> expedtedResponse = new HashMap<String, Object>();
485                 expedtedResponse.put("restCallStatus", " Unauthorized user");
486                 Map<String, Object> actualResponse =    roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
487                 assertEquals(actualResponse.size(), expedtedResponse.size());
488
489         }
490         
491         @Test(expected = Exception.class)
492         public void removeRoleExceptionTest() throws Exception {
493                 EPUser user = mockUser.mockEPUser();
494                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
495                 Mockito.when(appService.getApp((long) 1)).thenThrow(nullPointerException);
496                 StringWriter sw = new StringWriter();
497                 PrintWriter writer = new PrintWriter(sw);
498                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
499                 roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
500         }
501         
502         public CentralV2RoleFunction mockCentralRoleFunction()
503         {
504                 CentralV2RoleFunction roleFunction = new CentralV2RoleFunction();
505                 roleFunction.setCode("Test");
506                 roleFunction.setName("Test");
507                 roleFunction.setAppId((long) 1);
508                 return roleFunction;
509         }
510         
511         public EPApp CentralApp()
512         {
513                 EPApp app =  mockApp();
514                 app.setCentralAuth(true);
515                 app.setNameSpace("com.test");
516                 return app;
517         }
518         
519         public EPApp NonCentralApp()
520         {
521                 EPApp app =  mockApp();
522                 app.setCentralAuth(false);
523                 return app;
524         }
525 }