Search in sources :

Example 16 with QuestionEntity

use of easytests.core.entities.QuestionEntity in project easy-tests by malinink.

the class QuestionsServiceTest method testFindByTopicWithOptions.

@Test
public void testFindByTopicWithOptions() 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);
    given(topicModel.getId()).willReturn(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 QuestionsOptionsInterface questionOptions = Mockito.mock(QuestionsOptionsInterface.class);
    given(questionOptions.withRelations(questionsModels)).willReturn(questionsModels);
    final List<QuestionModelInterface> foundedQuestionsModels = this.questionsService.findByTopic(topicModel, questionOptions);
    verify(this.questionsMapper).findByTopicId(topicId);
    verify(questionOptions).withRelations(questionsModels);
    Assert.assertEquals(questionsModels, foundedQuestionsModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) ArrayList(java.util.ArrayList) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 17 with QuestionEntity

use of easytests.core.entities.QuestionEntity in project easy-tests by malinink.

the class QuestionsServiceTest method testFindAllWithOptions.

@Test
public void testFindAllWithOptions() throws Exception {
    final List<QuestionEntity> questionsEntities = this.getQuestionsEntities();
    final List<QuestionModelInterface> questionsModels = this.getQuestionsModels();
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    given(this.questionsMapper.findAll()).willReturn(questionsEntities);
    given(questionsOptions.withRelations(Mockito.anyList())).willReturn(questionsModels);
    final List<QuestionModelInterface> foundedQuestionsModels = this.questionsService.findAll(questionsOptions);
    verify(questionsOptions).withRelations(questionsModels);
    Assert.assertEquals(questionsModels, foundedQuestionsModels);
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) QuestionModelInterface(easytests.core.models.QuestionModelInterface) QuestionsOptionsInterface(easytests.core.options.QuestionsOptionsInterface)

Example 18 with QuestionEntity

use of easytests.core.entities.QuestionEntity 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 19 with QuestionEntity

use of easytests.core.entities.QuestionEntity in project easy-tests by malinink.

the class QuestionsMapperTest method testFind.

@Test
public void testFind() throws Exception {
    final QuestionEntity question = this.questionsMapper.find(1);
    Assert.assertEquals((long) 1, (long) question.getId());
    Assert.assertEquals("test1", question.getText());
    Assert.assertEquals((long) 1, (long) question.getQuestionTypeId());
    Assert.assertEquals((long) 1, (long) question.getTopicId());
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) Test(org.junit.Test)

Example 20 with QuestionEntity

use of easytests.core.entities.QuestionEntity in project easy-tests by malinink.

the class QuestionsMapperTest method testFindByTopicId.

@Test
public void testFindByTopicId() throws Exception {
    final List<QuestionEntity> questions = this.questionsMapper.findByTopicId(2);
    Assert.assertEquals((Integer) 1, (Integer) questions.size());
    final QuestionEntity question = questions.get(0);
    Assert.assertEquals((Integer) 3, question.getId());
    Assert.assertEquals("test3", question.getText());
    Assert.assertEquals((Integer) 3, question.getQuestionTypeId());
    Assert.assertEquals((Integer) 2, question.getTopicId());
}
Also used : QuestionEntity(easytests.core.entities.QuestionEntity) Test(org.junit.Test)

Aggregations

QuestionEntity (easytests.core.entities.QuestionEntity)22 QuestionModelInterface (easytests.core.models.QuestionModelInterface)8 Test (org.junit.Test)7 TopicModelInterface (easytests.core.models.TopicModelInterface)3 QuestionsOptionsInterface (easytests.core.options.QuestionsOptionsInterface)3 ArrayList (java.util.ArrayList)3 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)1 QuestionTypeModelEmpty (easytests.core.models.empty.QuestionTypeModelEmpty)1 TopicModelEmpty (easytests.core.models.empty.TopicModelEmpty)1 DeleteUnidentifiedModelException (easytests.core.services.exceptions.DeleteUnidentifiedModelException)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1