Search in sources :

Example 26 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserDaoImplTest method testUpdateUser_expectChangedValueAfterUpdate.

@Test
public void testUpdateUser_expectChangedValueAfterUpdate() throws Exception {
    User userToCreate = UserFactory.createNewUserTemplate();
    userToCreate.setDisplayName("old display name");
    userToCreate = userService.createUser(userToCreate);
    userToCreate.setDisplayName("new display name");
    userService.updateUser(userToCreate);
    User foundUser = userService.getUserByUuid(userToCreate.getUuid());
    assertEquals(userToCreate.getDisplayName(), foundUser.getDisplayName());
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Example 27 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class EntityChangedEventAdapterTest method testDeserializeExpectOkForAllowedClass.

@Test
@SuppressWarnings("unchecked")
public void testDeserializeExpectOkForAllowedClass() {
    Gson gson = getFixture();
    EntityChangedEvent<User> evt = gson.fromJson("{\"ct\": \"asdasd\", \"vt\": \"org.summerb.microservices.users.api.dto.User\", \"v\": {\"email\": \"asd\"}}", EntityChangedEvent.class);
    assertNotNull(evt);
    assertEquals("asd", evt.getValue().getEmail());
}
Also used : User(org.summerb.microservices.users.api.dto.User) Gson(com.google.gson.Gson) Test(org.junit.Test)

Example 28 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplFactory method createUsersServiceImpl.

public static UserServiceImpl createUsersServiceImpl() {
    UserServiceImpl ret = new UserServiceImpl();
    UserDao userDao = Mockito.mock(UserDao.class);
    ret.setUserDao(userDao);
    ret.setEventBus(Mockito.mock(EventBus.class));
    User existingUser = UserFactory.createExistingUser();
    when(userDao.findUserByUuid(UserFactory.EXISTENT_USER)).thenReturn(existingUser);
    when(userDao.findUserByUuid(UserFactory.EXISTENT_USER_2_PROBLEM_WITH_PASSWORD)).thenReturn(UserFactory.createExistingUser2());
    when(userDao.findUserByUuid(UserFactory.EXISTENT_USER_WITH_MISSING_PASSWORD)).thenReturn(UserFactory.createUserWithMissingPassword());
    when(userDao.findUserByUuid(UserFactory.NON_EXISTENT_USER)).thenReturn(null);
    when(userDao.findUserByUuid(UserFactory.USER_RESULT_IN_EXCEPTION)).thenThrow(new IllegalStateException("Simulate unexpected excception"));
    when(userDao.findUserByEmail(UserFactory.EXISTENT_USER_EMAIL)).thenReturn(existingUser);
    when(userDao.findUserByEmail(UserFactory.NON_EXISTENT_USER_EMAIL)).thenReturn(null);
    when(userDao.findUserByEmail(UserFactory.USER_EMAIL_RESULT_IN_EXCEPTION)).thenThrow(new IllegalStateException("Simulate unexpected excception"));
    when(userDao.findUserByDisplayNamePartial(eq(UserFactory.EXISTENT_USER), any(PagerParams.class))).thenThrow(new IllegalStateException("Simulate unexpected excception"));
    when(userDao.findUserByUuid(UserFactory.EXISTENT_USER_WITH_EXPIRED_TOKEN)).thenReturn(UserFactory.createUserWithExpiredToken());
    when(userDao.updateUser(UserFactory.createDuplicateUser())).thenThrow(new DuplicateKeyException("Simulate unexpected excception"));
    return ret;
}
Also used : User(org.summerb.microservices.users.api.dto.User) UserDao(org.summerb.microservices.users.impl.dao.UserDao) PagerParams(org.summerb.approaches.jdbccrud.api.dto.PagerParams) EventBus(com.google.common.eventbus.EventBus) DuplicateKeyException(org.springframework.dao.DuplicateKeyException)

Example 29 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplTest method testCreateUser_whitebox_expectDuplicateUserException.

@Test(expected = FieldValidationException.class)
public void testCreateUser_whitebox_expectDuplicateUserException() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    User user = UserFactory.createNewUserTemplate();
    doThrow(new DuplicateKeyException("duplicate user")).when(fixture.getUserDao()).createUser(any(User.class));
    fixture.createUser(user);
    fail();
}
Also used : User(org.summerb.microservices.users.api.dto.User) DuplicateKeyException(org.springframework.dao.DuplicateKeyException) Test(org.junit.Test)

Example 30 with User

use of org.summerb.microservices.users.api.dto.User in project summerb by skarpushin.

the class UserServiceImplTest method testGetUserByEmail_blackbox_expectFoundUser.

@Test
public void testGetUserByEmail_blackbox_expectFoundUser() throws Exception {
    UserServiceImpl fixture = UserServiceImplFactory.createUsersServiceImpl();
    when(fixture.getUserDao().findUserByEmail(any(String.class))).thenReturn(UserFactory.createNewUserTemplate());
    User user = fixture.getUserByEmail(UserFactory.createNewUserTemplate().getEmail());
    assertNotNull(user);
}
Also used : User(org.summerb.microservices.users.api.dto.User) Test(org.junit.Test)

Aggregations

User (org.summerb.microservices.users.api.dto.User)61 Test (org.junit.Test)34 UserNotFoundException (org.summerb.microservices.users.api.exceptions.UserNotFoundException)13 FieldValidationException (org.summerb.approaches.validation.FieldValidationException)11 AuthToken (org.summerb.microservices.users.api.dto.AuthToken)11 UserServiceUnexpectedException (org.summerb.microservices.users.api.exceptions.UserServiceUnexpectedException)11 Transactional (org.springframework.transaction.annotation.Transactional)8 Date (java.util.Date)4 PagerParams (org.summerb.approaches.jdbccrud.api.dto.PagerParams)4 DuplicateKeyException (org.springframework.dao.DuplicateKeyException)3 InvalidPasswordException (org.summerb.microservices.users.api.exceptions.InvalidPasswordException)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 UserDetailsImpl (org.summerb.approaches.springmvc.security.dto.UserDetailsImpl)2 ValidationContext (org.summerb.approaches.validation.ValidationContext)2 GenericException (org.summerb.utils.exceptions.GenericException)2 CacheBuilder (com.google.common.cache.CacheBuilder)1 EventBus (com.google.common.eventbus.EventBus)1 Gson (com.google.gson.Gson)1 Locale (java.util.Locale)1 Secured (org.springframework.security.access.annotation.Secured)1