Search in sources :

Example 46 with SubjectModelInterface

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/";
}
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 47 with SubjectModelInterface

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/";
}
Also used : SubjectModelInterface(easytests.core.models.SubjectModelInterface) TopicModelInterface(easytests.core.models.TopicModelInterface) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 48 with SubjectModelInterface

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);
}
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)

Example 49 with SubjectModelInterface

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);
}
Also used : TopicsOptionsInterface(easytests.core.options.TopicsOptionsInterface) 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)

Example 50 with SubjectModelInterface

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);
}
Also used : IssuesOptionsInterface(easytests.core.options.IssuesOptionsInterface) IssueEntity(easytests.core.entities.IssueEntity) ArrayList(java.util.ArrayList) IssueModelInterface(easytests.core.models.IssueModelInterface) SubjectModelInterface(easytests.core.models.SubjectModelInterface)

Aggregations

SubjectModelInterface (easytests.core.models.SubjectModelInterface)64 Test (org.junit.Test)22 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)21 TopicModelInterface (easytests.core.models.TopicModelInterface)18 ArrayList (java.util.ArrayList)16 SubjectsServiceInterface (easytests.core.services.SubjectsServiceInterface)15 SubjectsOptionsInterface (easytests.core.options.SubjectsOptionsInterface)11 UserModelInterface (easytests.core.models.UserModelInterface)9 SubjectEntity (easytests.core.entities.SubjectEntity)7 IssueStandardModelInterface (easytests.core.models.IssueStandardModelInterface)7 SubjectModel (easytests.core.models.SubjectModel)6 InOrder (org.mockito.InOrder)6 SubjectModelEmpty (easytests.core.models.empty.SubjectModelEmpty)5 TopicsServiceInterface (easytests.core.services.TopicsServiceInterface)5 GetMapping (org.springframework.web.bind.annotation.GetMapping)5 TopicEntity (easytests.core.entities.TopicEntity)4 IssueModelInterface (easytests.core.models.IssueModelInterface)4 ModelsListEmpty (easytests.core.models.empty.ModelsListEmpty)4 IssueStandardQuestionTypeOptionsServiceInterface (easytests.core.services.IssueStandardQuestionTypeOptionsServiceInterface)4 IssueStandardTopicPrioritiesServiceInterface (easytests.core.services.IssueStandardTopicPrioritiesServiceInterface)4