Search in sources :

Example 6 with UserModelInterface

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

the class ObjectsControllerTest method testViewReturnsData.

@Test
public void testViewReturnsData() throws Exception {
    final UserModelInterface userModel = this.usersSupport.getModelFixtureMock(0);
    when(this.usersOptionsBuilder.forAuth()).thenReturn(new UsersOptions());
    when(this.usersService.find(any(Integer.class), any(UsersOptionsInterface.class))).thenReturn(userModel);
    mvc.perform(get("/v1/objects/1/").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(MediaType.APPLICATION_JSON)).andReturn();
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) UsersOptions(easytests.core.options.UsersOptions) UsersOptionsInterface(easytests.core.options.UsersOptionsInterface) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 7 with UserModelInterface

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

the class UsersOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() 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.saveWithRelations(userModel);
    inOrder.verify(usersService).save(userModel);
    inOrder.verify(subjectsService).save(subjectsModels, subjectsOptions);
}
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 8 with UserModelInterface

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

the class UsersOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    final UserModelInterface userModel = null;
    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 UserModelInterface userModelWithRelations = usersOptions.withRelations(userModel);
    Assert.assertEquals(null, userModelWithRelations);
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 9 with UserModelInterface

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

the class UsersServiceTest method testFindByEmailWithOptions.

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

Example 10 with UserModelInterface

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

the class UsersServiceTest method testFindWithOptions.

@Test
public void testFindWithOptions() throws Exception {
    final Integer id = 1;
    final UserEntity userEntity = Entities.createUserEntityMock(id, "NewFirstName", "NewLastName1", "NewSurname1", "new.email@gmail.com", "newhash1", false, 3);
    final UserModelInterface userModel = this.mapUserModel(userEntity);
    final UsersOptionsInterface usersOptions = Mockito.mock(UsersOptionsInterface.class);
    given(this.usersMapper.find(id)).willReturn(userEntity);
    given(usersOptions.withRelations(userModel)).willReturn(userModel);
    final UserModelInterface foundedUserModel = this.usersService.find(id, usersOptions);
    Assert.assertEquals(userModel, foundedUserModel);
    verify(usersOptions).withRelations(userModel);
}
Also used : UserModelInterface(easytests.core.models.UserModelInterface) UsersOptionsInterface(easytests.core.options.UsersOptionsInterface) UserEntity(easytests.core.entities.UserEntity)

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