Search in sources :

Example 11 with User

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()));
}
Also used : User(cn.edu.zjnu.acm.judge.domain.User) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 12 with User

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();
}
Also used : User(cn.edu.zjnu.acm.judge.domain.User) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 13 with User

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();
}
Also used : User(cn.edu.zjnu.acm.judge.domain.User) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 14 with User

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();
}
Also used : User(cn.edu.zjnu.acm.judge.domain.User) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

User (cn.edu.zjnu.acm.judge.domain.User)14 Test (org.junit.Test)5 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)4 MvcResult (org.springframework.test.web.servlet.MvcResult)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 MessageException (cn.edu.zjnu.acm.judge.exception.MessageException)2 PrintWriter (java.io.PrintWriter)2 Nonnull (javax.annotation.Nonnull)2 BusinessException (cn.edu.zjnu.acm.judge.exception.BusinessException)1 MessagingException (javax.mail.MessagingException)1 HttpSession (javax.servlet.http.HttpSession)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Sort (org.springframework.data.domain.Sort)1 MailException (org.springframework.mail.MailException)1 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)1 WithMockUser (org.springframework.security.test.context.support.WithMockUser)1 Context (org.thymeleaf.context.Context)1