Merge branch 'dev' of https://gitlab.com/romanov73/ng-tracker into dev
commit
50314246f5
@ -0,0 +1,73 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import ru.ulstu.core.util.DateUtils;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.user.model.User;
|
||||||
|
import ru.ulstu.user.service.MailService;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantNotificationService {
|
||||||
|
private final static int DAYS_TO_DEADLINE_NOTIFICATION = 7;
|
||||||
|
private final static String TEMPLATE_DEADLINE = "grantDeadlineNotification";
|
||||||
|
private final static String TEMPLATE_CREATE = "grantCreateNotification";
|
||||||
|
private final static String TEMPLATE_AUTHORS_CHANGED = "grantAuthorsChangeNotification";
|
||||||
|
private final static String TEMPLATE_LEADER_CHANGED = "grantLeaderChangeNotification";
|
||||||
|
|
||||||
|
private final static String TITLE_DEADLINE = "Приближается дедлайн гранта: %s";
|
||||||
|
private final static String TITLE_CREATE = "Создан грант: %s";
|
||||||
|
private final static String TITLE_AUTHORS_CHANGED = "Изменился состав рабочей группы гранта: %s";
|
||||||
|
private final static String TITLE_LEADER_CHANGED = "Изменился руководитель гранта: %s";
|
||||||
|
|
||||||
|
private final MailService mailService;
|
||||||
|
|
||||||
|
public GrantNotificationService(MailService mailService) {
|
||||||
|
this.mailService = mailService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendDeadlineNotifications(List<Grant> grants, boolean isDeadlineBeforeWeek) {
|
||||||
|
Date now = DateUtils.addDays(new Date(), DAYS_TO_DEADLINE_NOTIFICATION);
|
||||||
|
grants.stream()
|
||||||
|
.filter(grant -> needToSendDeadlineNotification(grant, now, isDeadlineBeforeWeek))
|
||||||
|
.forEach(grant -> sendMessageDeadline(grant));
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean needToSendDeadlineNotification(Grant grant, Date compareDate, boolean isDeadlineBeforeWeek) {
|
||||||
|
return (grant.getNextDeadline().isPresent())
|
||||||
|
&& (compareDate.before(grant.getNextDeadline().get().getDate()) && isDeadlineBeforeWeek
|
||||||
|
|| compareDate.after(grant.getNextDeadline().get().getDate()) && !isDeadlineBeforeWeek)
|
||||||
|
&& grant.getNextDeadline().get().getDate().after(new Date());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendMessageDeadline(Grant grant) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_DEADLINE, String.format(TITLE_DEADLINE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendCreateNotification(Grant grant) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_CREATE, String.format(TITLE_CREATE, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendAuthorsChangeNotification(Grant grant, Set<User> oldAuthors) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldAuthors", oldAuthors);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_AUTHORS_CHANGED, String.format(TITLE_AUTHORS_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void sendLeaderChangeNotification(Grant grant, User oldLeader) {
|
||||||
|
Map<String, Object> variables = ImmutableMap.of("grant", grant, "oldLeader", oldLeader);
|
||||||
|
sendForAllAuthors(variables, grant, TEMPLATE_LEADER_CHANGED, String.format(TITLE_LEADER_CHANGED, grant.getTitle()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendForAllAuthors(Map<String, Object> variables, Grant grant, String template, String title) {
|
||||||
|
Set<User> allAuthors = grant.getAuthors();
|
||||||
|
allAuthors.forEach(author -> mailService.sendEmailFromTemplate(variables, author, template, title));
|
||||||
|
mailService.sendEmailFromTemplate(variables, grant.getLeader(), template, title);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,30 @@
|
|||||||
|
package ru.ulstu.grant.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class GrantScheduler {
|
||||||
|
private final static boolean IS_DEADLINE_NOTIFICATION_BEFORE_WEEK = true;
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(GrantScheduler.class);
|
||||||
|
|
||||||
|
private final GrantNotificationService grantNotificationService;
|
||||||
|
private final GrantService grantService;
|
||||||
|
|
||||||
|
public GrantScheduler(GrantNotificationService grantNotificationService,
|
||||||
|
GrantService grantService) {
|
||||||
|
this.grantNotificationService = grantNotificationService;
|
||||||
|
this.grantService = grantService;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 8 * * MON", zone = "Europe/Samara")
|
||||||
|
public void checkDeadlineBeforeWeek() {
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek started");
|
||||||
|
grantNotificationService.sendDeadlineNotifications(grantService.findAll(), IS_DEADLINE_NOTIFICATION_BEFORE_WEEK);
|
||||||
|
log.debug("GrantScheduler.checkDeadlineBeforeWeek finished");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.data.repository.query.Param;
|
||||||
|
|
||||||
|
public interface BaseRepository {
|
||||||
|
String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id);
|
||||||
|
}
|
@ -0,0 +1,16 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.validation.Errors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public abstract class BaseService {
|
||||||
|
|
||||||
|
public BaseRepository baseRepository;
|
||||||
|
|
||||||
|
public void checkUniqueName(NameContainer nameContainer, Errors errors, Integer id, String checkField, String errorMessage) {
|
||||||
|
if (nameContainer.getName().equals(baseRepository.findByNameAndNotId(nameContainer.getName(), id))) {
|
||||||
|
errors.rejectValue(checkField, "errorCode", errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package ru.ulstu.name;
|
||||||
|
|
||||||
|
public abstract class NameContainer {
|
||||||
|
|
||||||
|
private String name = "";
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package ru.ulstu.students.model;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import ru.ulstu.core.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.JoinColumn;
|
||||||
|
import javax.persistence.OneToOne;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Temporal;
|
||||||
|
import javax.persistence.TemporalType;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "scheduler")
|
||||||
|
public class Scheduler extends BaseEntity {
|
||||||
|
|
||||||
|
@OneToOne(optional = false)
|
||||||
|
@JoinColumn(name = "task_id")
|
||||||
|
private Task task;
|
||||||
|
|
||||||
|
@Temporal(value = TemporalType.TIMESTAMP)
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||||
|
private Date date;
|
||||||
|
|
||||||
|
public Scheduler() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scheduler(Task task, Date date) {
|
||||||
|
this.task = task;
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task getTask() {
|
||||||
|
return task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTask(Task task) {
|
||||||
|
this.task = task;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getDate() {
|
||||||
|
return date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Date date) {
|
||||||
|
this.date = date;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package ru.ulstu.students.repository;
|
||||||
|
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import ru.ulstu.students.model.Scheduler;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
|
|
||||||
|
public interface SchedulerRepository extends JpaRepository<Scheduler, Integer> {
|
||||||
|
|
||||||
|
Scheduler findOneByTask(Task task);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package ru.ulstu.students.service;
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import ru.ulstu.students.model.Scheduler;
|
||||||
|
import ru.ulstu.students.model.Task;
|
||||||
|
import ru.ulstu.students.repository.SchedulerRepository;
|
||||||
|
import ru.ulstu.tags.model.Tag;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class SchedulerService {
|
||||||
|
|
||||||
|
private final TaskService taskService;
|
||||||
|
private final SchedulerRepository schedulerRepository;
|
||||||
|
|
||||||
|
public SchedulerService(TaskService taskService, SchedulerRepository schedulerRepository) {
|
||||||
|
this.taskService = taskService;
|
||||||
|
this.schedulerRepository = schedulerRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void save(Tag tag) {
|
||||||
|
List<Task> taskList = taskService.findTasksByTag(tag);
|
||||||
|
create(taskList.get(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private Scheduler create(Task task) {
|
||||||
|
Scheduler scheduler = new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate());
|
||||||
|
return schedulerRepository.save(scheduler);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
private void delete(Integer schedulerId) {
|
||||||
|
if (schedulerRepository.exists(schedulerId)) {
|
||||||
|
schedulerRepository.delete(schedulerId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void checkPlanToday() {
|
||||||
|
List<Scheduler> schedulerList = schedulerRepository.findAll();
|
||||||
|
if (!schedulerList.isEmpty()) {
|
||||||
|
doTodayPlanIfNeed(schedulerList);
|
||||||
|
schedulerList = schedulerRepository.findAll();
|
||||||
|
}
|
||||||
|
checkNewPlan(schedulerList);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNewPlan(List<Scheduler> schedulerList) {
|
||||||
|
Set<Tag> tags = taskService.checkRepeatingTags(true);
|
||||||
|
Set<Tag> newTags = null;
|
||||||
|
if (!schedulerList.isEmpty()) {
|
||||||
|
newTags = checkNewTags(tags, schedulerList);
|
||||||
|
} else {
|
||||||
|
if (!tags.isEmpty()) {
|
||||||
|
newTags = tags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newTags != null) {
|
||||||
|
newTags.forEach(tag -> {
|
||||||
|
if (!hasNewTag(tag, schedulerList)) {
|
||||||
|
save(tag);
|
||||||
|
Task task = taskService.findTasksByTag(tag).get(0);
|
||||||
|
schedulerList.add(new Scheduler(task, task.getDeadlines().get(task.getDeadlines().size() - 1).getDate()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean hasNewTag(Tag tag, List<Scheduler> schedulerList) {
|
||||||
|
|
||||||
|
return schedulerList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(scheduler -> scheduler.getTask().getTags().contains(tag));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Set<Tag> checkNewTags(Set<Tag> tags, List<Scheduler> schedulerList) {
|
||||||
|
Set<Tag> newTags = tags
|
||||||
|
.stream()
|
||||||
|
.filter(tag -> schedulerList
|
||||||
|
.stream()
|
||||||
|
.anyMatch(scheduler ->
|
||||||
|
!scheduler.getTask().getTags().contains(tag)))
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
if (!newTags.isEmpty()) {
|
||||||
|
return newTags;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTodayPlanIfNeed(List<Scheduler> schedulerList) {
|
||||||
|
List<Scheduler> plan = schedulerList
|
||||||
|
.stream()
|
||||||
|
.filter(scheduler -> scheduler.getDate().before(new Date()))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
doToday(plan);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doToday(List<Scheduler> plan) {
|
||||||
|
plan.forEach(scheduler -> {
|
||||||
|
taskService.createPeriodTask(scheduler);
|
||||||
|
delete(scheduler.getId());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package ru.ulstu.students.service;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.scheduling.annotation.Scheduled;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class TaskGenerationService {
|
||||||
|
|
||||||
|
private final Logger log = LoggerFactory.getLogger(TaskGenerationService.class);
|
||||||
|
private final TaskService taskService;
|
||||||
|
private final SchedulerService schedulerService;
|
||||||
|
|
||||||
|
public TaskGenerationService(TaskService taskService, SchedulerService schedulerService) {
|
||||||
|
|
||||||
|
this.taskService = taskService;
|
||||||
|
this.schedulerService = schedulerService;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Scheduled(cron = "0 0 0 * * ?", zone = "Europe/Samara")
|
||||||
|
public void generateTasks() {
|
||||||
|
log.debug("SchedulerService.checkPlanToday started");
|
||||||
|
schedulerService.checkPlanToday();
|
||||||
|
log.debug("SchedulerService.checkPlanToday finished");
|
||||||
|
|
||||||
|
log.debug("TaskService.generateYearTasks started");
|
||||||
|
taskService.generateYearTasks();
|
||||||
|
log.debug("TaskService.generateYearTasks finished");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
<?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="nastya" id="20190505_000001-1">
|
||||||
|
<createTable tableName="scheduler">
|
||||||
|
<column name="id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="task_id" type="integer">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="date" type="timestamp">
|
||||||
|
<constraints nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="version" type="integer"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey columnNames="id" constraintName="pk_scheduler" tableName="scheduler"/>
|
||||||
|
<addForeignKeyConstraint baseTableName="scheduler" baseColumnNames="task_id"
|
||||||
|
constraintName="fk_scheduler_task_id" referencedTableName="task"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?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="tanya" id="20190507_000000-1">
|
||||||
|
<dropColumn columnName="deadline_date" tableName="grants"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,14 @@
|
|||||||
|
<?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="tanya" id="20190507_000001-1">
|
||||||
|
<sql>
|
||||||
|
update grants
|
||||||
|
set leader_id =
|
||||||
|
(select u.id
|
||||||
|
from users u
|
||||||
|
where u.last_name = 'Романов' AND u.first_name = 'Антон');
|
||||||
|
</sql>
|
||||||
|
</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="nastya" id="20190511_000000-1">
|
||||||
|
<addColumn tableName="event">
|
||||||
|
<column name="task_id" type="integer"></column>
|
||||||
|
</addColumn>
|
||||||
|
<addForeignKeyConstraint baseTableName="event" baseColumnNames="task_id"
|
||||||
|
constraintName="fk_event_task_id" referencedTableName="task"
|
||||||
|
referencedColumnNames="id"/>
|
||||||
|
</changeSet>
|
||||||
|
</databaseChangeLog>
|
@ -0,0 +1,230 @@
|
|||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import conference.ConferencePage;
|
||||||
|
import conference.ConferencesDashboardPage;
|
||||||
|
import conference.ConferencesPage;
|
||||||
|
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.openqa.selenium.By;
|
||||||
|
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 IndexConferenceTest extends TestTemplate {
|
||||||
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
|
new ConferencesPage(), Arrays.asList("КОНФЕРЕНЦИИ", "/conferences/conferences"),
|
||||||
|
new ConferencePage(), Arrays.asList("РЕДАКТИРОВАНИЕ КОНФЕРЕНЦИИ", "/conferences/conference?id=0"),
|
||||||
|
new ConferencesDashboardPage(), Arrays.asList("АКТУАЛЬНЫЕ КОНФЕРЕНЦИИ", "/conferences/dashboard")
|
||||||
|
);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ApplicationProperties applicationProperties;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testACreateNewConference() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 1);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(page.getKey());
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey());
|
||||||
|
|
||||||
|
String newConferenceName = "test " + (new Date()).getTime();
|
||||||
|
conferencePage.setName(newConferenceName);
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBChangeConferenceNameAndSave() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String newConferenceName = "test " + (new Date()).getTime();
|
||||||
|
conferencePage.clearName();
|
||||||
|
conferencePage.setName(newConferenceName);
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCAddDeadlineAndSave() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer deadlineCount = conferencePage.getDeadlineCount();
|
||||||
|
|
||||||
|
String description = "test";
|
||||||
|
String date = "09.09.2019";
|
||||||
|
String dateValue = "2019-09-09";
|
||||||
|
conferencePage.clickAddDeadlineBut();
|
||||||
|
conferencePage.setDeadlineDescription(description, deadlineCount);
|
||||||
|
conferencePage.setDeadlineDate(date, deadlineCount);
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertTrue(conferencePage.checkDeadline(description, dateValue));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDTakePartAndSave() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer membersCount = conferencePage.getMemberCount();
|
||||||
|
|
||||||
|
conferencePage.clickTakePartBut();
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount()
|
||||||
|
&& conferencePage.isTakePartButDisabledValueTrue());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testEDeleteDeadlineAndSave() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer deadlineCount = conferencePage.getDeadlineCount();
|
||||||
|
|
||||||
|
conferencePage.clickDeleteDeadlineBut();
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertEquals(deadlineCount - 1, (int) conferencePage.getDeadlineCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFAttachArticle() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer paperCount = conferencePage.getArticlesCount();
|
||||||
|
|
||||||
|
conferencePage.showAllowToAttachArticles();
|
||||||
|
WebElement paper = conferencePage.selectArticle();
|
||||||
|
String paperName = paper.findElement(By.className("text")).getText();
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount()
|
||||||
|
&& conferencePage.checkArticle(paperName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGAddArticle() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer paperCount = conferencePage.getArticlesCount();
|
||||||
|
|
||||||
|
conferencePage.clickAddPaperBut();
|
||||||
|
List<WebElement> webElements = conferencePage.getArticles();
|
||||||
|
String paperName = webElements.get(webElements.size() - 1).findElements(By.tagName("input")).get(1).getAttribute("value");
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount()
|
||||||
|
&& conferencePage.checkArticle(paperName));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testHUndockArticle() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey());
|
||||||
|
|
||||||
|
conferencesPage.getFirstConference();
|
||||||
|
String conferenceId = conferencePage.getId();
|
||||||
|
Integer paperCount = conferencePage.getArticlesCount();
|
||||||
|
|
||||||
|
conferencePage.clickUndockArticleBut();
|
||||||
|
conferencePage.clickSaveBut();
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId));
|
||||||
|
|
||||||
|
Assert.assertEquals(paperCount - 1, (int) conferencePage.getArticlesCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testISortAndFilterConferenceList() {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
conferencesPage.selectMember();
|
||||||
|
conferencesPage.selectYear();
|
||||||
|
|
||||||
|
Assert.assertEquals(1, conferencesPage.getConferencesList().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testJDeleteConf() throws InterruptedException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
|
||||||
|
getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1));
|
||||||
|
ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey());
|
||||||
|
|
||||||
|
Integer size = conferencesPage.getConferencesList().size();
|
||||||
|
conferencesPage.deleteFirst();
|
||||||
|
Thread.sleep(3000);
|
||||||
|
conferencesPage.clickConfirm();
|
||||||
|
|
||||||
|
Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,116 @@
|
|||||||
|
package conference;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ConferencePage 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 clickSaveBut() {
|
||||||
|
driver.findElement(By.id("send-message-button")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clickAddDeadlineBut() {
|
||||||
|
driver.findElement(By.id("addDeadline")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getDeadlineList() {
|
||||||
|
return driver.findElements(By.className("deadline"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Integer getDeadlineCount() {
|
||||||
|
return driver.findElements(By.className("deadline")).size();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 void clickTakePartBut() {
|
||||||
|
driver.findElement(By.id("take-part")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 clickDeleteDeadlineBut() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).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=\"conference-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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkArticle(String paperName) {
|
||||||
|
return getArticles()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(webElement -> webElement
|
||||||
|
.findElements(By.tagName("input"))
|
||||||
|
.get(1).getAttribute("value")
|
||||||
|
.equals(paperName));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
package conference;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
|
||||||
|
public class ConferencesDashboardPage extends PageObject {
|
||||||
|
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h2")).getText();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package conference;
|
||||||
|
|
||||||
|
import core.PageObject;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class ConferencesPage extends PageObject {
|
||||||
|
|
||||||
|
public String getSubTitle() {
|
||||||
|
return driver.findElement(By.tagName("h3")).getText();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getConferencesList() {
|
||||||
|
return driver.findElements(By.cssSelector("span.h6.float-left.m-2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getFirstConference() {
|
||||||
|
driver.findElement(By.xpath("//*[@id=\"conferences\"]/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 selectYear() {
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(1).findElement(By.className("btn")).click();
|
||||||
|
driver.findElements(By.className("bootstrap-select")).get(1).findElements(By.className("dropdown-item")).get(1).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteFirst() {
|
||||||
|
js.executeScript("$('input[data-confirm]').click();");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clickConfirm() {
|
||||||
|
driver.findElement(By.id("deleteConference")).click();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean checkNameInList(String newConferenceName) {
|
||||||
|
return getConferencesList()
|
||||||
|
.stream()
|
||||||
|
.anyMatch(webElement -> webElement.getText().equals(newConferenceName));
|
||||||
|
}
|
||||||
|
}
|
@ -1,14 +1,17 @@
|
|||||||
package core;
|
package core;
|
||||||
|
|
||||||
|
import org.openqa.selenium.JavascriptExecutor;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
public abstract class PageObject {
|
public abstract class PageObject {
|
||||||
protected WebDriver driver;
|
protected WebDriver driver;
|
||||||
|
protected JavascriptExecutor js;
|
||||||
|
|
||||||
public abstract String getSubTitle();
|
public abstract String getSubTitle();
|
||||||
|
|
||||||
public PageObject setDriver(WebDriver driver) {
|
public PageObject setDriver(WebDriver driver) {
|
||||||
this.driver = driver;
|
this.driver = driver;
|
||||||
|
js = (JavascriptExecutor) driver;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue