use of easytests.core.models.SubjectModelInterface 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.SubjectModelInterface 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/";
}
use of easytests.core.models.SubjectModelInterface in project easy-tests by malinink.
the class TopicsServiceTest method testFindBySubject.
@Test
public void testFindBySubject() throws Exception {
final Integer subjectId = 3;
final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
final List<TopicEntity> topicsEntities = this.getTopicsEntities();
final List<TopicModelInterface> topicsModels = getTopicsModels();
Mockito.when(subjectModel.getId()).thenReturn(subjectId);
given(this.topicsMapper.findBySubjectId(subjectId)).willReturn(topicsEntities);
final List<TopicModelInterface> foundedTopicsModels = this.topicsService.findBySubject(subjectModel);
verify(this.topicsMapper).findBySubjectId(subjectId);
Assert.assertEquals(topicsModels, foundedTopicsModels);
}
use of easytests.core.models.SubjectModelInterface in project easy-tests by malinink.
the class TopicsServiceTest method testFindByUserWithOptions.
@Test
public void testFindByUserWithOptions() throws Exception {
final Integer subjectId = 3;
final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
final List<TopicEntity> topicsEntities = this.getTopicsEntities();
final List<TopicModelInterface> topicsModels = this.getTopicsModels();
given(subjectModel.getId()).willReturn(subjectId);
given(this.topicsMapper.findBySubjectId(subjectId)).willReturn(topicsEntities);
final TopicsOptionsInterface topicOptions = Mockito.mock(TopicsOptionsInterface.class);
given(topicOptions.withRelations(topicsModels)).willReturn(topicsModels);
final List<TopicModelInterface> foundedTopicsModels = this.topicsService.findBySubject(subjectModel, topicOptions);
verify(this.topicsMapper).findBySubjectId(subjectId);
verify(topicOptions).withRelations(topicsModels);
Assert.assertEquals(topicsModels, foundedTopicsModels);
}
use of easytests.core.models.SubjectModelInterface in project easy-tests by malinink.
the class IssuesServiceTest method testFindBySubjectWithOptions.
@Test
public void testFindBySubjectWithOptions() throws Exception {
final Integer subjectId = 7;
final SubjectModelInterface subjectModel = Mockito.mock(SubjectModelInterface.class);
final IssueEntity issueEntityFirst = Entities.createIssueEntityMock(4, "test3", subjectId);
final IssueEntity issueEntitySecond = Entities.createIssueEntityMock(12, "test12", subjectId);
final List<IssueEntity> issuesEntities = new ArrayList<>();
issuesEntities.add(issueEntityFirst);
issuesEntities.add(issueEntitySecond);
Mockito.when(subjectModel.getId()).thenReturn(subjectId);
given(this.issuesMapper.findBySubjectId(subjectId)).willReturn(issuesEntities);
final List<IssueModelInterface> issuesModels = new ArrayList<>();
issuesModels.add(this.mapIssueModel(issueEntityFirst));
issuesModels.add(this.mapIssueModel(issueEntitySecond));
final IssuesOptionsInterface issuesOptions = Mockito.mock(IssuesOptionsInterface.class);
given(issuesOptions.withRelations(issuesModels)).willReturn(issuesModels);
final List<IssueModelInterface> foundIssuesModels = this.issuesService.findBySubject(subjectModel, issuesOptions);
verify(this.issuesMapper).findBySubjectId(subjectId);
verify(issuesOptions).withRelations(issuesModels);
Assert.assertEquals(issuesModels, foundIssuesModels);
}
Aggregations