2  * ============LICENSE_START==========================================
 
   4  * ===================================================================
 
   5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 
   6  * ===================================================================
 
   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
 
  13  *             http://www.apache.org/licenses/LICENSE-2.0
 
  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.
 
  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
 
  26  *             https://creativecommons.org/licenses/by/4.0/
 
  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.
 
  34  * ============LICENSE_END============================================
 
  36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
 
  38 package org.onap.portalapp.portal.controller;
 
  40 import static org.junit.Assert.assertEquals;
 
  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;
 
  48 import java.util.SortedSet;
 
  49 import java.util.TreeSet;
 
  51 import javax.servlet.http.HttpServletRequest;
 
  52 import javax.servlet.http.HttpServletResponse;
 
  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;
 
  82 public class RoleManageControllerTest {
 
  85          RoleController roleController;
 
  88     RoleListController roleListController;
 
  91     RoleFunctionListController roleFunctionListController;
 
  95         ExternalAccessRolesService externalAccessRolesService;
 
  97         EPUserUtils ePUserUtils = new EPUserUtils();
 
 100         ExternalAccessRolesService externalAccessRolesService1 = null;
 
 103         RoleManageController roleManageController = new RoleManageController(); 
 
 106         EPAppService appService;
 
 109         AuditService auditService;
 
 112         AdminRolesService adminRolesService;
 
 115         public void setup() {
 
 116                 MockitoAnnotations.initMocks(this);
 
 119         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
 
 121         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
 
 122         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
 
 123         NullPointerException nullPointerException = new NullPointerException();
 
 124         MockEPUser mockUser = new MockEPUser();
 
 128         public void removeRoleRoleFunctionTest() throws Exception
 
 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);
 
 138         public void addRoleRoRoleFunctionTest() throws Exception
 
 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);
 
 147         public void removeChildRoleTest() throws Exception
 
 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);
 
 157         public void getRoleIfRoleIdNullTest() throws Exception
 
 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);
 
 177         @Test(expected = Exception.class)
 
 178         public void getRoleExceptionTest() throws Exception
 
 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);
 
 188         public void getRoleIfRoleIdNotNullTest() throws Exception
 
 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);
 
 216         public EPApp mockApp()
 
 218                 EPApp app = new EPApp();
 
 221                 app.setImageUrl("test");
 
 222                 app.setDescription("test");
 
 223                 app.setNotes("test");
 
 226                 app.setAppRestEndpoint("test");
 
 227                 app.setAlternateUrl("test");
 
 229                 app.setMlAppName("test");
 
 230                 app.setMlAppAdminId("test");
 
 231                 app.setUsername("test");
 
 232                 app.setAppPassword("test");
 
 234                 app.setEnabled(false);
 
 235                 app.setUebKey("test");
 
 236                 app.setUebSecret("test");
 
 237                 app.setUebTopicName("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);
 
 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);
 
 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);
 
 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);
 
 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()))
 
 302                 EPUser user = mockUser.mockEPUser();
 
 303                 Mockito.when(EPUserUtils.getUserSession(mockedRequest)).thenReturn(user);
 
 304                 List<EPUser> userList = new ArrayList<>();
 
 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);
 
 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);
 
 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);
 
 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()))
 
 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);
 
 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()))
 
 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);
 
 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);
 
 391         public void syncRolesTest() throws Exception {
 
 392                 EPApp app = mockApp();
 
 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);
 
 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);
 
 424         public void syncRolesFunctionsTest() throws Exception {
 
 425                 EPApp app = mockApp();
 
 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);
 
 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);
 
 457         public void addeChildRoleTest() throws Exception
 
 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);
 
 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());
 
 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);
 
 502         public CentralV2RoleFunction mockCentralRoleFunction()
 
 504                 CentralV2RoleFunction roleFunction = new CentralV2RoleFunction();
 
 505                 roleFunction.setCode("Test");
 
 506                 roleFunction.setName("Test");
 
 507                 roleFunction.setAppId((long) 1);
 
 511         public EPApp CentralApp()
 
 513                 EPApp app =  mockApp();
 
 514                 app.setCentralAuth(true);
 
 515                 app.setNameSpace("com.test");
 
 519         public EPApp NonCentralApp()
 
 521                 EPApp app =  mockApp();
 
 522                 app.setCentralAuth(false);