Merge branch '101-projecgt-timeline' into 'dev'
Resolve "Генерация таймлайна для проекта" Closes #101 See merge request romanov73/ng-tracker!85environments/staging/deployments/79
commit
bacd3827e3
@ -0,0 +1,17 @@
|
||||
package ru.ulstu.core.model;
|
||||
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.timeline.model.Event;
|
||||
import ru.ulstu.user.model.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface EventSource {
|
||||
List<Deadline> getDeadlines();
|
||||
|
||||
String getTitle();
|
||||
|
||||
List<User> getRecipients();
|
||||
|
||||
void addObjectToEvent(Event event);
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
<changeSet author="anton" id="20190507_000002-1">
|
||||
<addColumn tableName="event">
|
||||
<column name="project_id" type="integer"/>
|
||||
</addColumn>
|
||||
<addForeignKeyConstraint baseTableName="event" baseColumnNames="project_id"
|
||||
constraintName="fk_event_project_id" referencedTableName="project"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,17 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
<changeSet author="anton" id="20190528_000000-3">
|
||||
<createTable tableName="project_grants">
|
||||
<column name="project_id" type="integer"/>
|
||||
<column name="grants_id" type="integer"/>
|
||||
</createTable>
|
||||
<addForeignKeyConstraint baseTableName="project_grants" baseColumnNames="project_id"
|
||||
constraintName="fk_project_project_grants" referencedTableName="project"
|
||||
referencedColumnNames="id"/>
|
||||
<addForeignKeyConstraint baseTableName="project_grants" baseColumnNames="grants_id"
|
||||
constraintName="fk_grant_project_grants" referencedTableName="grants"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||
<changeSet author="anton" id="20190529_000001-1">
|
||||
<addColumn tableName="file">
|
||||
<column name="project_id" type="integer"/>
|
||||
</addColumn>
|
||||
<addForeignKeyConstraint baseTableName="file" baseColumnNames="project_id"
|
||||
constraintName="fk_file_project" referencedTableName="project"
|
||||
referencedColumnNames="id"/>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
@ -0,0 +1,40 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8"/>
|
||||
</head>
|
||||
<body>
|
||||
<body>
|
||||
<div th:fragment="filesList">
|
||||
<th:block th:each="file, rowStat : *{files}">
|
||||
|
||||
<div class="row" th:id="|files${rowStat.index}|"
|
||||
th:style="${file.deleted} ? 'display: none;' :''">
|
||||
<input type="hidden" th:field="*{files[__${rowStat.index}__].id}"/>
|
||||
<input type="hidden"
|
||||
th:field="*{files[__${rowStat.index}__].deleted}"/>
|
||||
<input type="hidden"
|
||||
th:field="*{files[__${rowStat.index}__].name}"/>
|
||||
<input type="hidden"
|
||||
th:field="*{files[__${rowStat.index}__].tmpFileName}"/>
|
||||
<div class="col-2">
|
||||
<a class="btn btn-danger float-right"
|
||||
th:onclick="|$('#files${rowStat.index}\\.deleted').val('true'); $('#files${rowStat.index}').hide(); |">
|
||||
<span aria-hidden="true"><i class="fa fa-times"/></span>
|
||||
</a>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<a th:onclick="${file.id==null} ? 'downloadFile('+${file.tmpFileName}+',null,\''+${file.name}+'\')':
|
||||
'downloadFile(null,'+${file.id}+',\''+${file.name}+'\')' "
|
||||
href="javascript:void(0)"
|
||||
th:text="*{files[__${rowStat.index}__].name}">
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</th:block>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,174 @@
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.Iterables;
|
||||
import core.PageObject;
|
||||
import core.TestTemplate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import project.ProjectDashboard;
|
||||
import project.ProjectPage;
|
||||
import project.ProjectsPage;
|
||||
import ru.ulstu.NgTrackerApplication;
|
||||
import ru.ulstu.configuration.ApplicationProperties;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||
public class ProjectTest extends TestTemplate {
|
||||
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||
new ProjectPage(), Arrays.asList("ПРОЕКТЫ", "/projects/projects"),
|
||||
new ProjectsPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ПРОЕКТА", "/projects/project?id=0"),
|
||||
new ProjectDashboard(), Arrays.asList("ПРОЕКТЫ", "/projects/dashboard")
|
||||
);
|
||||
|
||||
@Autowired
|
||||
private ApplicationProperties applicationProperties;
|
||||
|
||||
@Test
|
||||
public void testACreateNewProject() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(page.getKey());
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||
String name = "Project " + (new Date()).getTime();
|
||||
String date = "01.01.2019";
|
||||
Integer deadNum = projectPage.getDeadlineCount();
|
||||
projectPage.setName(name);
|
||||
projectPage.clickAddDeadline();
|
||||
projectPage.addDeadlineDate(date, deadNum);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBChangeNameAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = "Project " + (new Date()).getTime();
|
||||
projectPage.clearName();
|
||||
projectPage.setName(name);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCChangeDeadlineAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
String date = "01.01.2019";
|
||||
Integer deadNum = projectPage.getDeadlineCount();
|
||||
projectPage.addDeadlineDate(date, deadNum);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDSetStatusAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
projectPage.setStatus();
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEAddDescriptionAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
String description = "Description " + (new Date()).getTime();
|
||||
projectPage.addDescription(description);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFAddLinkAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
String link = "Link " + (new Date()).getTime();
|
||||
projectPage.addLink(link);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGAddDeadlineDescriptionAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
String deadDesc = "Description " + (new Date()).getTime();
|
||||
projectPage.addDeadlineDescription(deadDesc);
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHSetDeadlineCompletionAndSave() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
projectPage.setDeadlineCompletion();
|
||||
projectPage.clickSave();
|
||||
Assert.assertTrue(projectsPage.checkNameInList(name));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIDeleteDeadline() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
projectPage.clickDeleteDeadline();
|
||||
Assert.assertTrue(projectPage.getDeadlineCount() == 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJDeleteProject() {
|
||||
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||
ProjectPage projectPage = (ProjectPage) getContext().initPage(page.getKey());
|
||||
ProjectsPage projectsPage = (ProjectsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||
projectsPage.getFirstProject();
|
||||
String name = projectPage.getName();
|
||||
projectPage.clickSave();
|
||||
projectsPage.deleteFirst();
|
||||
projectsPage.clickConfirm();
|
||||
Assert.assertFalse(projectsPage.checkNameInList(name));
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package project;
|
||||
|
||||
import core.PageObject;
|
||||
import org.openqa.selenium.By;
|
||||
|
||||
public class ProjectDashboard extends PageObject {
|
||||
|
||||
public String getSubTitle() {
|
||||
return driver.findElement(By.tagName("h2")).getText();
|
||||
}
|
||||
}
|
@ -0,0 +1,141 @@
|
||||
package project;
|
||||
|
||||
import core.PageObject;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectPage extends PageObject {
|
||||
|
||||
public String getSubTitle() {
|
||||
return driver.findElement(By.tagName("h3")).getText();
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return driver.findElement(By.id("id")).getAttribute("value");
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
driver.findElement(By.id("title")).sendKeys(name);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return driver.findElement(By.id("title")).getAttribute("value");
|
||||
}
|
||||
|
||||
public void clearName() {
|
||||
driver.findElement(By.id("title")).clear();
|
||||
}
|
||||
|
||||
public void clickSave() {
|
||||
driver.findElement(By.id("sendMessageButton")).click();
|
||||
}
|
||||
|
||||
public void clickAddDeadline() {
|
||||
driver.findElement(By.id("addDeadline")).click();
|
||||
}
|
||||
|
||||
public void addDeadlineDate(String deadDate, Integer deadNum) {
|
||||
driver.findElement(By.id(String.format("deadlines%d.date", deadNum))).sendKeys(deadDate);
|
||||
}
|
||||
|
||||
public void addDeadlineDescription(String description) {
|
||||
driver.findElement(By.id("deadlines0.description")).sendKeys(description);
|
||||
}
|
||||
|
||||
public void setDeadlineCompletion() {
|
||||
driver.findElement(By.id("deadlines0.done1")).click();
|
||||
}
|
||||
|
||||
public void setStatus() {
|
||||
driver.findElement(By.id("status")).click();
|
||||
getFirstStatus();
|
||||
}
|
||||
|
||||
public void getFirstStatus() {
|
||||
driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click();
|
||||
}
|
||||
|
||||
public void addDescription(String description) {
|
||||
driver.findElement(By.id("description")).sendKeys(description);
|
||||
}
|
||||
|
||||
public void addLink(String link) {
|
||||
driver.findElement(By.id("repository")).sendKeys(link);
|
||||
}
|
||||
|
||||
public List<WebElement> getDeadlineList() {
|
||||
return driver.findElements(By.className("deadline"));
|
||||
}
|
||||
|
||||
public Integer getDeadlineCount() {
|
||||
return driver.findElements(By.className("deadline")).size();
|
||||
}
|
||||
|
||||
public void setExecutors() {
|
||||
driver.findElement(By.id("status")).click();
|
||||
getFirstExecutor();
|
||||
}
|
||||
|
||||
public void getFirstExecutor() {
|
||||
driver.findElement(By.xpath("//*[@id=\"status\"]/option[1]")).click();
|
||||
}
|
||||
|
||||
public void setDeadlineDescription(String description, Integer i) {
|
||||
driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description);
|
||||
}
|
||||
|
||||
public void setDeadlineDate(String date, Integer i) {
|
||||
driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date);
|
||||
}
|
||||
|
||||
public Boolean isTakePartButDisabledValueTrue() {
|
||||
return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true");
|
||||
}
|
||||
|
||||
public Integer getMemberCount() {
|
||||
return driver.findElements(By.className("member")).size();
|
||||
}
|
||||
|
||||
public void clickDeleteDeadline() {
|
||||
driver.findElement(By.className("btn-danger")).click();
|
||||
}
|
||||
|
||||
public void showAllowToAttachArticles() {
|
||||
driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click();
|
||||
}
|
||||
|
||||
public void clickAddPaperBut() {
|
||||
driver.findElement(By.id("add-paper")).click();
|
||||
}
|
||||
|
||||
|
||||
public List<WebElement> getArticles() {
|
||||
return driver.findElements(By.className("paper"));
|
||||
}
|
||||
|
||||
public Integer getArticlesCount() {
|
||||
return driver.findElements(By.className("paper")).size();
|
||||
}
|
||||
|
||||
public WebElement selectArticle() {
|
||||
WebElement webElement = driver.findElement(By.xpath("//*[@id=\"project-form\"]/div/div[2]/div[5]/div/div/div[2]/ul/li[1]/a"));
|
||||
webElement.click();
|
||||
return webElement;
|
||||
}
|
||||
|
||||
public void clickUndockArticleBut() {
|
||||
driver.findElement(By.name("removePaper")).click();
|
||||
}
|
||||
|
||||
public boolean checkDeadline(String description, String dateValue) {
|
||||
return getDeadlineList()
|
||||
.stream()
|
||||
.anyMatch(webElement -> {
|
||||
return webElement.findElement(By.className("deadline-text")).getAttribute("value").equals(description)
|
||||
&& webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,41 @@
|
||||
package project;
|
||||
|
||||
import core.PageObject;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebElement;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProjectsPage extends PageObject {
|
||||
|
||||
public String getSubTitle() {
|
||||
return driver.findElement(By.tagName("h2")).getText();
|
||||
}
|
||||
|
||||
public List<WebElement> getProjectsList() {
|
||||
return driver.findElements(By.cssSelector("span.h6"));
|
||||
}
|
||||
|
||||
public void getFirstProject() {
|
||||
driver.findElement(By.xpath("//*[@id=\"projects\"]/div/div[2]/div[1]/div[1]/div/a")).click();
|
||||
}
|
||||
|
||||
public void selectMember() {
|
||||
driver.findElements(By.className("bootstrap-select")).get(0).findElement(By.className("btn")).click();
|
||||
driver.findElements(By.className("bootstrap-select")).get(0).findElements(By.className("dropdown-item")).get(1).click();
|
||||
}
|
||||
|
||||
public void deleteFirst() {
|
||||
js.executeScript("$('a[data-confirm]').click();");
|
||||
}
|
||||
|
||||
public void clickConfirm() {
|
||||
driver.findElement(By.id("dataConfirmOK")).click();
|
||||
}
|
||||
|
||||
public boolean checkNameInList(String newProjectName) {
|
||||
return getProjectsList()
|
||||
.stream()
|
||||
.anyMatch(webElement -> webElement.getText().equals(newProjectName));
|
||||
}
|
||||
}
|
@ -0,0 +1,148 @@
|
||||
package ru.ulstu.project.service;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
import ru.ulstu.deadline.model.Deadline;
|
||||
import ru.ulstu.deadline.service.DeadlineService;
|
||||
import ru.ulstu.file.model.FileData;
|
||||
import ru.ulstu.file.service.FileService;
|
||||
import ru.ulstu.grant.model.GrantDto;
|
||||
import ru.ulstu.grant.service.GrantService;
|
||||
import ru.ulstu.project.model.Project;
|
||||
import ru.ulstu.project.model.ProjectDto;
|
||||
import ru.ulstu.project.repository.ProjectRepository;
|
||||
import ru.ulstu.timeline.service.EventService;
|
||||
import ru.ulstu.user.model.User;
|
||||
import ru.ulstu.user.service.UserService;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.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;
|
||||
private GrantDto grant;
|
||||
private List<GrantDto> grants;
|
||||
|
||||
@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);
|
||||
|
||||
grants = new ArrayList<>();
|
||||
grant = new GrantDto();
|
||||
grant.setId(ID);
|
||||
grants.add(grant);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void findAll() {
|
||||
when(projectRepository.findAll()).thenReturn(projects);
|
||||
assertEquals(projects, projectService.findAll());
|
||||
}
|
||||
|
||||
@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.exists(ID)).thenReturn(true);
|
||||
when(projectRepository.findOne(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.findOne(ID)).thenReturn(project);
|
||||
assertEquals(project, projectService.findById(ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void removeDeadline() throws IOException {
|
||||
ProjectDto newProjectDto = new ProjectDto();
|
||||
newProjectDto.getRemovedDeadlineIds().add(INDEX);
|
||||
projectDto.getDeadlines().add(deadline);
|
||||
ProjectDto result = projectService.removeDeadline(projectDto, INDEX);
|
||||
|
||||
assertEquals(newProjectDto.getDeadlines(), result.getDeadlines());
|
||||
assertEquals(newProjectDto.getRemovedDeadlineIds(), result.getRemovedDeadlineIds());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue