Search in sources :

Example 6 with TopicsServiceInterface

use of easytests.core.services.TopicsServiceInterface in project easy-tests by malinink.

the class QuestionsOptionsTest method testDeleteWithRelations.

@Test
public void testDeleteWithRelations() throws Exception {
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
    final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
    questionsOptions.setQuestionsService(questionsService);
    questionsOptions.setAnswersService(answersService);
    questionsOptions.withAnswers(answersOptions);
    questionsOptions.setTopicsService(topicsService);
    questionsOptions.withTopic(topicsOptions);
    final List<AnswerModelInterface> answersModels = new ArrayList<>();
    answersModels.add(Mockito.mock(AnswerModelInterface.class));
    TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    given(questionModel.getAnswers()).willReturn(answersModels);
    given(questionModel.getTopic()).willReturn(topicModel);
    final InOrder inOrder = Mockito.inOrder(answersService, questionsService, topicsService);
    questionsOptions.deleteWithRelations(questionModel);
    inOrder.verify(answersService).delete(answersModels, answersOptions);
    inOrder.verify(questionsService).delete(questionModel);
    inOrder.verify(topicsService).delete(topicModel, topicsOptions);
}
Also used : InOrder(org.mockito.InOrder) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) AnswersServiceInterface(easytests.core.services.AnswersServiceInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) AnswerModelInterface(easytests.core.models.AnswerModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with TopicsServiceInterface

use of easytests.core.services.TopicsServiceInterface in project easy-tests by malinink.

the class QuestionsOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final QuestionModelInterface questionModelFirst = Mockito.mock(QuestionModelInterface.class);
    questionModelFirst.setId(1);
    given(questionModelFirst.getTopic()).willReturn(new TopicModelEmpty(1));
    given(questionModelFirst.getQuestionType()).willReturn(new QuestionTypeModelEmpty(1));
    final QuestionModelInterface questionModelSecond = Mockito.mock(QuestionModelInterface.class);
    questionModelSecond.setId(2);
    given(questionModelSecond.getTopic()).willReturn(new TopicModelEmpty(2));
    given(questionModelSecond.getQuestionType()).willReturn(new QuestionTypeModelEmpty(2));
    final List<QuestionModelInterface> questionsModels = new ArrayList<>(2);
    questionsModels.add(questionModelFirst);
    questionsModels.add(questionModelSecond);
    final QuestionsOptionsInterface questionsOptions = new QuestionsOptions();
    final AnswersServiceInterface answersService = Mockito.mock(AnswersServiceInterface.class);
    final AnswersOptionsInterface answersOptions = Mockito.mock(AnswersOptionsInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    final TopicsOptionsInterface topicsOptions = Mockito.mock(TopicsOptionsInterface.class);
    final QuestionTypesServiceInterface questionTypesService = Mockito.mock(QuestionTypesServiceInterface.class);
    final QuestionTypesOptionsInterface questionTypesOptions = Mockito.mock(QuestionTypesOptionsInterface.class);
    questionsOptions.setAnswersService(answersService);
    questionsOptions.withAnswers(answersOptions);
    questionsOptions.setTopicsService(topicsService);
    questionsOptions.withTopic(topicsOptions);
    questionsOptions.setQuestionTypesService(questionTypesService);
    questionsOptions.withQuestionType(questionTypesOptions);
    final List<AnswerModelInterface> answersModelsFirst = new ArrayList<>();
    answersModelsFirst.add(Mockito.mock(AnswerModelInterface.class));
    final List<AnswerModelInterface> answersModelsSecond = new ArrayList<>();
    answersModelsSecond.add(Mockito.mock(AnswerModelInterface.class));
    TopicModelInterface topicModelFirst = Mockito.mock(TopicModelInterface.class);
    TopicModelInterface topicModelSecond = Mockito.mock(TopicModelInterface.class);
    QuestionTypeModelInterface questionTypeModelFirst = Mockito.mock(QuestionTypeModelInterface.class);
    QuestionTypeModelInterface questionTypeModelSecond = Mockito.mock(QuestionTypeModelInterface.class);
    given(answersService.findByQuestion(questionModelFirst, answersOptions)).willReturn(answersModelsFirst);
    given(answersService.findByQuestion(questionModelSecond, answersOptions)).willReturn(answersModelsSecond);
    given(topicsService.find(questionModelFirst.getTopic().getId(), topicsOptions)).willReturn(topicModelFirst);
    given(topicsService.find(questionModelSecond.getTopic().getId(), topicsOptions)).willReturn(topicModelSecond);
    given(questionTypesService.find(questionModelFirst.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelFirst);
    given(questionTypesService.find(questionModelSecond.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModelSecond);
    final List<QuestionModelInterface> questionsModelsWithRelations = questionsOptions.withRelations(questionsModels);
    Assert.assertEquals(questionsModelsWithRelations, questionsModels);
    verify(answersService).findByQuestion(questionModelFirst, answersOptions);
    verify(questionsModels.get(0)).setAnswers(answersModelsFirst);
    verify(questionsModels.get(0)).setAnswers(Mockito.anyList());
    verify(answersService).findByQuestion(questionModelSecond, answersOptions);
    verify(questionsModels.get(1)).setAnswers(answersModelsSecond);
    verify(questionsModels.get(1)).setAnswers(Mockito.anyList());
    verify(topicsService).find(questionModelFirst.getTopic().getId(), topicsOptions);
    verify(topicsService).find(questionModelSecond.getTopic().getId(), topicsOptions);
    verify(questionsModels.get(0)).setTopic(topicModelFirst);
    verify(questionsModels.get(1)).setTopic(topicModelSecond);
    verify(questionTypesService).find(questionModelFirst.getQuestionType().getId(), questionTypesOptions);
    verify(questionTypesService).find(questionModelSecond.getQuestionType().getId(), questionTypesOptions);
    verify(questionModelFirst).setQuestionType(questionTypeModelFirst);
    verify(questionModelSecond).setQuestionType(questionTypeModelSecond);
}
Also used : QuestionTypesServiceInterface(easytests.core.services.QuestionTypesServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) AnswersServiceInterface(easytests.core.services.AnswersServiceInterface) QuestionTypeModelEmpty(easytests.core.models.empty.QuestionTypeModelEmpty) TopicModelInterface(easytests.core.models.TopicModelInterface) TopicModelEmpty(easytests.core.models.empty.TopicModelEmpty) QuestionTypeModelInterface(easytests.core.models.QuestionTypeModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) AnswerModelInterface(easytests.core.models.AnswerModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with TopicsServiceInterface

use of easytests.core.services.TopicsServiceInterface 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 9 with TopicsServiceInterface

use of easytests.core.services.TopicsServiceInterface 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 10 with TopicsServiceInterface

use of easytests.core.services.TopicsServiceInterface 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

TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)18 Test (org.junit.Test)18 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)18 TopicModelInterface (easytests.core.models.TopicModelInterface)16 ArrayList (java.util.ArrayList)11 QuestionModelInterface (easytests.core.models.QuestionModelInterface)10 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)7 InOrder (org.mockito.InOrder)6 SubjectModelInterface (easytests.core.models.SubjectModelInterface)5 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)5 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)5 AnswerModelInterface (easytests.core.models.AnswerModelInterface)4 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)4 IssueStandardTopicPriorityModelInterface (easytests.core.models.IssueStandardTopicPriorityModelInterface)3 SubjectModel (easytests.core.models.SubjectModel)3 IssueStandardsServiceInterface (easytests.core.services.IssueStandardsServiceInterface)3 QuestionTypesServiceInterface (easytests.core.services.QuestionTypesServiceInterface)3 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)2 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)2 IssueStandardModelEmpty (easytests.core.models.empty.IssueStandardModelEmpty)2