Search in sources :

Example 26 with TopicModelInterface

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

the class QuestionsServiceTest method testFindByTopicAbsentList.

@Test
public void testFindByTopicAbsentList() throws Exception {
    final TopicModelInterface topicModel = this.topicsSupport.getModelFixtureMock(0);
    when(this.questionsMapper.findByTopicId(topicModel.getId())).thenReturn(new ArrayList<>(0));
    final List<QuestionModelInterface> questionsFoundedModels = this.questionsService.findByTopic(topicModel);
    Assert.assertEquals(0, questionsFoundedModels.size());
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 27 with TopicModelInterface

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

the class QuestionsServiceTest method testFindByTopicPresentList.

@Test
public void testFindByTopicPresentList() throws Exception {
    final TopicModelInterface topicModel = this.topicsSupport.getModelFixtureMock(0);
    final List<QuestionEntity> questionEntities = this.getQuestionsFixturesEntities();
    when(this.questionsMapper.findByTopicId(topicModel.getId())).thenReturn(questionEntities);
    final List<QuestionModelInterface> questionsFoundedModels = this.questionsService.findByTopic(topicModel);
    this.questionsSupport.assertModelsListEquals(this.getQuestionsFixturesModels(), questionsFoundedModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 28 with TopicModelInterface

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

the class TopicsOptionsTest method testWithRelationsSubjectOnList.

@Test
public void testWithRelationsSubjectOnList() throws Exception {
    final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = new ArrayList<>(2);
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    topicsOptions.setTopicsService(topicsService);
    topicsOptions.setSubjectsService(subjectsService);
    topicsOptions.withSubject(subjectsOptions);
    topicsModels.add(topicModelFirst);
    topicsModels.add(topicModelSecond);
    final SubjectModelInterface subjectModelFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithIdFirst = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelSecond = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithIdSecond = Mockito.mock(SubjectModelInterface.class);
    given(topicModelFirst.getSubject()).willReturn(subjectModelWithIdFirst);
    given(topicModelSecond.getSubject()).willReturn(subjectModelWithIdSecond);
    given(topicModelFirst.getSubject().getId()).willReturn(1);
    given(topicModelSecond.getSubject().getId()).willReturn(2);
    given(subjectsService.find(topicModelFirst.getSubject().getId(), subjectsOptions)).willReturn(subjectModelFirst);
    given(subjectsService.find(topicModelSecond.getSubject().getId(), subjectsOptions)).willReturn(subjectModelSecond);
    final List<TopicModelInterface> topicsModelsWithRelations = topicsOptions.withRelations(topicsModels);
    Assert.assertEquals(topicsModelsWithRelations, topicsModels);
    subjectsService.find(1, subjectsOptions);
    subjectsService.find(2, subjectsOptions);
    verify(topicsModels.get(0)).setSubject(subjectModelFirst);
    verify(topicsModels.get(1)).setSubject(subjectModelSecond);
}
Also used : SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) ArrayList(java.util.ArrayList) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 29 with TopicModelInterface

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

the class TopicsOptionsTest method testWithRelationsQuestionsOnList.

@Test
public void testWithRelationsQuestionsOnList() throws Exception {
    final TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    final TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    final List<TopicModelInterface> topicsModels = new ArrayList<>(2);
    topicsModels.add(topicModelFirst);
    topicsModels.add(topicModelSecond);
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.setTopicsService(topicsService);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModelsFirst = new ArrayList<>();
    questionsModelsFirst.add(Mockito.mock(QuestionModelInterface.class));
    final List<QuestionModelInterface> questionsModelsSecond = new ArrayList<>();
    questionsModelsSecond.add(Mockito.mock(QuestionModelInterface.class));
    given(questionsService.findByTopic(topicModelFirst, questionsOptions)).willReturn(questionsModelsFirst);
    given(questionsService.findByTopic(topicModelSecond, questionsOptions)).willReturn(questionsModelsSecond);
    final List<TopicModelInterface> topicsModelsWithRelations = topicsOptions.withRelations(topicsModels);
    Assert.assertEquals(topicsModelsWithRelations, topicsModels);
    verify(questionsService).findByTopic(topicModelFirst, questionsOptions);
    verify(topicsModels.get(0)).setQuestions(questionsModelsFirst);
    verify(questionsService).findByTopic(topicModelSecond, questionsOptions);
    verify(topicsModels.get(1)).setQuestions(questionsModelsSecond);
}
Also used : QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 30 with TopicModelInterface

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

the class TopicsOptionsTest method testDeleteWithRelationsSubject.

@Test
public void testDeleteWithRelationsSubject() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final SubjectModelInterface subjectModelId = Mockito.mock(SubjectModelInterface.class);
    given(topicModel.getSubject()).willReturn(subjectModelId);
    final SubjectsServiceInterface subjectsService = Mockito.mock(SubjectsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setSubjectsService(subjectsService);
    topicsOptions.setTopicsService(topicsService);
    final SubjectsOptionsInterface subjectsOptions = Mockito.mock(SubjectsOptionsInterface.class);
    topicsOptions.withSubject(subjectsOptions);
    final SubjectModelInterface subjectModel = new SubjectModel();
    topicModel.setSubject(subjectModel);
    final InOrder inOrder = Mockito.inOrder(topicsService, subjectsService);
    topicsOptions.deleteWithRelations(topicModel);
    inOrder.verify(topicsService).delete(topicModel);
    inOrder.verify(subjectsService).save(topicModel.getSubject(), subjectsOptions);
}
Also used : InOrder(org.mockito.InOrder) SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) SubjectModel(easytests.core.models.SubjectModel) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

TopicModelInterface (easytests.core.models.TopicModelInterface)52 Test (org.junit.Test)34 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)32 SubjectModelInterface (easytests.core.models.SubjectModelInterface)18 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)16 ArrayList (java.util.ArrayList)15 QuestionModelInterface (easytests.core.models.QuestionModelInterface)14 TopicsOptionsInterface (easytests.core.options.TopicsOptionsInterface)9 TopicEntity (easytests.core.entities.TopicEntity)8 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)7 InOrder (org.mockito.InOrder)6 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)5 AnswerModelInterface (easytests.core.models.AnswerModelInterface)4 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)4 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)4 GetMapping (org.springframework.web.bind.annotation.GetMapping)4 QuestionEntity (easytests.core.entities.QuestionEntity)3 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)3 SubjectModel (easytests.core.models.SubjectModel)3 TopicModel (easytests.core.models.TopicModel)3