Merge branch '103-integr-tests-grant' into 'dev'

Resolve "Реализовать интеграционные автотесты для проверки модулей"

See merge request romanov73/ng-tracker!106
environments/staging/deployments/82
Anton Romanov 5 years ago
commit 624573a47a

@ -25,9 +25,9 @@ import ru.ulstu.user.service.UserService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Collections;
import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty;

@ -1,6 +1,5 @@
package ru.ulstu.grant.service;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.grant.model.Grant;
import ru.ulstu.grant.model.GrantDto;
import ru.ulstu.project.model.Project;
import ru.ulstu.project.model.ProjectDto;

@ -12,16 +12,16 @@ import ru.ulstu.grant.model.Grant;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.user.model.User;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.OneToMany;
import javax.persistence.CascadeType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.FetchType;
import javax.persistence.ManyToMany;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import java.util.ArrayList;
import java.util.Collections;

@ -6,13 +6,8 @@ import org.hibernate.validator.constraints.NotBlank;
import ru.ulstu.core.model.BaseEntity;
import ru.ulstu.core.model.EventSource;
import ru.ulstu.deadline.model.Deadline;
import ru.ulstu.deadline.service.DeadlineService;
import ru.ulstu.students.repository.SchedulerRepository;
import ru.ulstu.students.repository.TaskRepository;
import ru.ulstu.tags.model.Tag;
import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.model.Event;
import ru.ulstu.timeline.service.EventService;
import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;

@ -18,15 +18,15 @@ import ru.ulstu.tags.service.TagService;
import ru.ulstu.timeline.service.EventService;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.stream.Collectors;
import static org.springframework.util.ObjectUtils.isEmpty;

@ -18,7 +18,6 @@ import ru.ulstu.timeline.repository.EventRepository;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.service.UserService;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.List;

@ -3,7 +3,6 @@ package ru.ulstu.user.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.annotation.Secured;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
@ -33,7 +32,6 @@ import ru.ulstu.user.service.UserSessionService;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.Map;
import static ru.ulstu.user.controller.UserController.URL;

@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import ru.ulstu.configuration.Constants;
import ru.ulstu.odin.controller.OdinController;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.User;
import ru.ulstu.user.model.UserDto;
import ru.ulstu.user.model.UserListDto;
import ru.ulstu.user.service.UserService;
import ru.ulstu.user.service.UserSessionService;

