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());
}
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;
}
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;
}
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/";
}
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/";
}
Aggregations