@Test public void testSubmitAddUserFormWithErrors() throws Exception { setUpMockRoleDataService(); setUpMockUserDataService(false, false, false); setUpMockAuthenticationContext(); CreateUserCommand createUserCommand = createUserCommandFactory.getNewCreateUserCommand(); BindingResult bindingResult = new BeanPropertyBindingResult(createUserCommand,"createUserCommand"); Model model = new ExtendedModelMap(); String result = instance.submitAddUserForm(createUserCommand, bindingResult, model); assertEquals(ADD_USER_VIEW_NAME, result); assertTrue(bindingResult.hasErrors()); assertEquals(3,bindingResult.getFieldErrors().size()); assertNotNull(bindingResult.getFieldErrors("email")); assertEquals(1,bindingResult.getFieldErrors("email").size()); assertEquals("sign-up.missingEmail",bindingResult.getFieldErrors("email").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("password")); assertEquals(1,bindingResult.getFieldErrors("password").size()); assertEquals("sign-up.missingPassword",bindingResult.getFieldErrors("password").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("generalErrorMsg")); assertEquals(1,bindingResult.getFieldErrors("generalErrorMsg").size()); assertEquals("sign-up.mandatoryField",bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode()); createUserCommand = createUserCommandFactory.getNewCreateUserCommand(); createUserCommand.setEmail("user@test.com"); createUserCommand.setPassword("password"); createUserCommand.setConfirmPassword("confirmation"); bindingResult = new BeanPropertyBindingResult(createUserCommand,"createUserCommand"); model = new ExtendedModelMap(); result = instance.submitAddUserForm(createUserCommand, bindingResult, model); assertEquals(ADD_USER_VIEW_NAME, result); assertTrue(bindingResult.hasErrors()); assertEquals(3,bindingResult.getFieldErrors().size()); assertNotNull(bindingResult.getFieldErrors("email")); assertEquals(1,bindingResult.getFieldErrors("email").size()); assertEquals("sign-up.existingAccountWithEmail",bindingResult.getFieldErrors("email").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("password")); assertEquals(1,bindingResult.getFieldErrors("password").size()); assertEquals("sign-up.passwordNotIdentical",bindingResult.getFieldErrors("password").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("generalErrorMsg")); assertEquals(1,bindingResult.getFieldErrors("generalErrorMsg").size()); assertEquals("sign-up.mandatoryField",bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode()); createUserCommand = createUserCommandFactory.getNewCreateUserCommand(); createUserCommand.setEmail("null"); createUserCommand.setPassword("password"); createUserCommand.setConfirmPassword("password"); bindingResult = new BeanPropertyBindingResult(createUserCommand,"createUserCommand"); model = new ExtendedModelMap(); result = instance.submitAddUserForm(createUserCommand, bindingResult, model); assertEquals(ADD_USER_VIEW_NAME, result); assertTrue(bindingResult.hasErrors()); assertEquals(3,bindingResult.getFieldErrors().size()); assertNotNull(bindingResult.getFieldErrors("email")); assertEquals(1,bindingResult.getFieldErrors("email").size()); assertEquals("sign-up.invalidEmail",bindingResult.getFieldErrors("email").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("password")); assertEquals(1,bindingResult.getFieldErrors("password").size()); assertEquals("sign-up.invalidPassword",bindingResult.getFieldErrors("password").get(0).getCode()); assertNotNull(bindingResult.getFieldErrors("generalErrorMsg")); assertEquals(1,bindingResult.getFieldErrors("generalErrorMsg").size()); assertEquals("sign-up.mandatoryField",bindingResult.getFieldErrors("generalErrorMsg").get(0).getCode()); }
@RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.POST) protected String submitAddUserForm( @ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception { return submitCreateUserForm( createUserCommand, result, model, TgolKeyStore.ADMIN_VIEW_NAME, TgolKeyStore.ADD_USER_VIEW_NAME, TgolKeyStore.ADDED_USER_NAME_KEY); }
UserManagementController extends AbstractUserAndContractsController { @RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.POST) protected String submitAddUserForm( @ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception { return submitCreateUserForm( createUserCommand, result, model, TgolKeyStore.ADMIN_VIEW_NAME, TgolKeyStore.ADD_USER_VIEW_NAME, TgolKeyStore.ADDED_USER_NAME_KEY); } }
UserManagementController extends AbstractUserAndContractsController { @RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.POST) protected String submitAddUserForm( @ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception { return submitCreateUserForm( createUserCommand, result, model, TgolKeyStore.ADMIN_VIEW_NAME, TgolKeyStore.ADD_USER_VIEW_NAME, TgolKeyStore.ADDED_USER_NAME_KEY); } UserManagementController(ContractDataService contractDataService,
                                    CreateUserCommandFactory createUserCommandFactory); }
UserManagementController extends AbstractUserAndContractsController { @RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.POST) protected String submitAddUserForm( @ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception { return submitCreateUserForm( createUserCommand, result, model, TgolKeyStore.ADMIN_VIEW_NAME, TgolKeyStore.ADD_USER_VIEW_NAME, TgolKeyStore.ADDED_USER_NAME_KEY); } 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); }
UserManagementController extends AbstractUserAndContractsController { @RequestMapping(value = TgolKeyStore.ADD_USER_URL, method = RequestMethod.POST) protected String submitAddUserForm( @ModelAttribute(TgolKeyStore.CREATE_USER_COMMAND_KEY) CreateUserCommand createUserCommand, BindingResult result, Model model) throws Exception { return submitCreateUserForm( createUserCommand, result, model, TgolKeyStore.ADMIN_VIEW_NAME, TgolKeyStore.ADD_USER_VIEW_NAME, TgolKeyStore.ADDED_USER_NAME_KEY); } 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);  }