Search in sources :

Example 16 with UserEntity

use of easytests.core.entities.UserEntity in project easy-tests by malinink.

the class UsersServiceTest method testFindAllWithOptions.

@Test
public void testFindAllWithOptions() throws Exception {
    final List<UserEntity> usersEntities = this.getUsersEntities();
    final List<UserModelInterface> usersModels = this.getUsersModels();
    final UsersOptionsInterface usersOptions = Mockito.mock(UsersOptionsInterface.class);
    given(this.usersMapper.findAll()).willReturn(usersEntities);
    given(usersOptions.withRelations(Mockito.anyList())).willReturn(usersModels);
    final List<UserModelInterface> foundedUsersModels = this.usersService.findAll(usersOptions);
    verify(usersOptions).withRelations(usersModels);
    Assert.assertEquals(usersModels, foundedUsersModels);
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) UsersOptionsInterface(easytests.core.options.UsersOptionsInterface) UserEntity(easytests.core.entities.UserEntity)

Example 17 with UserEntity

use of easytests.core.entities.UserEntity in project easy-tests by malinink.

the class UsersServiceTest method mapUserEntity.

private UserEntity mapUserEntity(UserModelInterface userModel) {
    final UserEntity userEntity = new UserEntity();
    userEntity.map(userModel);
    return userEntity;
}
Also used : UserEntity(easytests.core.entities.UserEntity)

Example 18 with UserEntity

use of easytests.core.entities.UserEntity in project easy-tests by malinink.

the class UsersServiceTest method getUsersEntities.

private List<UserEntity> getUsersEntities() {
    final List<UserEntity> usersEntities = new ArrayList<>(2);
    final UserEntity userEntityFirst = Entities.createUserEntityMock(1, "FirstName1", "LastName1", "Surname1", "email1@gmail.com", "hash1", true, 1);
    final UserEntity userEntitySecond = Entities.createUserEntityMock(2, "FirstName2", "LastName2", "Surname2", "email2@gmail.com", "hash2", false, 2);
    usersEntities.add(userEntityFirst);
    usersEntities.add(userEntitySecond);
    return usersEntities;
}
Also used : ArrayList(java.util.ArrayList) UserEntity(easytests.core.entities.UserEntity)

Example 19 with UserEntity

use of easytests.core.entities.UserEntity in project easy-tests by malinink.

the class UsersServiceTest method testFindByEmailPresentModel.

@Test
public void testFindByEmailPresentModel() throws Exception {
    final String email = "new.email@gmail.com";
    final UserEntity userEntity = Entities.createUserEntityMock(1, "NewFirstName", "NewLastName1", "NewSurname1", email, "newhash1", false, 3);
    given(this.usersMapper.findByEmail(email)).willReturn(userEntity);
    final UserModelInterface userModel = this.usersService.findByEmail(email);
    Assert.assertEquals(this.mapUserModel(userEntity), userModel);
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) UserEntity(easytests.core.entities.UserEntity)

Example 20 with UserEntity

use of easytests.core.entities.UserEntity in project easy-tests by malinink.

the class UsersMapperTest method testInsert.

@Test
public void testInsert() throws Exception {
    final Integer id = this.usersMapper.findAll().size() + 1;
    final String firstName = "FirstName";
    final String lastName = "LastName";
    final String surname = "Surname";
    final String email = "email@gmail.com";
    final String password = "hash";
    final Boolean isAdmin = true;
    final Integer state = 1;
    UserEntity userEntity = Mockito.mock(UserEntity.class);
    Mockito.when(userEntity.getFirstName()).thenReturn(firstName);
    Mockito.when(userEntity.getLastName()).thenReturn(lastName);
    Mockito.when(userEntity.getSurname()).thenReturn(surname);
    Mockito.when(userEntity.getEmail()).thenReturn(email);
    Mockito.when(userEntity.getPassword()).thenReturn(password);
    Mockito.when(userEntity.getIsAdmin()).thenReturn(isAdmin);
    Mockito.when(userEntity.getState()).thenReturn(state);
    this.usersMapper.insert(userEntity);
    verify(userEntity, times(1)).setId(id);
    userEntity = this.usersMapper.find(id);
    Assert.assertEquals(id, userEntity.getId());
    Assert.assertEquals(firstName, userEntity.getFirstName());
    Assert.assertEquals(lastName, userEntity.getLastName());
    Assert.assertEquals(surname, userEntity.getSurname());
    Assert.assertEquals(email, userEntity.getEmail());
    Assert.assertEquals(password, userEntity.getPassword());
    Assert.assertEquals(isAdmin, userEntity.getIsAdmin());
    Assert.assertEquals(state, userEntity.getState());
}
Also used : UserEntity(easytests.core.entities.UserEntity) Test(org.junit.Test)

Aggregations

UserEntity (easytests.core.entities.UserEntity)21 UserModelInterface (easytests.core.models.UserModelInterface)7 Test (org.junit.Test)7 UsersOptionsInterface (easytests.core.options.UsersOptionsInterface)3 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)1 DeleteUnidentifiedModelException (easytests.core.services.exceptions.DeleteUnidentifiedModelException)1 ArrayList (java.util.ArrayList)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1