Search in sources :

Example 6 with SubjectModelInterface

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

the class TopicsServiceTest method testFindBySubjectAbsentList.

@Test
public void testFindBySubjectAbsentList() throws Exception {
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelFixtureMock(0);
    when(this.topicsMapper.findBySubjectId(subjectModel.getId())).thenReturn(new ArrayList<>(0));
    final List<TopicModelInterface> topicFoundedModels = this.topicsService.findBySubject(subjectModel);
    Assert.assertNotNull(topicFoundedModels);
    Assert.assertEquals(0, topicFoundedModels.size());
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with SubjectModelInterface

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

the class TopicsServiceTest method testFindBySubjectWithOptions.

@Test
public void testFindBySubjectWithOptions() throws Exception {
    final ArgumentCaptor<List> listCaptor = ArgumentCaptor.forClass(List.class);
    final List<TopicEntity> topicsEntities = this.getTopicsFixturesEntities();
    final List<TopicModelInterface> topicsModels = this.getTopicsFixturesModels();
    final TopicsOptionsInterface topicOptions = mock(TopicsOptionsInterface.class);
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelFixtureMock(0);
    when(this.topicsMapper.findBySubjectId(subjectModel.getId())).thenReturn(topicsEntities);
    when(topicOptions.withRelations(listCaptor.capture())).thenReturn(topicsModels);
    final List<TopicModelInterface> topicsFoundedModels = this.topicsService.findBySubject(subjectModel, topicOptions);
    this.topicsSupport.assertModelsListEquals(topicsModels, listCaptor.getValue());
    Assert.assertSame(topicsModels, topicsFoundedModels);
    this.assertServicesSet(topicOptions);
}
Also used : TopicsOptionsInterface(easytests.core.options.TopicsOptionsInterface) TopicEntity(easytests.core.entities.TopicEntity) ArrayList(java.util.ArrayList) List(java.util.List) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with SubjectModelInterface

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

the class IssueStandardOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() 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.saveWithRelations(issueStandardModel);
    inOrder.verify(subjectsService, times(1)).save(issueStandardModel.getSubject(), subjectsOptions);
    inOrder.verify(issueStandardsService, times(1)).save(issueStandardModel);
    inOrder.verify(topicPrioritiesService, times(1)).save(issueStandardModel.getTopicPriorities(), topicPrioritiesOptions);
    inOrder.verify(questionTypeOptionsService, times(1)).save(issueStandardModel.getQuestionTypeOptions(), questionTypeOptionsOptions);
}
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 9 with SubjectModelInterface

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

the class IssuesOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final IssueModelInterface issueModelFirst = Mockito.mock(IssueModelInterface.class);
    issueModelFirst.setId(1);
    given(issueModelFirst.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssueModelInterface issueModelSecond = Mockito.mock(IssueModelInterface.class);
    issueModelSecond.setId(2);
    given(issueModelSecond.getSubject()).willReturn(new SubjectModelEmpty(2));
    final List<IssueModelInterface> issuesModels = new ArrayList<>(2);
    issuesModels.add(issueModelFirst);
    issuesModels.add(issueModelSecond);
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final List<QuizModelInterface> quizzesModelsFirst = new ArrayList<>();
    quizzesModelsFirst.add(Mockito.mock(QuizModelInterface.class));
    final List<QuizModelInterface> quizzesModelsSecond = new ArrayList<>();
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    quizzesModelsSecond.add(Mockito.mock(QuizModelInterface.class));
    given(quizzesService.findByIssue(issueModelFirst, quizzesOptions)).willReturn(quizzesModelsFirst);
    given(quizzesService.findByIssue(issueModelSecond, quizzesOptions)).willReturn(quizzesModelsSecond);
    final SubjectModelInterface subjectModelFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelSecond = Mockito.mock(SubjectModelInterface.class);
    given(subjectsService.find(1, subjectsOptions)).willReturn(subjectModelFirst);
    given(subjectsService.find(2, subjectsOptions)).willReturn(subjectModelSecond);
    final List<IssueModelInterface> issuesModelsWithRelations = issuesOptions.withRelations(issuesModels);
    Assert.assertEquals(issuesModelsWithRelations, issuesModels);
    verify(quizzesService).findByIssue(issueModelFirst, quizzesOptions);
    verify(subjectsService).find(1, subjectsOptions);
    verify(issuesModels.get(0)).setQuizzes(quizzesModelsFirst);
    verify(issuesModels.get(0)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(0)).setSubject(subjectModelFirst);
    verify(quizzesService).findByIssue(issueModelSecond, quizzesOptions);
    verify(subjectsService).find(2, subjectsOptions);
    verify(issuesModels.get(1)).setQuizzes(quizzesModelsSecond);
    verify(issuesModels.get(1)).setQuizzes(Mockito.anyList());
    verify(issuesModels.get(1)).setSubject(subjectModelSecond);
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) SubjectModelInterface(easytests.core.models.SubjectModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) IssueModelInterface(easytests.core.models.IssueModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 10 with SubjectModelInterface

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

the class IssuesOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final IssueModelInterface issueModel = Mockito.mock(IssueModelInterface.class);
    issueModel.setId(1);
    given(issueModel.getSubject()).willReturn(new SubjectModelEmpty(1));
    final IssuesOptionsInterface issuesOptions = new IssuesOptions();
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuizzesOptionsInterface quizzesOptions = Mockito.mock(QuizzesOptionsInterface.class);
    issuesOptions.setSubjectsService(subjectsService);
    issuesOptions.setQuizzesService(quizzesService);
    issuesOptions.withSubject(subjectsOptions);
    issuesOptions.withQuizzes(quizzesOptions);
    final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
    final List<QuizModelInterface> quizzesModels = new ArrayList<>();
    quizzesModels.add(Mockito.mock(QuizModelInterface.class));
    given(subjectsService.find(issueModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    given(quizzesService.findByIssue(issueModel, quizzesOptions)).willReturn(quizzesModels);
    final IssueModelInterface issueModelWithRelations = issuesOptions.withRelations(issueModel);
    Assert.assertEquals(issueModel, issueModelWithRelations);
    verify(subjectsService).find(1, subjectsOptions);
    verify(quizzesService).findByIssue(issueModel, quizzesOptions);
    verify(issueModel).setQuizzes(quizzesModels);
    verify(issueModel).setQuizzes(Mockito.anyList());
}
Also used : SubjectModelEmpty(easytests.core.models.empty.SubjectModelEmpty) QuizModelInterface(easytests.core.models.QuizModelInterface) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) 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