fix using deadline dto
parent
aae86b94b5
commit
f1229b6019
@ -0,0 +1,61 @@
|
||||
package ru.ulstu.activity.deadline.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class DeadlineDto {
|
||||
private final Integer id;
|
||||
private final Date date;
|
||||
private final String description;
|
||||
private final List<Integer> executorsIds;
|
||||
private final Boolean done;
|
||||
|
||||
public DeadlineDto() {
|
||||
this.id = null;
|
||||
this.date = null;
|
||||
this.description = null;
|
||||
this.executorsIds = new ArrayList<>();
|
||||
this.done = false;
|
||||
}
|
||||
|
||||
public DeadlineDto(Deadline deadline) {
|
||||
this.id = deadline.getId();
|
||||
this.date = deadline.getDate();
|
||||
this.description = deadline.getDescription();
|
||||
this.executorsIds = deadline.getExecutors()
|
||||
.stream()
|
||||
.map(executor -> executor.getId())
|
||||
.collect(Collectors.toList());
|
||||
this.done = deadline.isDone();
|
||||
}
|
||||
|
||||
public DeadlineDto(Date date, String description) {
|
||||
this.id = null;
|
||||
this.date = date;
|
||||
this.description = description;
|
||||
this.executorsIds = new ArrayList<>();
|
||||
this.done = false;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Date getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public List<Integer> getExecutorsIds() {
|
||||
return executorsIds;
|
||||
}
|
||||
|
||||
public Boolean isDone() {
|
||||
return done;
|
||||
}
|
||||
}
|
@ -1,149 +0,0 @@
|
||||
package project;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import ru.ulstu.activity.deadline.model.Deadline;
|
||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||
import ru.ulstu.activity.file.model.FileData;
|
||||
import ru.ulstu.activity.file.service.FileService;
|
||||
import ru.ulstu.activity.grant.model.GrantDto;
|
||||
import ru.ulstu.activity.grant.service.GrantService;
|
||||
import ru.ulstu.activity.project.model.Project;
|
||||
import ru.ulstu.activity.project.model.ProjectDto;
|
||||
import ru.ulstu.activity.project.repository.ProjectRepository;
|
||||
import ru.ulstu.activity.project.service.ProjectService;
|
||||
import ru.ulstu.activity.timeline.service.EventService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class ProjectServiceTest {
|
||||
|
||||
@Mock
|
||||
ProjectRepository projectRepository;
|
||||
|
||||
@Mock
|
||||
DeadlineService deadlineService;
|
||||
|
||||
@Mock
|
||||
EventService eventService;
|
||||
|
||||
@Mock
|
||||
FileService fileService;
|
||||
|
||||
@Mock
|
||||
UserService userService;
|
||||
|
||||
@Mock
|
||||
GrantService grantService;
|
||||
|
||||
@InjectMocks
|
||||
ProjectService projectService;
|
||||
|
||||
private final static String TITLE = "title";
|
||||
private final static String DESCR = "descr";
|
||||
private final static Integer ID = 1;
|
||||
private final static Integer INDEX = 0;
|
||||
private final static String NAME = "name";
|
||||
|
||||
private List<Project> projects;
|
||||
private Project project;
|
||||
private ProjectDto projectDto;
|
||||
private Deadline deadline;
|
||||
private List<Deadline> deadlines;
|
||||
private FileData file;
|
||||
private List<FileData> files;
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
projects = new ArrayList<>();
|
||||
project = new Project();
|
||||
|
||||
projects.add(project);
|
||||
projectDto = new ProjectDto(project);
|
||||
|
||||
deadlines = new ArrayList<>();
|
||||
deadline = new Deadline(new Date(), DESCR);
|
||||
deadline.setId(ID);
|
||||
deadlines.add(deadline);
|
||||
|
||||
user = new User();
|
||||
user.setFirstName(NAME);
|
||||
|
||||
List<GrantDto> grants = new ArrayList<>();
|
||||
GrantDto grant = new GrantDto(ID);
|
||||
grants.add(grant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAll() {
|
||||
when(projectRepository.findAll()).thenReturn(projects);
|
||||
assertEquals(projects, projectService.findAll(0, 100).getItems());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create() throws IOException {
|
||||
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
||||
when(projectRepository.save(new Project())).thenReturn(project);
|
||||
eventService.createFromObject(new Project(), Collections.emptyList(), false, "проекта");
|
||||
|
||||
projectDto.setTitle(TITLE);
|
||||
projectDto.setDeadlines(deadlines);
|
||||
|
||||
project.setId(ID);
|
||||
project.setTitle(TITLE);
|
||||
project.setDescription(DESCR);
|
||||
project.setDeadlines(deadlines);
|
||||
project.setFiles(files);
|
||||
|
||||
assertEquals(project.getId(), (projectService.create(projectDto)).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() throws IOException {
|
||||
when(projectRepository.existsById(ID)).thenReturn(true);
|
||||
when(projectRepository.getOne(ID)).thenReturn(project);
|
||||
|
||||
assertTrue(projectService.delete(ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getProjectExecutors() {
|
||||
List<User> executors = Collections.singletonList(user);
|
||||
when(userService.findAll()).thenReturn(executors);
|
||||
|
||||
assertEquals(executors, projectService.getProjectExecutors(projectDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findById() {
|
||||
when(projectRepository.getOne(ID)).thenReturn(project);
|
||||
assertEquals(project, projectService.findById(ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeDeadline() {
|
||||
ProjectDto newProjectDto = new ProjectDto(null);
|
||||
newProjectDto.getRemovedDeadlineIds().add(INDEX);
|
||||
projectDto.getDeadlines().add(deadline);
|
||||
ProjectDto result = projectService.removeDeadline(projectDto, INDEX);
|
||||
|
||||
assertEquals(newProjectDto.getDeadlines(), result.getDeadlines());
|
||||
assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
||||
}
|
||||
}
|
@ -1,216 +0,0 @@
|
||||
package students;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import ru.ulstu.activity.deadline.model.Deadline;
|
||||
import ru.ulstu.activity.deadline.service.DeadlineService;
|
||||
import ru.ulstu.activity.students.model.Scheduler;
|
||||
import ru.ulstu.activity.students.model.Task;
|
||||
import ru.ulstu.activity.students.model.TaskDto;
|
||||
import ru.ulstu.activity.students.model.TaskFilterDto;
|
||||
import ru.ulstu.activity.students.repository.SchedulerRepository;
|
||||
import ru.ulstu.activity.students.repository.TaskRepository;
|
||||
import ru.ulstu.activity.students.service.TaskService;
|
||||
import ru.ulstu.activity.tags.model.Tag;
|
||||
import ru.ulstu.activity.tags.service.TagService;
|
||||
import ru.ulstu.activity.timeline.service.EventService;
|
||||
import ru.ulstu.core.util.DateUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
public class TaskServiceTest {
|
||||
|
||||
@Mock
|
||||
TaskRepository taskRepository;
|
||||
|
||||
@Mock
|
||||
SchedulerRepository schedulerRepository;
|
||||
|
||||
@Mock
|
||||
private TagService tagService;
|
||||
|
||||
@Mock
|
||||
DeadlineService deadlineService;
|
||||
|
||||
@Mock
|
||||
EventService eventService;
|
||||
|
||||
@InjectMocks
|
||||
TaskService taskService;
|
||||
|
||||
private final static Sort SORT = new Sort(Sort.Direction.DESC, "createDate");
|
||||
private final static Integer ID = 1;
|
||||
private final static Task.TaskStatus STATUS = Task.TaskStatus.IN_WORK;
|
||||
private final static String TITLE = "title";
|
||||
private final static String DESCR = "descr";
|
||||
private final static String TAG = "tag";
|
||||
private final static Date YEAR = DateUtils.clearTime(DateUtils.addYears(new Date(), 0));
|
||||
|
||||
private List<Task> tasks;
|
||||
private List<Tag> tags;
|
||||
private Task task;
|
||||
private Task taskForSchedule;
|
||||
private TaskDto taskDto;
|
||||
private Tag tag;
|
||||
private Deadline deadline;
|
||||
private List<Deadline> deadlines;
|
||||
private Scheduler scheduler;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
tasks = new ArrayList<>();
|
||||
task = new Task();
|
||||
|
||||
task.setId(ID);
|
||||
task.setTitle(TITLE);
|
||||
task.setDescription(DESCR);
|
||||
|
||||
|
||||
tag = new Tag();
|
||||
tag.setId(ID);
|
||||
tag.setTagName(TAG);
|
||||
|
||||
deadlines = new ArrayList<>();
|
||||
deadline = new Deadline(new Date(), DESCR);
|
||||
deadline.setId(ID);
|
||||
deadlines.add(deadline);
|
||||
|
||||
task.setDeadlines(deadlines);
|
||||
|
||||
tags = new ArrayList<>();
|
||||
tags.add(tag);
|
||||
|
||||
tasks.add(task);
|
||||
taskDto = new TaskDto(task);
|
||||
|
||||
taskForSchedule = new Task();
|
||||
taskForSchedule.setTitle(TITLE);
|
||||
taskForSchedule.setDescription(DESCR);
|
||||
|
||||
scheduler = new Scheduler();
|
||||
scheduler.setDate(new Date());
|
||||
scheduler.setTask(taskForSchedule);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAll() {
|
||||
when(taskRepository.findAll(SORT)).thenReturn(tasks);
|
||||
assertEquals(Collections.singletonList(task), taskService.findAll());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void filter() {
|
||||
when(tagService.findById(ID)).thenReturn(tag);
|
||||
when(taskRepository.filterNew(STATUS, tag)).thenReturn(tasks);
|
||||
|
||||
TaskFilterDto taskFilterDto = new TaskFilterDto();
|
||||
taskFilterDto.setTag(ID);
|
||||
taskFilterDto.setOrder("new");
|
||||
taskFilterDto.setStatus(STATUS);
|
||||
|
||||
assertEquals(Collections.singletonList(taskDto), taskService.filter(taskFilterDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void create() throws IOException {
|
||||
when(tagService.saveOrCreate(new ArrayList<>())).thenReturn(tags);
|
||||
when(deadlineService.saveOrCreate(new ArrayList<>())).thenReturn(deadlines);
|
||||
when(taskRepository.save(new Task())).thenReturn(task);
|
||||
eventService.createFromObject(new Task(), Collections.emptyList(), true, "задачи");
|
||||
|
||||
taskDto.setTags(tags);
|
||||
taskDto.setDeadlines(deadlines);
|
||||
|
||||
Task newTask = new Task();
|
||||
task.setId(ID);
|
||||
task.setTitle(TITLE);
|
||||
task.setDescription(DESCR);
|
||||
task.setTags(tags);
|
||||
task.setDeadlines(deadlines);
|
||||
|
||||
assertEquals(task.getId(), taskService.create(taskDto));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void delete() throws IOException {
|
||||
when(taskRepository.existsById(ID)).thenReturn(true);
|
||||
when(taskRepository.getOne(ID)).thenReturn(task);
|
||||
when(schedulerRepository.findOneByTask(task)).thenReturn(null);
|
||||
|
||||
assertTrue(taskService.delete(ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void generateYearTasks() {
|
||||
when(tagService.getTags()).thenReturn(tags);
|
||||
tasks.get(0).setTags(tags);
|
||||
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
||||
tasks.get(0).setCreateDate(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)));
|
||||
when(taskRepository.findByTag(tag)).thenReturn(tasks);
|
||||
|
||||
Task newTask = new Task();
|
||||
newTask.setTitle(tasks.get(0).getTitle());
|
||||
newTask.setTags(tasks.get(0).getTags());
|
||||
newTask.setCreateDate(new Date());
|
||||
newTask.setStatus(Task.TaskStatus.LOADED_FROM_KIAS);
|
||||
|
||||
Deadline newDeadline = new Deadline();
|
||||
newDeadline.setId(ID);
|
||||
newDeadline.setDescription(deadline.getDescription());
|
||||
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
||||
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
||||
newTask.setDeadlines(Arrays.asList(newDeadline));
|
||||
|
||||
when(taskRepository.save(newTask)).thenReturn(task);
|
||||
|
||||
assertEquals(Arrays.asList(task), taskService.generateYearTasks());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkRepeatingTags() {
|
||||
when(tagService.getTags()).thenReturn(tags);
|
||||
tasks.get(0).setTags(tags);
|
||||
when(taskRepository.findAllYear(DateUtils.clearTime(DateUtils.addYears(new Date(), -1)))).thenReturn(tasks);
|
||||
|
||||
assertEquals(new HashSet<Tag>(Arrays.asList(tag)), taskService.checkRepeatingTags(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createPeriodTask() {
|
||||
Task newTask = new Task();
|
||||
newTask.setTitle(scheduler.getTask().getTitle());
|
||||
newTask.setTags(scheduler.getTask().getTags());
|
||||
newTask.setCreateDate(new Date());
|
||||
|
||||
Deadline newDeadline = new Deadline();
|
||||
newDeadline.setId(ID);
|
||||
newDeadline.setDescription(deadline.getDescription());
|
||||
newDeadline.setDate(DateUtils.addYears(deadline.getDate(), 1));
|
||||
when(deadlineService.create(newDeadline)).thenReturn(newDeadline);
|
||||
newTask.setDeadlines(Arrays.asList(newDeadline));
|
||||
|
||||
when(taskRepository.save(newTask)).thenReturn(taskForSchedule);
|
||||
|
||||
assertEquals(taskForSchedule, taskService.createPeriodTask(scheduler));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue