use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class AccountControllerTest method testUpdate.
/**
* Test of update method, of class AccountController.
*
* @see AccountController#update(String, User)
*/
@Test
public void testUpdate() throws Exception {
log.info("update");
User user = mockDataService.user();
String userId = user.getId();
assertEquals(user.getSchool(), accountService.findOne(userId).getSchool());
user = user.toBuilder().school("test school").password("empty").build();
mvc.perform(patch("/api/accounts/{userId}.json", userId).content(objectMapper.writeValueAsString(user)).contentType(MediaType.APPLICATION_JSON)).andExpect(status().isNoContent()).andReturn();
assertEquals("test school", accountService.findOne(userId).getSchool());
// password not changed, for annotation JsonIgnore is present on field password
assertTrue("password should not be changed", passwordEncoder.matches(userId, accountService.findOne(userId).getPassword()));
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class SecurityConfigurationTest method testLoginErrorWithoutRedirectParam.
@Test
public void testLoginErrorWithoutRedirectParam() throws Exception {
log.info("login");
String redirectedUrl = "/login?error";
User user = mockDataService.user();
mvc.perform(post("/login").param("user_id1", user.getId()).param("password1", user.getPassword() + 1)).andExpect(status().isFound()).andExpect(redirectedUrl(redirectedUrl)).andReturn();
mvc.perform(post("/login").param("user_id1", user.getId()).param("password1", user.getPassword() + 1).param("url", "")).andExpect(status().isFound()).andExpect(redirectedUrl(redirectedUrl)).andReturn();
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class SecurityConfigurationTest method testLoginError.
@Test
public void testLoginError() throws Exception {
log.info("login");
String url = "/test?k=1&v=2";
String redirectedUrl = "/login?error&url=%2Ftest%3Fk%3D1%26v%3D2";
User user = mockDataService.user();
MvcResult result = mvc.perform(post("/login").param("user_id1", user.getId()).param("password1", user.getPassword() + 1).param("url", url)).andExpect(status().isFound()).andExpect(redirectedUrl(redirectedUrl)).andReturn();
}
use of cn.edu.zjnu.acm.judge.domain.User in project judge by zjnu-acm.
the class ModifyUserControllerTest method testUpdate.
/**
* Test of update method, of class ModifyUserController.
* @see ModifyUserController#update(Model, String, String, String, String, String, String, Authentication)
*/
@Test
public void testUpdate() throws Exception {
log.info("update");
User user = mockDataService.user();
String userId = user.getId();
String oldPassword = user.getPassword();
// at least 6 characters or empty
String newPassword = "";
String rptPassword = newPassword;
String email = "";
String nick = "";
String school = "";
MvcResult result = mvc.perform(post("/modifyuser").with(user(userId)).param("oldPassword", oldPassword).param("newPassword", newPassword).param("rptPassword", rptPassword).param("email", email).param("nick", nick).param("school", school)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.TEXT_HTML)).andExpect(view().name("modifyusersuccess")).andReturn();
}
Aggregations