LoginController { @RequestMapping(value = { "/login" }, method = RequestMethod.POST, produces = {"application/json"}) public @ResponseBody AjaxResponse login(String username, String password, String rememberme) { UsernamePasswordToken token = new UsernamePasswordToken(username, password); if (StringUtils.isNotBlank(rememberme)) { token.setRememberMe(true); } try { SecurityUtils.getSubject().login(token); logger.debug("{}登陆成功!", username); return new AjaxResponse(true, "登录成功！", Realm.getUser()); } catch (AuthenticationException e) { return new AjaxResponse(false, "用户名或密码错误!"); } catch (Exception e) { return new AjaxResponse(false, e.getMessage()); } }  @RequestMapping(value = { "/login" }, method = RequestMethod.POST, produces = {"application/json"}) @ResponseBody AjaxResponse login(String username, String password, String rememberme); @RequestMapping(value = "/logout") @RequiresUser @ResponseBody AjaxResponse logout();  }
@Test public void testLogin() throws Exception { this.mockMvc.perform( post(URI).param("username", "admin").param("password", "123456").accept(MediaType.APPLICATION_JSON)) .andExpect(jsonPath("$.sucess").value(true)); }