Search in sources :

Example 61 with SubjectModelInterface

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

the class IssueStandardOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final IssueStandardsOptionsInterface issueStandardsOptions = new IssueStandardsOptions();
    final IssueStandardsServiceInterface issueStandardsService = Mockito.mock(IssueStandardsServiceInterface.class);
    final IssueStandardTopicPrioritiesServiceInterface topicPrioritiesService = Mockito.mock(IssueStandardTopicPrioritiesServiceInterface.class);
    final IssueStandardTopicPrioritiesOptionsInterface topicPrioritiesOptions = Mockito.mock(IssueStandardTopicPrioritiesOptionsInterface.class);
    final IssueStandardQuestionTypeOptionsServiceInterface questionTypeOptionsService = Mockito.mock(IssueStandardQuestionTypeOptionsServiceInterface.class);
    final IssueStandardQuestionTypeOptionsOptionsInterface questionTypeOptionsOptions = Mockito.mock(IssueStandardQuestionTypeOptionsOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final Integer subjectId = 3;
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    Mockito.when(subjectModel.getId()).thenReturn(subjectId);
    final IssueStandardModelInterface issueStandardModel = Mockito.mock(IssueStandardModelInterface.class);
    Mockito.when(issueStandardModel.getTopicPriorities()).thenReturn(new ArrayList<>());
    Mockito.when(issueStandardModel.getQuestionTypeOptions()).thenReturn(new ArrayList<>());
    Mockito.when(issueStandardModel.getSubject()).thenReturn(subjectModel);
    issueStandardsOptions.setIssueStandardsService(issueStandardsService);
    issueStandardsOptions.setTopicPrioritiesService(topicPrioritiesService);
    issueStandardsOptions.setQuestionTypeOptionsService(questionTypeOptionsService);
    issueStandardsOptions.setSubjectsService(subjectsService);
    issueStandardsOptions.withTopicPriorities(topicPrioritiesOptions).withQuestionTypeOptions(questionTypeOptionsOptions).withSubject(subjectsOptions);
    final InOrder inOrder = Mockito.inOrder(subjectsService, issueStandardsService, topicPrioritiesService, questionTypeOptionsService);
    issueStandardsOptions.deleteWithRelations(issueStandardModel);
    inOrder.verify(topicPrioritiesService, times(1)).delete(issueStandardModel.getTopicPriorities(), topicPrioritiesOptions);
    inOrder.verify(questionTypeOptionsService, times(1)).delete(issueStandardModel.getQuestionTypeOptions(), questionTypeOptionsOptions);
    inOrder.verify(issueStandardsService, times(1)).delete(issueStandardModel);
    inOrder.verify(subjectsService, times(1)).delete(issueStandardModel.getSubject(), subjectsOptions);
}
Also used : IssueStandardsServiceInterface(easytests.core.services.IssueStandardsServiceInterface) InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) IssueStandardTopicPrioritiesServiceInterface(easytests.core.services.IssueStandardTopicPrioritiesServiceInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) IssueStandardModelInterface(easytests.core.models.IssueStandardModelInterface) IssueStandardQuestionTypeOptionsServiceInterface(easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 62 with SubjectModelInterface

use of easytests.core.models.SubjectModelInterface 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 63 with SubjectModelInterface

use of easytests.core.models.SubjectModelInterface 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 64 with SubjectModelInterface

use of easytests.core.models.SubjectModelInterface 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

SubjectModelInterface (easytests.core.models.SubjectModelInterface)64 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)21 TopicModelInterface (easytests.core.models.TopicModelInterface)18 ArrayList (java.util.ArrayList)16 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)15 SubjectsOptionsInterface (easytests.core.options.SubjectsOptionsInterface)11 UserModelInterface (easytests.core.models.UserModelInterface)9 SubjectEntity (easytests.core.entities.SubjectEntity)7 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)7 SubjectModel (easytests.core.models.SubjectModel)6 InOrder (org.mockito.InOrder)6 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)5 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 TopicEntity (easytests.core.entities.TopicEntity)4 IssueModelInterface (easytests.core.models.IssueModelInterface)4 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)4 IssueStandardQuestionTypeOptionsServiceInterface (easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface)4 IssueStandardTopicPrioritiesServiceInterface (easytests.core.services.IssueStandardTopicPrioritiesServiceInterface)4