@Test public void testSave() throws Exception { UserManager userManager = (UserManager) applicationContext.getBean("userManager"); User user = userManager.getUserByUsername("user"); user.setPassword("user"); user.setConfirmPassword("user"); action.setUser(user); action.setFrom("list"); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("encryptPass", "true"); ServletActionContext.setRequest(request); assertEquals("input", action.save()); assertNotNull(action.getUser()); assertFalse(action.hasActionErrors()); }
@Test public void testSave() throws Exception { request = newPost("/userform.html"); // set updated properties first since adding them later will // result in multiple parameters with the same name getting sent User user = ((UserManager) applicationContext.getBean("userManager")).getUser("-1"); user.setConfirmPassword(user.getPassword()); user.setLastName("Updated Last Name"); request.setRemoteUser(user.getUsername()); BindingResult errors = new DataBinder(user).getBindingResult(); c.onSubmit(user, errors, request, new MockHttpServletResponse()); assertFalse(errors.hasErrors()); assertNotNull(request.getSession().getAttribute("successMessages")); }
@Test public void testSignupUser() throws Exception { MockHttpServletRequest request = newPost("/signup.html"); Address address = new Address(); address.setCity("Denver"); address.setProvince("Colorado"); address.setCountry("USA"); address.setPostalCode("80210"); User user = new User(); user.setAddress(address); user.setUsername("self-registered"); user.setPassword("Password1"); user.setConfirmPassword("Password1"); user.setFirstName("First"); user.setLastName("Last"); user.setEmail("*****@*****.**"); user.setWebsite("http://raibledesigns.com"); user.setPasswordHint("Password is one with you."); HttpServletResponse response = new MockHttpServletResponse(); // start SMTP Server Wiser wiser = new Wiser(); wiser.setPort(getSmtpPort()); wiser.start(); BindingResult errors = new DataBinder(user).getBindingResult(); c.onSubmit(user, errors, request, response); assertFalse("errors returned in model", errors.hasErrors()); // verify an account information e-mail was sent wiser.stop(); assertTrue(wiser.getMessages().size() == 1); // verify that success messages are in the request assertNotNull(request.getSession().getAttribute("successMessages")); assertNotNull(request.getSession().getAttribute(Constants.REGISTERED)); SecurityContextHolder.getContext().setAuthentication(null); }
@Test public void testSaveConflictingUser() throws Exception { UserManager userManager = (UserManager) applicationContext.getBean("userManager"); User user = userManager.getUserByUsername("user"); user.setPassword("user"); user.setConfirmPassword("user"); // e-mail address from existing user User existingUser = (User) userManager.getUsers().get(0); user.setEmail(existingUser.getEmail()); action.setUser(user); action.setFrom("list"); Integer originalVersionNumber = user.getVersion(); log.debug("original version #: " + originalVersionNumber); MockHttpServletRequest request = new MockHttpServletRequest(); request.addParameter("encryptPass", "true"); ServletActionContext.setRequest(request); assertEquals("input", action.save()); assertNotNull(action.getUser()); assertEquals(originalVersionNumber, user.getVersion()); assertTrue(action.hasActionErrors()); }