@Test public void testEdit() throws Exception { // so request.getRequestURL() doesn't fail MockHttpServletRequest request = new MockHttpServletRequest("GET", "/editUser.html"); ServletActionContext.setRequest(request); action.setId("-1"); // regular user assertNull(action.getUser()); assertEquals("success", action.edit()); assertNotNull(action.getUser()); assertFalse(action.hasActionErrors()); }
@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 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()); }