Search in sources :

Example 1 with TopicModelInterface

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

the class TopicsOptionsTest method testWithRelationsQuestionsOnSingleModel.

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

Example 2 with TopicModelInterface

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

the class TopicsOptionsTest method testDeleteWithRelationsQuestion.

@Test
public void testDeleteWithRelationsQuestion() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    final QuestionsServiceInterface questionsService = Mockito.mock(QuestionsServiceInterface.class);
    final TopicsServiceInterface topicsService = Mockito.mock(TopicsServiceInterface.class);
    topicsOptions.setQuestionsService(questionsService);
    topicsOptions.setTopicsService(topicsService);
    final QuestionsOptionsInterface questionsOptions = Mockito.mock(QuestionsOptionsInterface.class);
    topicsOptions.withQuestions(questionsOptions);
    final List<QuestionModelInterface> questionsModels = new ArrayList<>();
    topicModel.setQuestions(questionsModels);
    final InOrder inOrder = Mockito.inOrder(questionsService, topicsService);
    topicsOptions.deleteWithRelations(topicModel);
    inOrder.verify(questionsService).save(topicModel.getQuestions(), questionsOptions);
    inOrder.verify(topicsService).delete(topicModel);
}
Also used : InOrder(org.mockito.InOrder) QuestionsServiceInterface(easytests.core.services.QuestionsServiceInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicsServiceInterface(easytests.core.services.TopicsServiceInterface) ArrayList(java.util.ArrayList) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 3 with TopicModelInterface

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

the class TopicsOptionsTest method testWithRelationsSubjectOnSingleModel.

@Test
public void testWithRelationsSubjectOnSingleModel() throws Exception {
    final TopicsOptionsInterface topicsOptions = new TopicsOptions();
    final TopicModelInterface topicModel = Mockito.mock(TopicModelInterface.class);
    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 = Mockito.mock(SubjectModelInterface.class);
    final SubjectModelInterface subjectModelWithId = Mockito.mock(SubjectModelInterface.class);
    given(topicModel.getSubject()).willReturn(subjectModelWithId);
    given(subjectsService.find(topicModel.getSubject().getId(), subjectsOptions)).willReturn(subjectModel);
    final TopicModelInterface topicModelWithRelations = topicsOptions.withRelations(topicModel);
    Assert.assertEquals(topicModel, topicModelWithRelations);
    subjectsService.find(1, subjectsOptions);
    verify(topicModel).setSubject(subjectModel);
}
Also used : SubjectsServiceInterface(easytests.core.services.SubjectsServiceInterface) 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 4 with TopicModelInterface

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

the class TopicsServiceTest method testFindAbsentModel.

@Test
public void testFindAbsentModel() throws Exception {
    final Integer absentId = 7;
    when(this.topicsMapper.find(absentId)).thenReturn(null);
    final TopicModelInterface topicFoundedModel = this.topicsService.find(absentId);
    Assert.assertNull(topicFoundedModel);
}
Also used : TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with TopicModelInterface

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

the class TopicsServiceTest method testFindBySubjectPresentList.

@Test
public void testFindBySubjectPresentList() throws Exception {
    final SubjectModelInterface subjectModel = this.subjectsSupport.getModelFixtureMock(0);
    final List<TopicEntity> topicsEntities = this.getTopicsFixturesEntities();
    when(this.topicsMapper.findBySubjectId(subjectModel.getId())).thenReturn(topicsEntities);
    final List<TopicModelInterface> topicsFoundedModels = this.topicsService.findBySubject(subjectModel);
    this.topicsSupport.assertModelsListEquals(this.getTopicsFixturesModels(), topicsFoundedModels);
}
Also used : TopicEntity(easytests.core.entities.TopicEntity) 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