Added Junits
[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                 roleManageController.saveRoleFunction(mockedRequest, mockedResponse, addNewFunc, (long) 1);
336         }
337
338         @Test
339         public void removeRoleFunctionTest() throws Exception {
340                 EPUser user = mockUser.mockEPUser();
341                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
342                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
343                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
344                 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
345                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
346                 StringWriter sw = new StringWriter();
347                 PrintWriter writer = new PrintWriter(sw);
348                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
349                 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
350                                 .thenReturn(true);
351                 List<EPApp> appList = new ArrayList<>();
352                 appList.add(CentralApp());
353                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
354                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
355                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
356                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
357         }
358
359         @Test
360         public void removeRoleFunctionExceptionTest() throws Exception {
361                 EPUser user = mockUser.mockEPUser();
362                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
363                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
364                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
365                 CentralV2RoleFunction roleFunction = mockCentralRoleFunction();
366                 Mockito.when(externalAccessRolesService.getRoleFunction("Test", "test")).thenReturn(roleFunction);
367                 StringWriter sw = new StringWriter();
368                 PrintWriter writer = new PrintWriter(sw);
369                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
370                 Mockito.when(externalAccessRolesService.deleteCentralRoleFunction(Matchers.anyString(), Matchers.anyObject()))
371                                 .thenReturn(false);
372                 List<EPApp> appList = new ArrayList<>();
373                 appList.add(CentralApp());
374                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
375                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
376                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
377                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
378         }
379
380         @Test
381         public void removeRoleFunctionIfAppNotCentralizedTest() throws Exception {
382                 EPApp app = mockApp();
383                 app.setCentralAuth(false);
384                 Mockito.when(appService.getApp((long) 1)).thenReturn(app);
385                 String roleFun = "{\"name\":\"Test\",\"code\":\"Test\"}";
386                 roleManageController.removeRoleFunction(mockedRequest, mockedResponse, roleFun, (long) 1);
387         }
388
389         @Test
390         public void syncRolesTest() throws Exception {
391                 EPApp app = mockApp();
392                 app.setId((long) 1);
393                 EPUser user = mockUser.mockEPUser();
394                 Mockito.when(appService.getApp(1l)).thenReturn(app);
395                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
396                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
397                 Mockito.doNothing().when(externalAccessRolesService).syncApplicationRolesWithEcompDB(app);
398                 List<EPApp> appList = new ArrayList<>();
399                 appList.add(CentralApp());
400                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
401                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
402                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
403                 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
404                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
405                 portalRestResponse.setMessage("Sync roles completed successfully!");
406                 portalRestResponse.setResponse("Success");
407                 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
408                 assertEquals(portalRestResponse, actual);
409         }
410
411         @Test
412         public void syncRolesException() throws Exception {
413                 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
414                 PortalRestResponse<String> actual = roleManageController.syncRoles(mockedRequest, mockedResponse, 1l);
415                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
416                 portalRestResponse.setMessage(null);
417                 portalRestResponse.setResponse("Failed");
418                 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
419                 assertEquals(portalRestResponse, actual);
420         }
421         
422         @Test
423         public void syncRolesFunctionsTest() throws Exception {
424                 EPApp app = mockApp();
425                 app.setId((long) 1);
426                 EPUser user = mockUser.mockEPUser();
427                 Mockito.when(appService.getApp(1l)).thenReturn(app);
428                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
429                 Mockito.when(adminRolesService.isSuperAdmin(Matchers.anyObject())).thenReturn(true);
430                 Mockito.doNothing().when(externalAccessRolesService).syncRoleFunctionFromExternalAccessSystem(app);
431                 List<EPApp> appList = new ArrayList<>();
432                 appList.add(CentralApp());
433                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
434                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
435                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
436                 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
437                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
438                 portalRestResponse.setMessage("Sync Functions completed successfully!");
439                 portalRestResponse.setResponse("Success");
440                 portalRestResponse.setStatus(PortalRestStatusEnum.OK);
441                 assertEquals(portalRestResponse, actual);
442         }
443
444         @Test
445         public void syncRolesFunctionsException() throws Exception {
446                 Mockito.when(appService.getAppDetailByAppName("test")).thenThrow(nullPointerException);
447                 PortalRestResponse<String> actual = roleManageController.syncFunctions(mockedRequest, mockedResponse, 1l);
448                 PortalRestResponse<String> portalRestResponse = new PortalRestResponse<>();
449                 portalRestResponse.setMessage(null);
450                 portalRestResponse.setResponse("Failed");
451                 portalRestResponse.setStatus(PortalRestStatusEnum.ERROR);
452                 assertEquals(portalRestResponse, actual);
453         }
454         
455         @Test
456         public void addeChildRoleTest() throws Exception
457         {
458                 ModelAndView modelandView = new ModelAndView("login.htm");
459                 Mockito.when(roleController.addChildRole(mockedRequest, mockedResponse)).thenReturn(modelandView);
460                 ModelAndView expectedModelandView =     roleManageController.addChildRole(mockedRequest, mockedResponse);
461                 assertEquals(expectedModelandView, modelandView);
462         }
463         
464         @Test
465         public void removeRoleTest() throws Exception {
466                 List<EPUser> epuserList = new ArrayList<>();
467                 List<EPApp> appList = new ArrayList<>();
468                 appList.add(CentralApp());
469                 EPUser user = mockUser.mockEPUser();
470                 epuserList.add(user);
471                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
472                 Mockito.when(appService.getApp((long) 1)).thenReturn(CentralApp());
473                 StringWriter sw = new StringWriter();
474                 PrintWriter writer = new PrintWriter(sw);
475                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
476                 ExternalRequestFieldsValidator res = new ExternalRequestFieldsValidator(true, "success");
477                 Mockito.when(externalAccessRolesService.deleteDependencyRoleRecord(Matchers.anyLong(), Matchers.anyString(),
478                                 Matchers.anyString())).thenReturn(res);
479                 Mockito.when(externalAccessRolesService.getUser(Matchers.anyString())).thenReturn(epuserList);
480                 Mockito.when(externalAccessRolesService.getApp(Matchers.anyString())).thenReturn(appList);
481                 ResponseEntity<String> response = new ResponseEntity<>(HttpStatus.OK);
482                 Mockito.when( externalAccessRolesService.getNameSpaceIfExists(Matchers.anyObject())).thenReturn(response);
483                 Map<String, Object> expedtedResponse = new HashMap<String, Object>();
484                 expedtedResponse.put("restCallStatus", " Unauthorized user");
485                 Map<String, Object> actualResponse =    roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
486                 assertEquals(actualResponse.size(), expedtedResponse.size());
487
488         }
489         
490         @Test(expected = Exception.class)
491         public void removeRoleExceptionTest() throws Exception {
492                 EPUser user = mockUser.mockEPUser();
493                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
494                 Mockito.when(appService.getApp((long) 1)).thenThrow(nullPointerException);
495                 StringWriter sw = new StringWriter();
496                 PrintWriter writer = new PrintWriter(sw);
497                 Mockito.when(mockedResponse.getWriter()).thenReturn(writer);
498                 roleManageController.removeRole(mockedRequest, mockedResponse, (long) 1, (long) 1);
499         }
500         
501         public CentralV2RoleFunction mockCentralRoleFunction()
502         {
503                 CentralV2RoleFunction roleFunction = new CentralV2RoleFunction();
504                 roleFunction.setCode("Test");
505                 roleFunction.setName("Test");
506                 roleFunction.setAppId((long) 1);
507                 return roleFunction;
508         }
509         
510         public EPApp CentralApp()
511         {
512                 EPApp app =  mockApp();
513                 app.setCentralAuth(true);
514                 app.setNameSpace("com.test");
515                 return app;
516         }
517         
518         public EPApp NonCentralApp()
519         {
520                 EPApp app =  mockApp();
521                 app.setCentralAuth(false);
522                 return app;
523         }
524 }