UserManagementController extends AbstractUserAndContractsController { @RequestMapping(value = TgolKeyStore.EDIT_USER_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) public String displayEditUserAdminPage( @RequestParam(TgolKeyStore.USER_ID_KEY) String userId, HttpServletRequest request, HttpServletResponse response, Model model) { Long lUserId; try { lUserId = Long.valueOf(userId); } catch (NumberFormatException nfe) { throw new ForbiddenUserException(); } User userToModify = userDataService.read(lUserId); model.addAttribute(TgolKeyStore.USER_NAME_KEY, userToModify.getEmail1()); request.getSession().setAttribute(TgolKeyStore.USER_ID_KEY, lUserId); return prepateDataAndReturnCreateUserView( model, userToModify, TgolKeyStore.EDIT_USER_VIEW_NAME); } UserManagementController(ContractDataService contractDataService,
                                    CreateUserCommandFactory createUserCommandFactory); @RequestMapping(value = TgolKeyStore.ADMIN_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayAdminPage(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.EDIT_USER_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayEditUserAdminPage(
            @RequestParam(TgolKeyStore.USER_ID_KEY) String userId,
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayAddUserAdminPage(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayDeleteUserPage(
            @RequestParam(TgolKeyStore.USER_ID_KEY) String userId,
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.DELETE_USER_URL, method = RequestMethod.POST) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayDeleteUserConfirmation(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayDeleteUserAuditsPage(
            @RequestParam(TgolKeyStore.USER_ID_KEY) String userId,
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.DELETE_USER_AUDITS_URL, method = RequestMethod.POST) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayDeleteUserAuditsConfirmationPage(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.ADD_CONTRACT_URL, method = RequestMethod.GET) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String displayAddContractAdminPage(
            HttpServletRequest request,
            HttpServletResponse response,
            Model model); @RequestMapping(value = TgolKeyStore.ADD_CONTRACT_URL, method = RequestMethod.POST) @Secured(TgolKeyStore.ROLE_ADMIN_KEY) String submitAddContractAdminPage(
            @ModelAttribute(TgolKeyStore.CREATE_CONTRACT_COMMAND_KEY) CreateContractCommand ccc,
            BindingResult result,
            HttpServletRequest request,
            HttpServletResponse response,
            Model model);  }
@Test public void testEditUserAdminPage() { setUpMockRoleDataService(); setUpMockUserDataService(false, false, false); setUpMockAuthenticationContext(); HttpServletResponse response = new MockHttpServletResponse(); MockHttpServletRequest request = new MockHttpServletRequest(); assertThrows(ForbiddenUserException.class, () -> instance.displayEditUserAdminPage("", request, response, new ExtendedModelMap())); String userId = "4"; Model model = new ExtendedModelMap(); String result = instance.displayEditUserAdminPage(userId, request, response, model); assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result); CreateUserCommand cuc = ((CreateUserCommand)model.asMap().get(CREATE_USER_COMMAND_KEY)); assertNotNull(cuc); assertTrue(cuc.getActivated()); assertTrue(cuc.getAdmin()); assertEquals("admin@test.com",cuc.getEmail()); assertEquals("http: assertEquals("0123456789",cuc.getPhoneNumber()); assertEquals("nameAdmin",cuc.getLastName()); assertEquals("firstNameAdmin",cuc.getFirstName()); assertEquals(4L,request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY)); userId = "5"; result = instance.displayEditUserAdminPage(userId, request, response, model); assertEquals(TgolKeyStore.EDIT_USER_VIEW_NAME, result); cuc = ((CreateUserCommand)model.asMap().get(CREATE_USER_COMMAND_KEY)); assertNotNull(cuc); assertFalse(cuc.getActivated()); assertFalse(cuc.getAdmin()); assertEquals("user@test.com",cuc.getEmail()); assertEquals("http: assertEquals("9876543210",cuc.getPhoneNumber()); assertEquals("nameUser",cuc.getLastName()); assertEquals("firstNameUser",cuc.getFirstName()); assertEquals(5L,request.getSession().getAttribute(TgolKeyStore.USER_ID_KEY)); }