Search in sources :

Example 11 with User

use of ru.javawebinar.topjava.model.User in project topjava10 by JavaWebinar.

the class AbstractUserServiceTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    User updated = new User(USER);
    updated.setName("UpdatedName");
    updated.setCaloriesPerDay(330);
    updated.setRoles(Collections.singletonList(Role.ROLE_ADMIN));
    service.update(updated);
    MATCHER.assertEquals(updated, service.get(USER_ID));
}
Also used : User(ru.javawebinar.topjava.model.User) Test(org.junit.Test)

Example 12 with User

use of ru.javawebinar.topjava.model.User in project topjava10 by JavaWebinar.

the class AbstractJpaUserServiceTest method testValidation.

@Test
public void testValidation() throws Exception {
    validateRootCause(() -> service.save(new User(null, "  ", "invalid@yandex.ru", "password", 2000, Role.ROLE_USER)), ConstraintViolationException.class);
    validateRootCause(() -> service.save(new User(null, "User", "  ", "password", 2000, Role.ROLE_USER)), ConstraintViolationException.class);
    validateRootCause(() -> service.save(new User(null, "User", "invalid@yandex.ru", "  ", 2000, Role.ROLE_USER)), ConstraintViolationException.class);
    validateRootCause(() -> service.save(new User(null, "User", "invalid@yandex.ru", "password", 9, true, new Date(), Collections.emptySet())), ConstraintViolationException.class);
    validateRootCause(() -> service.save(new User(null, "User", "invalid@yandex.ru", "password", 10001, true, new Date(), Collections.emptySet())), ConstraintViolationException.class);
}
Also used : User(ru.javawebinar.topjava.model.User) Date(java.util.Date) Test(org.junit.Test)

Example 13 with User

use of ru.javawebinar.topjava.model.User in project topjava10 by JavaWebinar.

the class ProfileRestControllerTest method testUpdate.

@Test
public void testUpdate() throws Exception {
    UserTo updatedTo = new UserTo(null, "newName", "newemail@ya.ru", "newPassword", 1500);
    mockMvc.perform(put(REST_URL).contentType(MediaType.APPLICATION_JSON).with(userHttpBasic(USER)).content(JsonUtil.writeValue(updatedTo))).andDo(print()).andExpect(status().isOk());
    MATCHER.assertEquals(UserUtil.updateFromTo(new User(USER), updatedTo), userService.getByEmail("newemail@ya.ru"));
}
Also used : User(ru.javawebinar.topjava.model.User) UserTo(ru.javawebinar.topjava.to.UserTo) Test(org.junit.Test) AbstractControllerTest(ru.javawebinar.topjava.web.AbstractControllerTest)

Aggregations

User (ru.javawebinar.topjava.model.User)13 Test (org.junit.Test)9 AbstractControllerTest (ru.javawebinar.topjava.web.AbstractControllerTest)3 Date (java.util.Date)2 CacheEvict (org.springframework.cache.annotation.CacheEvict)2 Transactional (org.springframework.transaction.annotation.Transactional)2 AuthorizedUser (ru.javawebinar.topjava.AuthorizedUser)2 URI (java.net.URI)1 GenericXmlApplicationContext (org.springframework.context.support.GenericXmlApplicationContext)1 ResultActions (org.springframework.test.web.servlet.ResultActions)1 AbstractJpaUserServiceTest (ru.javawebinar.topjava.service.AbstractJpaUserServiceTest)1 MealWithExceed (ru.javawebinar.topjava.to.MealWithExceed)1 UserTo (ru.javawebinar.topjava.to.UserTo)1 MealRestController (ru.javawebinar.topjava.web.meal.MealRestController)1 AdminRestController (ru.javawebinar.topjava.web.user.AdminRestController)1