Search in sources :

Example 36 with UserModelInterface

use of easytests.core.models.UserModelInterface 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 37 with UserModelInterface

use of easytests.core.models.UserModelInterface in project easy-tests by malinink.

the class UserEntityTest 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 UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
    Mockito.when(userModel.getId()).thenReturn(userId);
    Mockito.when(userModel.getFirstName()).thenReturn(firstName);
    Mockito.when(userModel.getLastName()).thenReturn(lastName);
    Mockito.when(userModel.getSurname()).thenReturn(surname);
    final UserEntity userEntity = new UserEntity();
    userEntity.map(userModel);
    Assert.assertEquals(userId, userEntity.getId());
    Assert.assertEquals(firstName, userEntity.getFirstName());
    Assert.assertEquals(lastName, userEntity.getLastName());
    Assert.assertEquals(surname, userEntity.getSurname());
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) Test(org.junit.Test)

Example 38 with UserModelInterface

use of easytests.core.models.UserModelInterface in project easy-tests by malinink.

the class UsersOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
    final UsersOptionsInterface usersOptions = new UsersOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    usersOptions.setSubjectsService(subjectsService);
    usersOptions.withSubjects(subjectsOptions);
    final List<SubjectModelInterface> subjectsModels = new ArrayList<>();
    subjectsModels.add(Mockito.mock(SubjectModelInterface.class));
    given(subjectsService.findByUser(userModel, subjectsOptions)).willReturn(subjectsModels);
    final UserModelInterface userModelWithRelations = usersOptions.withRelations(userModel);
    Assert.assertEquals(userModel, userModelWithRelations);
    verify(subjectsService).findByUser(userModel, subjectsOptions);
    verify(userModel).setSubjects(subjectsModels);
    verify(userModel).setSubjects(Mockito.anyList());
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 39 with UserModelInterface

use of easytests.core.models.UserModelInterface in project easy-tests by malinink.

the class UsersOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final UserModelInterface userModel = Mockito.mock(UserModelInterface.class);
    final UsersOptionsInterface usersOptions = new UsersOptions();
    final UsersServiceInterface usersService = Mockito.mock(UsersServiceInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    usersOptions.setUsersService(usersService);
    usersOptions.setSubjectsService(subjectsService);
    usersOptions.withSubjects(subjectsOptions);
    final List<SubjectModelInterface> subjectsModels = new ArrayList<>();
    subjectsModels.add(Mockito.mock(SubjectModelInterface.class));
    given(userModel.getSubjects()).willReturn(subjectsModels);
    final InOrder inOrder = Mockito.inOrder(subjectsService, usersService);
    usersOptions.deleteWithRelations(userModel);
    inOrder.verify(subjectsService).delete(subjectsModels, subjectsOptions);
    inOrder.verify(usersService).delete(userModel);
}
Also used : UsersServiceInterface(easytests.core.services.UsersServiceInterface) UserModelInterface(easytests.core.models.UserModelInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with UserModelInterface

use of easytests.core.models.UserModelInterface in project easy-tests by malinink.

the class UsersOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final UserModelInterface userModelFirst = Mockito.mock(UserModelInterface.class);
    userModelFirst.setId(1);
    final UserModelInterface userModelSecond = Mockito.mock(UserModelInterface.class);
    userModelSecond.setId(2);
    final List<UserModelInterface> usersModels = new ArrayList<>(2);
    usersModels.add(userModelFirst);
    usersModels.add(userModelSecond);
    final UsersOptionsInterface usersOptions = new UsersOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    usersOptions.setSubjectsService(subjectsService);
    usersOptions.withSubjects(subjectsOptions);
    final List<SubjectModelInterface> subjectsModelsFirst = new ArrayList<>();
    subjectsModelsFirst.add(Mockito.mock(SubjectModelInterface.class));
    final List<SubjectModelInterface> subjectsModelsSecond = new ArrayList<>();
    subjectsModelsSecond.add(Mockito.mock(SubjectModelInterface.class));
    subjectsModelsSecond.add(Mockito.mock(SubjectModelInterface.class));
    given(subjectsService.findByUser(userModelFirst, subjectsOptions)).willReturn(subjectsModelsFirst);
    given(subjectsService.findByUser(userModelSecond, subjectsOptions)).willReturn(subjectsModelsSecond);
    final List<UserModelInterface> usersModelsWithRelations = usersOptions.withRelations(usersModels);
    Assert.assertEquals(usersModelsWithRelations, usersModels);
    verify(subjectsService).findByUser(userModelFirst, subjectsOptions);
    verify(usersModels.get(0)).setSubjects(subjectsModelsFirst);
    verify(usersModels.get(0)).setSubjects(Mockito.anyList());
    verify(subjectsService).findByUser(userModelSecond, subjectsOptions);
    verify(usersModels.get(1)).setSubjects(subjectsModelsSecond);
    verify(usersModels.get(1)).setSubjects(Mockito.anyList());
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

UserModelInterface (easytests.core.models.UserModelInterface)40 Test (org.junit.Test)11 SubjectModelInterface (easytests.core.models.SubjectModelInterface)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 UserEntity (easytests.core.entities.UserEntity)7 UsersOptionsInterface (easytests.core.options.UsersOptionsInterface)7 ArrayList (java.util.ArrayList)6 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)5 SubjectEntity (easytests.core.entities.SubjectEntity)3 UserModel (easytests.core.models.UserModel)3 UsersServiceInterface (easytests.core.services.UsersServiceInterface)2 InOrder (org.mockito.InOrder)2 UserModelDto (easytests.admin.dto.UserModelDto)1 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)1 SubjectModel (easytests.core.models.SubjectModel)1 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)1 SubjectsOptionsInterface (easytests.core.options.SubjectsOptionsInterface)1 UsersOptions (easytests.core.options.UsersOptions)1 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)1