Search in sources :

Example 11 with QuestionModelInterface

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

the class QuestionsServiceTest method testDeleteUnidentifiedModel.

@Test
public void testDeleteUnidentifiedModel() throws Exception {
    final QuestionModelInterface questionModel = Models.createQuestionModel(null, "Text", 1, 1);
    exception.expect(DeleteUnidentifiedModelException.class);
    this.questionsService.delete(questionModel);
}
Also used : QuestionModelInterface(easytests.core.models.QuestionModelInterface)

Example 12 with QuestionModelInterface

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

the class QuestionsServiceTest method testFindPresentModel.

@Test
public void testFindPresentModel() throws Exception {
    final Integer id = 1;
    final QuestionEntity questionEntity = Entities.createQuestionEntityMock(id, "NewText", 1, 1);
    given(this.questionsMapper.find(id)).willReturn(questionEntity);
    final QuestionModelInterface questionModel = this.questionsService.find(id);
    Assert.assertEquals(this.mapQuestionModel(questionEntity), questionModel);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface)

Example 13 with QuestionModelInterface

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

the class PointsOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final PointModelInterface pointModel = Mockito.mock(PointModelInterface.class);
    final PointsOptionsInterface pointsOptions = new PointsOptions();
    pointModel.setId(1);
    given(pointModel.getQuiz()).willReturn(new QuizModelEmpty(1));
    given(pointModel.getQuestion()).willReturn(new QuestionModelEmpty(1));
    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 quizModel = Mockito.mock(QuizModelInterface.class);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    final List<SolutionModelInterface> solutionsModels = new ArrayList<>();
    solutionsModels.add(Mockito.mock(SolutionModelInterface.class));
    given(quizzesService.find(pointModel.getQuiz().getId(), quizOptions)).willReturn(quizModel);
    given(questionsService.find(pointModel.getQuestion().getId(), questionOptions)).willReturn(questionModel);
    given(solutionsService.findByPoint(pointModel, solutionsOptions)).willReturn(solutionsModels);
    final PointModelInterface pointModelWithRelations = pointsOptions.withRelations(pointModel);
    Assert.assertEquals(pointModel, pointModelWithRelations);
    verify(quizzesService).find(1, quizOptions);
    verify(questionsService).find(1, questionOptions);
    verify(solutionsService).findByPoint(pointModel, solutionsOptions);
    verify(pointModel).setQuiz(quizModel);
    verify(pointModel).setQuestion(questionModel);
    verify(pointModel).setSolutions(solutionsModels);
}
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 14 with QuestionModelInterface

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

the class QuestionsOptionsTest method testWithRelationsOnSingleModel.

@Test
public void testWithRelationsOnSingleModel() throws Exception {
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    questionModel.setId(1);
    given(questionModel.getTopic()).willReturn(new TopicModelEmpty(1));
    given(questionModel.getQuestionType()).willReturn(new QuestionTypeModelEmpty(1));
    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> answersModels = new ArrayList<>();
    answersModels.add(Mockito.mock(AnswerModelInterface.class));
    TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    QuestionTypeModelInterface questionTypeModel = Mockito.mock(QuestionTypeModelInterface.class);
    given(answersService.findByQuestion(questionModel, answersOptions)).willReturn(answersModels);
    given(topicsService.find(questionModel.getTopic().getId(), topicsOptions)).willReturn(topicModel);
    given(questionTypesService.find(questionModel.getQuestionType().getId(), questionTypesOptions)).willReturn(questionTypeModel);
    final QuestionModelInterface questionModelWithRelations = questionsOptions.withRelations(questionModel);
    Assert.assertEquals(questionModel, questionModelWithRelations);
    verify(answersService).findByQuestion(questionModel, answersOptions);
    verify(topicsService).find(questionModel.getTopic().getId(), topicsOptions);
    verify(questionTypesService).find(questionModel.getQuestionType().getId(), questionTypesOptions);
    verify(questionModel).setAnswers(answersModels);
    verify(questionModel).setTopic(topicModel);
    verify(questionModel).setQuestionType(questionTypeModel);
    verify(questionModel).setAnswers(Mockito.anyList());
}
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 15 with QuestionModelInterface

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

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