@ -252,7 +252,7 @@ public class UserService implements UserDetailsService {
mailService.sendChangePasswordMail(user);
}
public boolean requestUserPasswordReset(String email) {
public boolean requestUserPasswordReset(String email) {
User user = userRepository.findOneByEmailIgnoreCase(email);
if (user == null) {
throw new UserNotFoundException(email);

@ -18,7 +18,7 @@ public class TimetableService {
private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s";
private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm");
private long[] lessonsStarts = new long[] {
private long[] lessonsStarts = new long[]{
lessonTimeFormat.parse("8:00:00").getTime(),
lessonTimeFormat.parse("9:40:00").getTime(),
lessonTimeFormat.parse("11:30:00").getTime(),
@ -58,8 +58,8 @@ public class TimetableService {
firstJan.set(Calendar.MONTH, 0);
firstJan.set(Calendar.DAY_OF_MONTH, 1);
return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000)
+ DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2));
return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000)
+ DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2));
}
private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException {
@ -67,7 +67,7 @@ public class TimetableService {
return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class);
}
public Lesson getCurrentLesson(String userFio) {
public Lesson getCurrentLesson(String userFio) {
TimetableResponse response;
try {
response = getTimetableForUser(userFio);

@ -4,7 +4,7 @@ import java.util.ArrayList;
import java.util.List;
public class Day {
public class Day {
private Integer day;
private List<List<Lesson>> lessons = new ArrayList<>();

@ -1,6 +1,6 @@
package ru.ulstu.utils.timetable.model;
public class Lesson {
public class Lesson {
private String group;
private String nameOfLesson;
private String teacher;

@ -1,6 +1,6 @@
package ru.ulstu.utils.timetable.model;
public class TimetableResponse {
public class TimetableResponse {
private Response response;
private String error;

@ -156,14 +156,16 @@
<a class="paper-name"
th:href="@{'/papers/paper?id=' + *{papers[__${rowStat.index}__].id} + ''}"
th:if="*{papers[__${rowStat.index}__].id !=null}">
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=*{papers[__${rowStat.index}__].status})"/>
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=*{papers[__${rowStat.index}__].status},
title=*{papers[__${rowStat.index}__].title}, small=false)"/>
<span th:text="*{papers[__${rowStat.index}__].title}">
Имя статьи
</span>
</a>
<a class="paper-name"
th:unless="*{papers[__${rowStat.index}__].id !=null}">
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=*{papers[__${rowStat.index}__].status})"/>
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=*{papers[__${rowStat.index}__].status},
title=*{papers[__${rowStat.index}__].title}, small=false)"/>
<span th:text="*{papers[__${rowStat.index}__].title}">
Имя статьи
</span>

@ -8,10 +8,16 @@
<div class="col">
<span th:replace="grants/fragments/grantStatusFragment :: grantStatus(grantStatus=${grant.status})"/>
<a th:href="@{'grant?id='+${grant.id}}">
<span class="h6" th:if="${#strings.length(grant.title) > 50}" th:text="${#strings.substring(grant.title, 0, 50)} + '...'" th:title="${grant.title}"/>
<span class="h6" th:if="${#strings.length(grant.title) le 50}" th:text="${grant.title}" th:title="${grant.title}"/>
<span class="h6" th:if="${#strings.length(grant.title) > 50}"
th:text="${#strings.substring(grant.title, 0, 50)} + '...'" th:title="${grant.title}"/>
<span class="h6" th:if="${#strings.length(grant.title) le 50}" th:text="${grant.title}"
th:title="${grant.title}"/>
<span class="text-muted" th:text="${grant.authorsString}"/>
</a>
<span th:each="paper, rowStat : *{grant.papers}">
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status},
title=${paper.title}, small=true)"/>
</span>
<input class="id-class" type="hidden" th:value="${grant.id}"/>
<a class="remove-paper pull-right d-none" th:href="@{'/grants/delete/'+${grant.id}}"
data-confirm="Удалить грант?">

@ -25,7 +25,7 @@
<i class="fa fa-circle fa-stack-2x text-failed"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
<i class="fa fa-clipboard fa-stack-1x fa-inverse"></i>
</span>
</body>
</html>

@ -49,7 +49,7 @@
<div class="form-group">
<label>Дедлайны показателей:</label>
<input type="hidden" th:field="*{removedDeadlineIds}"/>
<div class="row" th:each="deadline, rowStat : *{deadlines}">
<div class="row" id="deadlines" th:each="deadline, rowStat : *{deadlines}">
<input type="hidden" th:field="*{deadlines[__${rowStat.index}__].id}"/>
<div class="col-6 div-deadline-date">
<input type="date" class="form-control form-deadline-date" name="deadline"
@ -191,6 +191,7 @@
</div>
</div>
</div>
<!--
<div class="form-group">
<div th:if="*{project} == null">
<input type="submit" name="createProject" class="btn btn-primary"
@ -198,6 +199,7 @@
</div>
<input type = "hidden" th:field="*{project.id}"/>
</div>
-->
</div>
<div class="clearfix"></div>
<div class="col-lg-12">

@ -7,7 +7,8 @@
<div th:fragment="paperDashboard (paper)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
<div class="row">
<div class="col-2">
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status},
title=${paper.title}, small=false)"/>
</div>
<div class="col col-10 text-right">
<p th:if="${paper.url!=null and paper.url!=''}"><a target="_blank" class="externalLink"

@ -6,10 +6,12 @@
<body>
<div th:fragment="paperLine (paper)" class="row text-left paper-row" style="background-color: white;">
<div class="col">
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status})"/>
<a th:href="@{'paper?id='+${paper.id}}">
<span class="h6" th:if="${#strings.length(paper.title)} > 50" th:text="${#strings.substring(paper.title, 0, 50) + '...'}" th:title="${paper.title}"/>
<span class="h6" th:if="${#strings.length(paper.title) le 50}" th:text="${paper.title}" th:title="${paper.title}"/>
<span th:replace="papers/fragments/paperStatusFragment :: paperStatus(paperStatus=${paper.status}, title=${paper.title}, small=false)"/>
<a th:href="@{'../papers/paper?id='+${paper.id}}">
<span class="h6" th:if="${#strings.length(paper.title)} > 50"
th:text="${#strings.substring(paper.title, 0, 50) + '...'}" th:title="${paper.title}"/>
<span class="h6" th:if="${#strings.length(paper.title) le 50}" th:text="${paper.title}"
th:title="${paper.title}"/>
<span class="text-muted" th:text="${paper.authorsString}"/>
</a>
<input class="id-class" type="hidden" th:value="${paper.id}"/>

