Search in sources :

Example 36 with QuestionModelInterface

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

the class QuestionsServiceTest method testFindByTopic.

@Test
public void testFindByTopic() throws Exception {
    final Integer topicId = 7;
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionEntity questionEntityFirst = Entities.createQuestionEntityMock(3, "test3", 1, topicId);
    final QuestionEntity questionEntitySecond = Entities.createQuestionEntityMock(12, "test12", 1, topicId);
    final List<QuestionEntity> questionsEntities = new ArrayList<>();
    questionsEntities.add(questionEntityFirst);
    questionsEntities.add(questionEntitySecond);
    Mockito.when(topicModel.getId()).thenReturn(topicId);
    given(this.questionsMapper.findByTopicId(topicId)).willReturn(questionsEntities);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    questionsModels.add(this.mapQuestionModel(questionEntityFirst));
    questionsModels.add(this.mapQuestionModel(questionEntitySecond));
    final List<QuestionModelInterface> foundedQuestionsModels = this.questionsService.findByTopic(topicModel);
    verify(this.questionsMapper).findByTopicId(topicId);
    Assert.assertEquals(questionsModels, foundedQuestionsModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 37 with QuestionModelInterface

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

the class PointsOptionsTest method testWithRelationsOnModelsList.

@Test
public void testWithRelationsOnModelsList() throws Exception {
    final PointModelInterface pointModelFirst = Mockito.mock(PointModelInterface.class);
    final PointModelInterface pointModelSecond = Mockito.mock(PointModelInterface.class);
    pointModelFirst.setId(1);
    pointModelSecond.setId(2);
    given(pointModelFirst.getQuiz()).willReturn(new QuizModelEmpty(1));
    given(pointModelSecond.getQuiz()).willReturn(new QuizModelEmpty(2));
    given(pointModelFirst.getQuestion()).willReturn(new QuestionModelEmpty(1));
    given(pointModelSecond.getQuestion()).willReturn(new QuestionModelEmpty(2));
    final List<PointModelInterface> pointsModels = new ArrayList<>();
    pointsModels.add(pointModelFirst);
    pointsModels.add(pointModelSecond);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    final QuizzesServiceInterface quizzesService = Mockito.mock(QuizzesServiceInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final SolutionsServiceInterface solutionsService = Mockito.mock(SolutionsServiceInterface.class);
    pointsOptions.setQuizzesService(quizzesService);
    pointsOptions.setQuestionsService(questionsService);
    pointsOptions.setSolutionsService(solutionsService);
    final QuizzesOptionsInterface quizOptions = Mockito.mock(QuizzesOptionsInterface.class);
    final QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    final SolutionsOptionsInterface solutionsOptions = Mockito.mock(SolutionsOptionsInterface.class);
    pointsOptions.withQuiz(quizOptions);
    pointsOptions.withQuestion(questionOptions);
    pointsOptions.withSolutions(solutionsOptions);
    final QuizModelInterface quizModelFirst = Mockito.mock(QuizModelInterface.class);
    final QuizModelInterface quizModelSecond = Mockito.mock(QuizModelInterface.class);
    given(quizzesService.find(1, quizOptions)).willReturn(quizModelFirst);
    given(quizzesService.find(2, quizOptions)).willReturn(quizModelSecond);
    final QuestionModelInterface questionModelFirst = Mockito.mock(QuestionModelInterface.class);
    final QuestionModelInterface questionModelSecond = Mockito.mock(QuestionModelInterface.class);
    given(questionsService.find(1, questionOptions)).willReturn(questionModelFirst);
    given(questionsService.find(2, questionOptions)).willReturn(questionModelSecond);
    final List<SolutionModelInterface> solutionsModelsFirst = new ArrayList<>();
    solutionsModelsFirst.add(Mockito.mock(SolutionModelInterface.class));
    final List<SolutionModelInterface> solutionsModelsSecond = new ArrayList<>();
    solutionsModelsSecond.add(Mockito.mock(SolutionModelInterface.class));
    solutionsModelsSecond.add(Mockito.mock(SolutionModelInterface.class));
    given(solutionsService.findByPoint(pointModelFirst, solutionsOptions)).willReturn(solutionsModelsFirst);
    given(solutionsService.findByPoint(pointModelSecond, solutionsOptions)).willReturn(solutionsModelsSecond);
    final List<PointModelInterface> pointsModelsWithRelations = pointsOptions.withRelations(pointsModels);
    Assert.assertEquals(pointsModels, pointsModelsWithRelations);
    verify(quizzesService).find(1, quizOptions);
    verify(questionsService).find(1, questionOptions);
    verify(solutionsService).findByPoint(pointModelFirst, solutionsOptions);
    verify(pointsModels.get(0)).setQuiz(quizModelFirst);
    verify(pointsModels.get(0)).setQuestion(questionModelFirst);
    verify(pointsModels.get(0)).setSolutions(solutionsModelsFirst);
    verify(pointsModels.get(0)).setSolutions(Mockito.anyList());
    verify(quizzesService).find(2, quizOptions);
    verify(questionsService).find(2, questionOptions);
    verify(solutionsService).findByPoint(pointModelSecond, solutionsOptions);
    verify(pointsModels.get(1)).setQuiz(quizModelSecond);
    verify(pointsModels.get(1)).setQuestion(questionModelSecond);
    verify(pointsModels.get(1)).setSolutions(solutionsModelsSecond);
    verify(pointsModels.get(1)).setSolutions(Mockito.anyList());
}
Also used : SolutionModelInterface(easytests.core.models.SolutionModelInterface) QuestionModelEmpty(easytests.core.models.empty.QuestionModelEmpty) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) PointModelInterface(easytests.core.models.PointModelInterface) QuizModelInterface(easytests.core.models.QuizModelInterface) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuizModelEmpty(easytests.core.models.empty.QuizModelEmpty) QuizzesServiceInterface(easytests.core.services.QuizzesServiceInterface) SolutionsServiceInterface(easytests.core.services.SolutionsServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 38 with QuestionModelInterface

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

the class PointEntityTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer pointId = 3;
    final Integer questionId = 1;
    final Integer quizId = 2;
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    final QuizModelInterface quizModel = Mockito.mock(QuizModelInterface.class);
    Mockito.when(quizModel.getId()).thenReturn(quizId);
    Mockito.when(pointModel.getId()).thenReturn(pointId);
    Mockito.when(pointModel.getQuestion()).thenReturn(questionModel);
    Mockito.when(pointModel.getQuiz()).thenReturn(quizModel);
    final PointEntity pointEntity = new PointEntity();
    pointEntity.map(pointModel);
    Assert.assertEquals(pointId, pointEntity.getId());
    Assert.assertEquals(questionId, pointEntity.getQuestionId());
    Assert.assertEquals(quizId, pointEntity.getQuizId());
}
Also used : QuizModelInterface(easytests.core.models.QuizModelInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) PointModelInterface(easytests.core.models.PointModelInterface) Test(org.junit.Test)

Example 39 with QuestionModelInterface

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

the class QuestionsOptionsTest method testWithRelationsOnNull.

@Test
public void testWithRelationsOnNull() throws Exception {
    final QuestionModelInterface questionModel = null;
    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 QuestionModelInterface questionModelWithRelations = questionsOptions.withRelations(questionModel);
    Assert.assertEquals(null, questionModelWithRelations);
}
Also used : QuestionTypesServiceInterface(easytests.core.services.QuestionTypesServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) AnswersServiceInterface(easytests.core.services.AnswersServiceInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 40 with QuestionModelInterface

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

the class QuestionsOptionsTest method testSaveWithRelations.

@Test
public void testSaveWithRelations() 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(topicsService, questionsService, answersService);
    questionsOptions.saveWithRelations(questionModel);
    inOrder.verify(topicsService).save(topicModel, topicsOptions);
    inOrder.verify(questionsService).save(questionModel);
    inOrder.verify(answersService).save(answersModels, answersOptions);
}
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)

Aggregations

QuestionModelInterface (easytests.core.models.QuestionModelInterface)40 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)15 TopicModelInterface (easytests.core.models.TopicModelInterface)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)13 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)10 QuestionsOptionsInterface (easytests.core.options.QuestionsOptionsInterface)9 QuestionsServiceInterface (easytests.core.services.QuestionsServiceInterface)9 QuestionEntity (easytests.core.entities.QuestionEntity)8 AnswerModelInterface (easytests.core.models.AnswerModelInterface)6 AnswersServiceInterface (easytests.core.services.AnswersServiceInterface)5 InOrder (org.mockito.InOrder)4 PointModelInterface (easytests.core.models.PointModelInterface)3 QuestionTypeModelInterface (easytests.core.models.QuestionTypeModelInterface)3 QuizModelInterface (easytests.core.models.QuizModelInterface)3 QuestionTypeModelEmpty (easytests.core.models.empty.QuestionTypeModelEmpty)3 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)3 QuestionTypesServiceInterface (easytests.core.services.QuestionTypesServiceInterface)3 QuestionModel (easytests.core.models.QuestionModel)2 SolutionModelInterface (easytests.core.models.SolutionModelInterface)2