Search in sources :

Example 41 with TopicModelInterface

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

the class QuestionEntityTest method testMap.

@Test
public void testMap() throws Exception {
    final Integer questionId = 1;
    final String text = "test1";
    final Integer questionTypeId = 1;
    final Integer topicId = 1;
    final TopicModelInterface topic = Mockito.mock(TopicModelInterface.class);
    Mockito.when(topic.getId()).thenReturn(topicId);
    final QuestionTypeModelInterface questionType = Mockito.mock(QuestionTypeModelInterface.class);
    Mockito.when(questionType.getId()).thenReturn(questionTypeId);
    final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
    Mockito.when(questionModel.getId()).thenReturn(questionId);
    Mockito.when(questionModel.getText()).thenReturn(text);
    Mockito.when(questionModel.getQuestionType()).thenReturn(questionType);
    Mockito.when(questionModel.getTopic()).thenReturn(topic);
    final QuestionEntity questionEntity = new QuestionEntity();
    questionEntity.map(questionModel);
    Assert.assertEquals(questionId, questionEntity.getId());
    Assert.assertEquals(text, questionEntity.getText());
    Assert.assertEquals(questionTypeId, questionEntity.getQuestionTypeId());
    Assert.assertEquals(topicId, questionEntity.getTopicId());
}
Also used : QuestionTypeModelInterface(easytests.core.models.QuestionTypeModelInterface) QuestionModelInterface(easytests.core.models.QuestionModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) Test(org.junit.Test)

Example 42 with TopicModelInterface

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

the class TopicsController method getTopicModel.

private TopicModelInterface getTopicModel(Integer id, Integer subjectId, TopicsOptionsInterface topicsOptions) {
    final TopicModelInterface topicModel = this.topicsService.find(id, topicsOptions);
    checkModel(topicModel, subjectId);
    return topicModel;
}
Also used : TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 43 with TopicModelInterface

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

the class TopicsController method getCurrentSubjectModel.

private SubjectModelInterface getCurrentSubjectModel(Integer subjectId, boolean withTopics) {
    final SubjectsOptionsInterface subjectsOptions = this.subjectsOptionsBuilder.forAuth();
    final SubjectModelInterface subjectModel = subjectsService.find(subjectId, subjectsOptions);
    if (withTopics) {
        final List<TopicModelInterface> topics = this.topicsService.findBySubject(subjectModel);
        subjectModel.setTopics(topics);
    }
    checkModel(subjectModel);
    return subjectModel;
}
Also used : SubjectsOptionsInterface(easytests.core.options.SubjectsOptionsInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface)

Example 44 with TopicModelInterface

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

the class TopicsController method create.

@PostMapping("create/")
public String create(Model model, @Valid @NotNull TopicDto topic, BindingResult bindingResult, @PathVariable("subjectId") Integer subjectId) {
    final SubjectModelInterface subjectModel = getCurrentSubjectModel(subjectId, false);
    if (bindingResult.hasErrors()) {
        setCreateBehaviour(model);
        model.addAttribute("topic", topic);
        model.addAttribute("subjectId", subjectId);
        model.addAttribute("errors", bindingResult);
        return "topics/form";
    }
    final TopicModelInterface topicModel = new TopicModel();
    topic.mapInto(topicModel);
    topicModel.setSubject(subjectModel);
    this.topicsService.save(topicModel);
    return "redirect:/personal/subjects/" + subjectId + "/topics/";
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModel(easytests.core.models.TopicModel) TopicModelInterface(easytests.core.models.TopicModelInterface) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 45 with TopicModelInterface

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

the class TopicsController method update.

@PostMapping("update/{topicId}/")
public String update(Model model, @PathVariable Integer topicId, @Valid @NotNull TopicDto topic, BindingResult bindingResult, @PathVariable("subjectId") Integer subjectId) {
    final SubjectModelInterface subjectModel = getCurrentSubjectModel(subjectId, false);
    final TopicModelInterface topicModel = this.getTopicModel(topicId, subjectId);
    if (bindingResult.hasErrors()) {
        setUpdateBehaviour(model);
        model.addAttribute("topic", topic);
        model.addAttribute("subjectId", subjectId);
        model.addAttribute("errors", bindingResult);
        return "topics/form";
    }
    topic.mapInto(topicModel);
    this.topicsService.save(topicModel);
    return "redirect:/personal/subjects/" + subjectId + "/topics/";
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) PostMapping(org.springframework.web.bind.annotation.PostMapping)

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