Search in sources :

Example 6 with UserEntity

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

the class UsersServiceTest method testSaveCreatesEntity.

@Test
public void testSaveCreatesEntity() throws Exception {
    final UserModelInterface userModel = Models.createUserModel(null, "FirstName", "LastName", "Surname", "email@gmail.com", "hash", true, 1);
    doAnswer(invocation -> {
        final UserEntity userEntity = (UserEntity) invocation.getArguments()[0];
        userEntity.setId(5);
        return null;
    }).when(this.usersMapper).insert(Mockito.any(UserEntity.class));
    this.usersService.save(userModel);
    verify(this.usersMapper, times(1)).insert(this.mapUserEntity(userModel));
    Assert.assertEquals((Integer) 5, userModel.getId());
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) UserEntity(easytests.core.entities.UserEntity)

Example 7 with UserEntity

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

the class UsersService method save.

@Override
public void save(UserModelInterface userModel) {
    final UserEntity userEntity = this.map(userModel);
    if (userEntity.getId() == null) {
        this.usersMapper.insert(userEntity);
        userModel.setId(userEntity.getId());
        return;
    }
    this.usersMapper.update(userEntity);
}
Also used : UserEntity(easytests.core.entities.UserEntity)

Example 8 with UserEntity

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

the class UsersService method delete.

@Override
public void delete(UserModelInterface userModel) {
    final UserEntity userEntity = this.map(userModel);
    if (userEntity.getId() == null) {
        throw new DeleteUnidentifiedModelException();
    }
    this.usersMapper.delete(userEntity);
}
Also used : DeleteUnidentifiedModelException(easytests.core.services.exceptions.DeleteUnidentifiedModelException) UserEntity(easytests.core.entities.UserEntity)

Example 9 with UserEntity

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

the class UserModelTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer userId = 3;
    final String firstName = "FirstName";
    final String lastName = "LastName";
    final String surname = "Surname";
    final String email = "email";
    final String password = "password";
    final Boolean isAdmin = false;
    final Integer state = 2;
    final UserEntity userEntity = Entities.createUserEntityMock(userId, firstName, lastName, surname, email, password, isAdmin, state);
    final UserModel userModel = new UserModel();
    userModel.map(userEntity);
    Assert.assertEquals(userId, userModel.getId());
    Assert.assertEquals(firstName, userModel.getFirstName());
    Assert.assertEquals(lastName, userModel.getLastName());
    Assert.assertEquals(surname, userModel.getSurname());
    Assert.assertEquals(email, userModel.getEmail());
    Assert.assertEquals(password, userModel.getPassword());
    Assert.assertEquals(isAdmin, userModel.getIsAdmin());
    Assert.assertEquals(state, userModel.getState());
    Assert.assertEquals(new ModelsListEmpty(), userModel.getSubjects());
}
Also used : ModelsListEmpty(easytests.core.models.empty.ModelsListEmpty) UserEntity(easytests.core.entities.UserEntity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 10 with UserEntity

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

the class UsersMapperTest method testFindByEmail.

@Test
public void testFindByEmail() throws Exception {
    final UserEntity userEntity = this.usersMapper.findByEmail("email1@gmail.com");
    Assert.assertEquals((Integer) 1, userEntity.getId());
    Assert.assertEquals("FirstName1", userEntity.getFirstName());
    Assert.assertEquals("LastName1", userEntity.getLastName());
    Assert.assertEquals("Surname1", userEntity.getSurname());
    Assert.assertEquals("email1@gmail.com", userEntity.getEmail());
    Assert.assertEquals("hash1", userEntity.getPassword());
    Assert.assertEquals(true, userEntity.getIsAdmin());
    Assert.assertEquals((Integer) 1, 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