#93 merged with dev
commit
0bb9d5771f
@ -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,29 @@
|
|||||||
|
package ru.ulstu.grant.controller;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import ru.ulstu.configuration.Constants;
|
||||||
|
import ru.ulstu.grant.service.GrantService;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.text.ParseException;
|
||||||
|
|
||||||
|
import static ru.ulstu.paper.controller.PaperRestController.URL;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping(URL)
|
||||||
|
public class GrantRestController {
|
||||||
|
public static final String URL = Constants.API_1_0 + "grants";
|
||||||
|
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantRestController(GrantService grantService) {
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/grab")
|
||||||
|
public void grab() throws IOException, ParseException {
|
||||||
|
grantService.createFromKias();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package ru.ulstu.ping.model;
|
||||||
|
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PingInfo {
|
||||||
|
private User user;
|
||||||
|
private List<Ping> pings = new ArrayList<>();
|
||||||
|
|
||||||
|
public PingInfo(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public User getUser() {
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUser(User user) {
|
||||||
|
this.user = user;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Ping> getPings() {
|
||||||
|
return pings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPings(List<Ping> pings) {
|
||||||
|
this.pings = pings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addPing(Ping ping) {
|
||||||
|
this.pings.add(ping);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
package ru.ulstu.ping.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.model.UserActivity;
|
||||||
|
import ru.ulstu.ping.model.Ping;
|
||||||
|
import ru.ulstu.ping.model.PingInfo;
|
||||||
|
import ru.ulstu.ping.repository.PingRepository;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class PingScheduler {
|
||||||
|
private final Logger log = LoggerFactory.getLogger(PingScheduler.class);
|
||||||
|
private final PingRepository pingRepository;
|
||||||
|
private final MailService mailService;
|
||||||
|
private final static String PING_MAIL_SUBJECT = "Ping статистика";
|
||||||
|
|
||||||
|
public PingScheduler(PingRepository pingRepository, MailService mailService) {
|
||||||
|
this.pingRepository = pingRepository;
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 * * 1 ?")
|
||||||
|
public void sendPingsInfo() {
|
||||||
|
log.debug("Scheduler.sendPingsInfo started");
|
||||||
|
|
||||||
|
List<PingInfo> pingInfos = new ArrayList<>();
|
||||||
|
|
||||||
|
for (Ping ping : pingRepository.findByDate(java.sql.Date.valueOf(LocalDate.now().minusWeeks(1)))) {
|
||||||
|
UserActivity pingActivity = ping.getActivity();
|
||||||
|
Set<User> users = pingActivity.getActivityUsers();
|
||||||
|
|
||||||
|
for (User user : users) {
|
||||||
|
PingInfo userPing = pingInfos.stream().filter(u -> u.getUser() == user).findFirst().orElse(null);
|
||||||
|
if (userPing == null) {
|
||||||
|
userPing = new PingInfo(user);
|
||||||
|
pingInfos.add(userPing);
|
||||||
|
}
|
||||||
|
userPing.addPing(ping);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (PingInfo pingInfo : pingInfos) {
|
||||||
|
mailService.sendEmailFromTemplate(ImmutableMap.of("pings", pingInfo.getPings()),
|
||||||
|
pingInfo.getUser(), "pingsInfoWeekEmail", PING_MAIL_SUBJECT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,21 +1,8 @@
|
|||||||
package ru.ulstu.project.repository;
|
package ru.ulstu.project.repository;
|
||||||
|
|
||||||
import org.springframework.data.jpa.repository.JpaRepository;
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
import org.springframework.data.jpa.repository.Query;
|
|
||||||
import org.springframework.data.repository.query.Param;
|
|
||||||
import ru.ulstu.paper.model.Paper;
|
|
||||||
import ru.ulstu.project.model.Project;
|
import ru.ulstu.project.model.Project;
|
||||||
import ru.ulstu.user.model.User;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface ProjectRepository extends JpaRepository<Project, Integer> {
|
public interface ProjectRepository extends JpaRepository<Project, Integer> {
|
||||||
@Query("SELECT p FROM Project p WHERE (:user IS NULL OR user MEMBER OF p.authors) AND (:status IS NULL OR :status = p.status) " +
|
|
||||||
"AND (:dateFrom IS NULL OR :dateFrom < p.updateDate) AND (:dateTo IS NULL OR :dateTo > p.updateDate)")
|
|
||||||
List<Project> findByAuthorHasAndStatus(@Param("user") User user,
|
|
||||||
@Param("status") Project.ProjectStatus status,
|
|
||||||
@Param("dateFrom") Date dateFrom,
|
|
||||||
@Param("dateTo") Date dateTo);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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,11 @@
|
|||||||
|
<?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="arefyev" id="20190525_000000-1">
|
||||||
|
<addColumn tableName="ping">
|
||||||
|
<column name="activity_type" type="varchar(20)"/>
|
||||||
|
<column name="activity_id" type="integer"/>
|
||||||
|
</addColumn>
|
||||||
|
</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,225 @@
|
|||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import core.PageObject;
|
||||||
|
import core.TestTemplate;
|
||||||
|
import grant.GrantPage;
|
||||||
|
import grant.GrantsDashboardPage;
|
||||||
|
import grant.GrantsPage;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.FixMethodOrder;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.junit.runners.MethodSorters;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
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 GrantTest extends TestTemplate {
|
||||||
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
|
new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"),
|
||||||
|
new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"),
|
||||||
|
new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard")
|
||||||
|
);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void aCreateNewGrant() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
|
||||||
|
String newGrantName = "test grant" + (new Date());
|
||||||
|
grantPage.setTitle(newGrantName);
|
||||||
|
String deadlineDate = new Date().toString();
|
||||||
|
String deadlineDescription = "test deadline description";
|
||||||
|
grantPage.setDeadline(deadlineDate, 0, deadlineDescription);
|
||||||
|
grantPage.setLeader();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bCreateBlankGrant() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
Assert.assertTrue(grantPage.checkBlankFields());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void cUpdateGrantTitle() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
String newGrantTitle = "test " + (new Date());
|
||||||
|
grantPage.setTitle(newGrantTitle);
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void dAttachPaper() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
Integer countPapers = grantPage.getAttachedPapers().size();
|
||||||
|
|
||||||
|
Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void eDeletePaper() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
Integer oldCountPapers = grantPage.getAttachedPapers().size();
|
||||||
|
if (oldCountPapers == 0) {
|
||||||
|
oldCountPapers = grantPage.attachPaper().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void fAddDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
String grantId = grantPage.getId();
|
||||||
|
Integer deadlineCount = grantPage.getDeadlineCount();
|
||||||
|
|
||||||
|
String description = "deadline test";
|
||||||
|
String date = "08.08.2019";
|
||||||
|
String dateValue = "2019-08-08";
|
||||||
|
grantPage.addDeadline();
|
||||||
|
grantPage.setDeadline(date, deadlineCount, description);
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId));
|
||||||
|
|
||||||
|
Assert.assertTrue(grantPage.checkDeadline(description, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void gDeleteDeadline() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
String grantId = grantPage.getId();
|
||||||
|
Integer deadlineCount = grantPage.getDeadlineCount();
|
||||||
|
|
||||||
|
grantPage.deleteDeadline();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId));
|
||||||
|
Integer newDeadlineCount = grantPage.getDeadlineCount();
|
||||||
|
Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void hAddAuthor() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
WebElement grant = grantsPage.getFirstGrantWithoutClick();
|
||||||
|
String grantTitle = grantsPage.getGrantTitle(grant);
|
||||||
|
Integer authorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
grantPage.addAuthor();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
grant = grantsPage.getGrantByTitle(grantTitle);
|
||||||
|
Integer newAuthorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iDeleteAuthor() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
WebElement grant = grantsPage.getFirstGrantWithoutClick();
|
||||||
|
String grantTitle = grantsPage.getGrantTitle(grant);
|
||||||
|
Integer authorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
grantPage.deleteAuthor();
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
grant = grantsPage.getGrantByTitle(grantTitle);
|
||||||
|
Integer newAuthorsCount = grantsPage.getAuthorsCount(grant);
|
||||||
|
|
||||||
|
authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1;
|
||||||
|
|
||||||
|
Assert.assertEquals((int) authorsCount, (int) newAuthorsCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jUpdateGrantDescription() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
String description = "newDescriptionForGrant";
|
||||||
|
grantsPage.getFirstGrant();
|
||||||
|
String grantId = grantPage.getId();
|
||||||
|
grantPage.setDescription(description);
|
||||||
|
grantPage.saveGrant();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId));
|
||||||
|
|
||||||
|
Assert.assertTrue(description.equals(grantPage.getDescription()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void kDeleteGrant() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
Integer size = grantsPage.getGrantsList().size();
|
||||||
|
grantsPage.deleteFirst();
|
||||||
|
Assert.assertEquals(size - 1, grantsPage.getGrantsList().size());
|
||||||
|
}
|
||||||
|
}
|
@ -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,149 @@
|
|||||||
|
package grant;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.openqa.selenium.support.ui.Select;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GrantPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h2")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return driver.findElement(By.id("id")).getAttribute("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String name) {
|
||||||
|
driver.findElement(By.id("title")).clear();
|
||||||
|
driver.findElement(By.id("title")).sendKeys(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return driver.findElement(By.id("title")).getAttribute("value");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeadline(String date, Integer i, String description) {
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date);
|
||||||
|
driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLeader() {
|
||||||
|
WebElement webElement = driver.findElement(By.id("leaderId"));
|
||||||
|
Select selectLeader = new Select(webElement);
|
||||||
|
selectLeader.selectByVisibleText("Романов");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void saveGrant() {
|
||||||
|
driver.findElement(By.id("sendMessageButton")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkBlankFields() {
|
||||||
|
return driver.findElements(By.className("alert-danger")).size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getAttachedPapers() {
|
||||||
|
try {
|
||||||
|
return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div"));
|
||||||
|
} catch (Exception ex) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> attachPaper() {
|
||||||
|
WebElement selectPapers = driver.findElement(By.id("allPapers"));
|
||||||
|
Select select = new Select(selectPapers);
|
||||||
|
List<WebElement> selectedOptions = select.getAllSelectedOptions();
|
||||||
|
List<WebElement> allOptions = select.getOptions();
|
||||||
|
if (selectedOptions.size() >= allOptions.size()) {
|
||||||
|
for (int i = 0; i < allOptions.size(); i++) {
|
||||||
|
if (!allOptions.get(i).equals(selectedOptions.get(i))) {
|
||||||
|
select.selectByVisibleText(allOptions.get(i).getText());
|
||||||
|
selectedOptions.add(allOptions.get(i));
|
||||||
|
return selectedOptions;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
select.selectByVisibleText(allOptions.get(0).getText());
|
||||||
|
selectedOptions.add(allOptions.get(0));
|
||||||
|
return selectedOptions;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> deletePaper() {
|
||||||
|
WebElement selectPapers = driver.findElement(By.id("allPapers"));
|
||||||
|
Select select = new Select(selectPapers);
|
||||||
|
select.deselectByVisibleText(select.getFirstSelectedOption().getText());
|
||||||
|
return select.getAllSelectedOptions();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getDeadlineList() {
|
||||||
|
return driver.findElements(By.id("deadlines"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDeadlineCount() {
|
||||||
|
return getDeadlineList().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addDeadline() {
|
||||||
|
driver.findElement(By.id("addDeadline")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkDeadline(String description, String dateValue) {
|
||||||
|
return getDeadlineList()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(webElement -> {
|
||||||
|
return webElement.findElement(By.className("div-deadline-description")).findElement(
|
||||||
|
By.tagName("input")).getAttribute("value").equals(description)
|
||||||
|
&& webElement.findElement(By.className("form-deadline-date")).getAttribute("value").equals(dateValue);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteDeadline() {
|
||||||
|
driver.findElements(By.className("btn-delete-deadline")).get(0).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> addAuthor() {
|
||||||
|
WebElement selectAuthors = driver.findElement(By.id("authors"));
|
||||||
|
Select select = new Select(selectAuthors);
|
||||||
|
List<WebElement> selectedOptions = select.getAllSelectedOptions();
|
||||||
|
List<WebElement> allOptions = select.getOptions();
|
||||||
|
int i = 0;
|
||||||
|
while (i < selectedOptions.size()) {
|
||||||
|
if (!allOptions.get(i).equals(selectedOptions.get(i))) {
|
||||||
|
select.selectByVisibleText(allOptions.get(i).getText());
|
||||||
|
selectedOptions.add(allOptions.get(i));
|
||||||
|
return selectedOptions;
|
||||||
|
} else {
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selectedOptions.size() != allOptions.size()) {
|
||||||
|
select.selectByVisibleText(allOptions.get(i).getText());
|
||||||
|
selectedOptions.add(allOptions.get(i));
|
||||||
|
}
|
||||||
|
return selectedOptions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAuthor() {
|
||||||
|
WebElement selectAuthors = driver.findElement(By.id("authors"));
|
||||||
|
Select select = new Select(selectAuthors);
|
||||||
|
List<WebElement> selectedOptions = select.getAllSelectedOptions();
|
||||||
|
if (selectedOptions.size() != 0) {
|
||||||
|
select.deselectByVisibleText(selectedOptions.get(0).getText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
driver.findElement(By.id("comment")).clear();
|
||||||
|
driver.findElement(By.id("comment")).sendKeys(description);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return driver.findElement(By.id("comment")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package grant;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
|
||||||
|
public class GrantsDashboardPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h2")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package grant;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GrantsPage extends PageObject {
|
||||||
|
@Override
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h2")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getGrantsList() {
|
||||||
|
return driver.findElements(By.className("grant-row"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean findGrantByTitle(String grantTitle) {
|
||||||
|
return getGrantsList()
|
||||||
|
.stream()
|
||||||
|
.map(el -> el.findElement(By.cssSelector("span.h6")))
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(grantTitle));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFirst() throws InterruptedException {
|
||||||
|
WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div"));
|
||||||
|
findDeleteButton.click();
|
||||||
|
Thread.sleep(3000);
|
||||||
|
WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]"));
|
||||||
|
grant.click();
|
||||||
|
WebElement ok = driver.findElement(By.id("dataConfirmOK"));
|
||||||
|
ok.click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getFirstGrant() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebElement getFirstGrantWithoutClick() {
|
||||||
|
return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantTitle(WebElement webElement) {
|
||||||
|
return webElement.findElement(By.cssSelector("span.h6")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebElement getGrantByTitle(String title) {
|
||||||
|
List<WebElement> list = getGrantsList();
|
||||||
|
for (int i = 0; i < list.size(); i++) {
|
||||||
|
if (getGrantTitle(list.get(i)).equals(title)) {
|
||||||
|
return list.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getAuthorsCount(WebElement webElement) {
|
||||||
|
String authors = webElement.findElement(By.className("text-muted")).getText();
|
||||||
|
if (!authors.equals("")) {
|
||||||
|
String[] mas = authors.split(",");
|
||||||
|
return mas.length;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
@ -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,151 @@
|
|||||||
|
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.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(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