@ -4,34 +4,35 @@
<meta charset="UTF-8"/>
</head>
<body>
<span th:fragment="paperStatus (paperStatus)" class="fa-stack fa-1x">
<span th:fragment="paperStatus (paperStatus, title, small)" class="fa-stack fa-1x">
<th:block th:switch="${paperStatus.name()}">
<div th:case="'ATTENTION'">
<i class="fa fa-circle fa-stack-2x text-warning"></i>
<i class="fa fa-circle text-warning" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'DRAFT'">
<i class="fa fa-circle fa-stack-2x text-draft"></i>
<i class="fa fa-circle fa-stack-2x text-draft" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'ON_PREPARATION'">
<i class="fa fa-circle fa-stack-2x text-primary"></i>
<i class="fa fa-circle fa-stack-2x text-primary" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'ON_REVIEW'">
<i class="fa fa-circle fa-stack-2x text-review"></i>
<i class="fa fa-circle fa-stack-2x text-review" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'COMPLETED'">
<i class="fa fa-circle fa-stack-2x text-success"></i>
<i class="fa fa-circle fa-stack-2x text-success" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'FAILED'">
<i class="fa fa-circle fa-stack-2x text-failed"></i>
<i class="fa fa-circle fa-stack-2x text-failed" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'ACCEPTED'">
<i class="fa fa-circle fa-stack-2x text-accepted"></i>
<i class="fa fa-circle fa-stack-2x text-accepted" th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
<div th:case="'NOT_ACCEPTED'">
<i class="fa fa-circle fa-stack-2x text-not-accepted"></i>
<i class="fa fa-circle fa-stack-2x text-not-accepted"
th:classappend="${small} ? fa-stack-1x : fa-stack-2x"></i>
</div>
</th:block>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse"></i>
<i class="fa fa-file-text-o fa-stack-1x fa-inverse" th:title="${title}"></i>
</span>
</body>
</html>

@ -530,6 +530,7 @@
}
}
</script>
<script th:inline="javascript">
/*<![CDATA[*/

@ -98,9 +98,11 @@
</div>
<div class="col-12" style="margin-bottom: 15px;"></div>
<div class="col-10 div-deadline-executor">
<select class="selectpicker form-control" multiple="true" data-live-search="true"
<select class="selectpicker form-control" multiple="true"
data-live-search="true"
title="-- Выберите исполнителя --" id="executors"
th:field="*{deadlines[__${rowStat.index}__].executors}" data-size="5">
th:field="*{deadlines[__${rowStat.index}__].executors}"
data-size="5">
<option th:each="executors : ${allExecutors}" th:value="${executors.id}"
th:text="${executors.lastName}"> Участник
</option>

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="en"
xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
layout:decorator="default" xmlns:th="http://www.w3.org/1999/xhtml">
layout:decorator="default">
<head>
<script src="/js/users.js"></script>
<link rel="stylesheet" href="../css/base.css"/>
@ -35,7 +35,8 @@
<input type="text" name="email" id="resetKey" class="form-control"
placeholder="Код подтверждения" style="display:none"/>
</div>
<div id="dvloader" class="loader" style="display:none"><img src="../img/main/ajax-loader.gif" /></div>
<div id="dvloader" class="loader" style="display:none"><img src="../img/main/ajax-loader.gif"/>
</div>
<button id="btnSend" type="button" onclick="requestResetPassword()"
class="btn btn-success btn-block">
Отправить код подтверждения

@ -29,6 +29,7 @@
showFeedbackMessage(error, MessageTypesEnum.WARNING)
});
/*]]>*/
</script>
</div>
</body>

@ -7,9 +7,13 @@
<div th:fragment="userDashboard (user)" class="col-12 col-sm-12 col-md-12 col-lg-4 col-xl-3 dashboard-card">
<div class="row">
<div class="col col-10">
<b><p th:text="${user.user.lastName} + ' ' + ${user.user.firstName} + ' ' + ${user.user.patronymic}"></p></b>
<i><p th:if="${user.conference != null}" th:text="'Сейчас на конференции ' + ${user.conference.title}"></p></i>
<i><p th:if="${user.lesson != null}" th:text="'Сейчас на паре ' + ${user.lesson.nameOfLesson} + ' в аудитории ' + ${user.lesson.room}"></p></i>
<b><p th:text="${user.user.lastName} + ' ' + ${user.user.firstName} + ' ' + ${user.user.patronymic}"></p>
</b>
<i><p th:if="${user.conference != null}" th:text="'Сейчас на конференции ' + ${user.conference.title}"></p>
</i>
<i><p th:if="${user.lesson != null}"
th:text="'Сейчас на паре ' + ${user.lesson.nameOfLesson} + ' в аудитории ' + ${user.lesson.room}"></p>
</i>
<p th:if="${user.isOnline()}">Онлайн</p>
</div>
</div>

@ -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,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;
}
}

@ -20,7 +20,10 @@ import ru.ulstu.user.model.User;
import ru.ulstu.user.service.UserService;
import java.io.IOException;
import java.util.*;
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;

Loading…
Cancel
Save