UserAction extends BaseAction implements Preparable { public String edit() throws IOException { HttpServletRequest request = getRequest(); boolean editProfile = request.getRequestURI().contains("editProfile"); if (editProfile && ((request.getParameter("id") != null) || (request.getParameter("from") != null))) { ServletActionContext.getResponse().sendError(HttpServletResponse.SC_FORBIDDEN); log.warn("User '" + request.getRemoteUser() + "' is trying to edit user '" + request.getParameter("id") + "'"); return null; } if (id != null) { user = userManager.getUser(id); } else if (editProfile) { user = userManager.getUserByUsername(request.getRemoteUser()); } else { user = new User(); user.addRole(new Role(Constants.USER_ROLE)); } if (user.getUsername() != null) { user.setConfirmPassword(user.getPassword()); log.debug("checking for remember me login..."); AuthenticationTrustResolver resolver = new AuthenticationTrustResolverImpl(); SecurityContext ctx = SecurityContextHolder.getContext(); if (ctx != null) { Authentication auth = ctx.getAuthentication(); if (resolver.isRememberMe(auth)) { getSession().setAttribute("cookieLogin", "true"); saveMessage(getText("userProfile.cookieLogin")); } } } return SUCCESS; }  void prepare(); List<User> getUsers(); void setId(String id); User getUser(); void setUser(User user); void setQ(String q); String delete(); String edit(); String execute(); String cancel(); String save(); String list();  }
@Test public void testEdit() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest("GET", "/editUser.html"); ServletActionContext.setRequest(request); action.setId("-1"); assertNull(action.getUser()); assertEquals("success", action.edit()); assertNotNull(action.getUser()); assertFalse(action.hasActionErrors()); }