From b57142e28fc423b5779372e28107e536f03db963 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Wed, 8 May 2019 17:08:37 +0400 Subject: [PATCH 01/25] #70 added unique name control --- .../controller/ConferenceController.java | 1 + .../ulstu/conference/model/ConferenceDto.java | 3 ++- .../repository/ConferenceRepository.java | 7 +++++- .../conference/service/ConferenceService.java | 12 ++++++++-- .../java/ru/ulstu/name/NameContainer.java | 24 +++++++++++++++++++ .../java/ru/ulstu/name/NameRepository.java | 7 ++++++ src/main/java/ru/ulstu/name/NameService.java | 11 +++++++++ 7 files changed, 61 insertions(+), 4 deletions(-) create mode 100644 src/main/java/ru/ulstu/name/NameContainer.java create mode 100644 src/main/java/ru/ulstu/name/NameRepository.java create mode 100644 src/main/java/ru/ulstu/name/NameService.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 5aecb51..4e11d32 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -76,6 +76,7 @@ public class ConferenceController { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { conferenceService.filterEmptyDeadlines(conferenceDto); conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); + conferenceService.checkUniqueName(conferenceDto, errors); if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java index 2e2f13b..9c9b37a 100644 --- a/src/main/java/ru/ulstu/conference/model/ConferenceDto.java +++ b/src/main/java/ru/ulstu/conference/model/ConferenceDto.java @@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import ru.ulstu.deadline.model.Deadline; +import ru.ulstu.name.NameContainer; import ru.ulstu.paper.model.Paper; import javax.persistence.Temporal; @@ -16,7 +17,7 @@ import java.util.List; import static ru.ulstu.core.util.StreamApiUtils.convert; -public class ConferenceDto { +public class ConferenceDto extends NameContainer { private final static String BEGIN_DATE = "Начало: "; private final static String END_DATE = "Конец: "; diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 3a8bbe1..5dfe7dd 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -5,12 +5,13 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; +import ru.ulstu.name.NameRepository; import ru.ulstu.user.model.User; import java.util.Date; import java.util.List; -public interface ConferenceRepository extends JpaRepository { +public interface ConferenceRepository extends JpaRepository, NameRepository { @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); @@ -24,4 +25,8 @@ public interface ConferenceRepository extends JpaRepository @Modifying @Query("UPDATE Conference c SET c.ping = (c.ping + 1) WHERE c.id = :id") int updatePingConference(@Param("id") Integer id); + + @Override + @Query("SELECT title FROM Conference c WHERE c.title = :name") + String findByName(@Param("name") String name); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..9a10efb 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,6 +13,7 @@ import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; +import ru.ulstu.name.NameService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; @@ -31,7 +32,7 @@ import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service -public class ConferenceService { +public class ConferenceService extends NameService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; @@ -280,10 +281,17 @@ public class ConferenceService { } } - public void filterEmptyDeadlines(ConferenceDto conferenceDto) { conferenceDto.setDeadlines(conferenceDto.getDeadlines().stream() .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); } + + public void checkUniqueName(ConferenceDto conferenceDto, Errors errors) { + conferenceDto.setName(conferenceDto.getTitle()); + conferenceDto.setNameRepository(conferenceRepository); + if (checkUniqueName(conferenceDto)) { + errors.rejectValue("title", "errorCode", "Конференция с таким именем уже существует"); + } + } } diff --git a/src/main/java/ru/ulstu/name/NameContainer.java b/src/main/java/ru/ulstu/name/NameContainer.java new file mode 100644 index 0000000..bcccc80 --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameContainer.java @@ -0,0 +1,24 @@ +package ru.ulstu.name; + +public abstract class NameContainer { + + private String name = ""; + + private NameRepository nameRepository; + + public NameRepository getNameRepository() { + return nameRepository; + } + + public void setNameRepository(NameRepository nameRepository) { + this.nameRepository = nameRepository; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } +} diff --git a/src/main/java/ru/ulstu/name/NameRepository.java b/src/main/java/ru/ulstu/name/NameRepository.java new file mode 100644 index 0000000..99bd3ac --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameRepository.java @@ -0,0 +1,7 @@ +package ru.ulstu.name; + +import org.springframework.data.repository.query.Param; + +public interface NameRepository { + String findByName(@Param("name") String name); +} diff --git a/src/main/java/ru/ulstu/name/NameService.java b/src/main/java/ru/ulstu/name/NameService.java new file mode 100644 index 0000000..7d7bdc9 --- /dev/null +++ b/src/main/java/ru/ulstu/name/NameService.java @@ -0,0 +1,11 @@ +package ru.ulstu.name; + +import org.springframework.stereotype.Service; + +@Service +public abstract class NameService { + + public boolean checkUniqueName(NameContainer nameContainer) { + return nameContainer.getName().equals(nameContainer.getNameRepository().findByName(nameContainer.getName())); + } +} From 961fdf939759265df386f113444593d9586b4b61 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 15:07:47 +0400 Subject: [PATCH 02/25] #70 added conference class, added create method test --- src/test/java/IndexConferenceTest.java | 59 +++++++++++++++++++ src/test/java/conference/ConferencePage.java | 19 ++++++ .../conference/ConferencesDashboardPage.java | 11 ++++ src/test/java/conference/ConferencesPage.java | 19 ++++++ 4 files changed, 108 insertions(+) create mode 100644 src/test/java/IndexConferenceTest.java create mode 100644 src/test/java/conference/ConferencePage.java create mode 100644 src/test/java/conference/ConferencesDashboardPage.java create mode 100644 src/test/java/conference/ConferencesPage.java diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java new file mode 100644 index 0000000..9adf2f5 --- /dev/null +++ b/src/test/java/IndexConferenceTest.java @@ -0,0 +1,59 @@ +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.assertj.core.api.Assertions; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +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) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class IndexConferenceTest extends TestTemplate { + private final Map> 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 testStartApplication() { + getContext().goTo(applicationProperties.getBaseUrl()); + Assertions + .assertThat(getContext().getTitle()) + .isEqualTo("NG-Tracker"); + } + + @Test + public void testCreateNewConference() { + Map.Entry> 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.getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + } +} diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java new file mode 100644 index 0000000..5f57008 --- /dev/null +++ b/src/test/java/conference/ConferencePage.java @@ -0,0 +1,19 @@ +package conference; + +import core.PageObject; +import org.openqa.selenium.By; + +public class ConferencePage extends PageObject { + + public String getSubTitle() { + return driver.findElement(By.tagName("h3")).getText(); + } + + public void setName(String name) { + driver.findElement(By.id("title")).sendKeys(name); + } + + public void clickSaveBut() { + driver.findElement(By.id("send-message-button")).click(); + } +} diff --git a/src/test/java/conference/ConferencesDashboardPage.java b/src/test/java/conference/ConferencesDashboardPage.java new file mode 100644 index 0000000..d358c4a --- /dev/null +++ b/src/test/java/conference/ConferencesDashboardPage.java @@ -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(); + } +} diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java new file mode 100644 index 0000000..0dc899d --- /dev/null +++ b/src/test/java/conference/ConferencesPage.java @@ -0,0 +1,19 @@ +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 getConferencesList() { + return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); + + } +} \ No newline at end of file From 1ad66d6fb17bcf14d12fc8ca7fa9218419ad1665 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 15:54:12 +0400 Subject: [PATCH 03/25] #103 change name method test --- src/test/java/IndexConferenceTest.java | 21 +++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 ++++ src/test/java/conference/ConferencesPage.java | 3 +++ 3 files changed, 28 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 9adf2f5..b3a4118 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -56,4 +56,25 @@ public class IndexConferenceTest extends TestTemplate { .stream() .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); } + + @Test + public void testChangeConferenceNameAndSave() { + Map.Entry> 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.getConferenceFirst(); + String newConferenceName = "test " + (new Date()).getTime(); + conferencePage.clearName(); + conferencePage.setName(newConferenceName); + conferencePage.clickSaveBut(); + + Assert.assertTrue(conferencesPage.getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + } + + } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 5f57008..48362e0 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -13,6 +13,10 @@ public class ConferencePage extends PageObject { driver.findElement(By.id("title")).sendKeys(name); } + public void clearName() { + driver.findElement(By.id("title")).clear(); + } + public void clickSaveBut() { driver.findElement(By.id("send-message-button")).click(); } diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 0dc899d..b258420 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -14,6 +14,9 @@ public class ConferencesPage extends PageObject { public List getConferencesList() { return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); + } + public void getConferenceFirst() { + driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } } \ No newline at end of file From 253f4b4aad96dad266fb62fb1180bea11055e5dd Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:03:47 +0400 Subject: [PATCH 04/25] #103 add check new deadline --- src/test/java/IndexConferenceTest.java | 29 +++++++++++++++++ src/test/java/conference/ConferencePage.java | 33 +++++++++++++++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3a4118..7f8ee57 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -9,6 +9,7 @@ import org.assertj.core.api.Assertions; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.openqa.selenium.By; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; @@ -76,5 +77,33 @@ public class IndexConferenceTest extends TestTemplate { .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); } + @Test + public void testAddDeadlineAndSave() { + Map.Entry> 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.getConferenceFirst(); + 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.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); + })); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 48362e0..00d9585 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -2,6 +2,9 @@ package conference; import core.PageObject; import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; public class ConferencePage extends PageObject { @@ -9,10 +12,18 @@ public class ConferencePage extends PageObject { 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(); } @@ -20,4 +31,24 @@ public class ConferencePage extends PageObject { public void clickSaveBut() { driver.findElement(By.id("send-message-button")).click(); } -} + + public void clickAddDeadlineBut() { + driver.findElement(By.id("addDeadline")).click(); + } + + public List 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); + } +} \ No newline at end of file From 0cb7b05c2556f64b277c1d6903229ea0f38e72be Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:21:36 +0400 Subject: [PATCH 05/25] #103 add check take part --- src/test/java/IndexConferenceTest.java | 21 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 12 +++++++++++ 2 files changed, 33 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7f8ee57..4fb72d4 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -106,4 +106,25 @@ public class IndexConferenceTest extends TestTemplate { && webElement.findElement(By.cssSelector("input[type=\"date\"]")).getAttribute("value").equals(dateValue); })); } + + @Test + public void testTakePartAndSave() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer membersCount = conferencePage.getMemperCount(); + + conferencePage.clickTakePartBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() + && conferencePage.getTakePartButDisabledValue().equals("true")); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 00d9585..9a448eb 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -51,4 +51,16 @@ public class ConferencePage extends PageObject { 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 String getTakePartButDisabledValue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled"); + } + + public Integer getMemperCount() { + return driver.findElements(By.className("member")).size(); + } } \ No newline at end of file From 7b4318a3b528c93b0be5cbdcbc19cb4019485221 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 17:40:24 +0400 Subject: [PATCH 06/25] #103 add delete deadline --- src/test/java/IndexConferenceTest.java | 20 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 ++++ 2 files changed, 24 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 4fb72d4..8408029 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -127,4 +127,24 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() && conferencePage.getTakePartButDisabledValue().equals("true")); } + + @Test + public void testDeleteDeadlineAndSave() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer deadlineCount = conferencePage.getDeadlineCount(); + + conferencePage.clickDeleteDeadlineBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 9a448eb..d51e7b9 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -63,4 +63,8 @@ public class ConferencePage extends PageObject { public Integer getMemperCount() { return driver.findElements(By.className("member")).size(); } + + public void clickDeleteDeadlineBut() { + driver.findElement(By.xpath("//*[@id=\"deadlines\"]/div/input[4]")).click(); + } } \ No newline at end of file From d9a4224317c2ef5c5dae969003c6342a530d4500 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 19:15:22 +0400 Subject: [PATCH 07/25] #103 add attach article --- src/test/java/IndexConferenceTest.java | 33 ++++++++++++++++++-- src/test/java/conference/ConferencePage.java | 20 +++++++++++- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 8408029..4c40d7d 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -10,6 +10,7 @@ import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; 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; @@ -117,14 +118,14 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer membersCount = conferencePage.getMemperCount(); + Integer membersCount = conferencePage.getMemberCount(); conferencePage.clickTakePartBut(); conferencePage.clickSaveBut(); getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(membersCount + 1 == conferencePage.getMemperCount() + Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() && conferencePage.getTakePartButDisabledValue().equals("true")); } @@ -147,4 +148,32 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); } + + @Test + public void testAttachArticle() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getPaperCount(); + + conferencePage.showAllowToAttachArticles(); + WebElement paper = conferencePage.selectPaper(); + 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.getPaperCount() + && conferencePage.getPapers() + .stream() + .anyMatch(webElement -> webElement + .findElement(By.className("paper-name")) + .findElements(By.tagName("span")) + .get(1).getText().equals(paperName))); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index d51e7b9..02fa0fc 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -60,11 +60,29 @@ public class ConferencePage extends PageObject { return driver.findElement(By.id("take-part")).getAttribute("disabled"); } - public Integer getMemperCount() { + 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 List getPapers() { + return driver.findElements(By.className("paper")); + } + + public Integer getPaperCount() { + return driver.findElements(By.className("paper")).size(); + } + + public WebElement selectPaper() { + 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; + } } \ No newline at end of file From cad8682088abff0a54035edbcd0baaa2c5fe26b1 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 20:07:55 +0400 Subject: [PATCH 08/25] #103 add adding article --- src/main/resources/public/css/conference.css | 6 +++++ src/test/java/IndexConferenceTest.java | 28 ++++++++++++++++++++ src/test/java/conference/ConferencePage.java | 4 +++ 3 files changed, 38 insertions(+) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 73a96ae..26ac40e 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -140,6 +140,7 @@ body { .paper-name { flex: 1; + overflow: hidden; } .paper-name:hover { @@ -156,6 +157,11 @@ body { float: left; } +.paper-name span:nth-child(2) { + max-width: 326px; + white-space: nowrap; +} + .icon { diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 4c40d7d..a2e0124 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -176,4 +176,32 @@ public class IndexConferenceTest extends TestTemplate { .findElements(By.tagName("span")) .get(1).getText().equals(paperName))); } + + @Test + public void testAddArticle() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getPaperCount(); + + conferencePage.clickAddPaperBut(); + List webElements = conferencePage.getPapers(); + String paperName = webElements.get(webElements.size() - 1).findElement(By.tagName("a")).findElements(By.tagName("span")).get(1).getText(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount + 1 == conferencePage.getPaperCount() + && conferencePage.getPapers() + .stream() + .anyMatch(webElement -> webElement + .findElement(By.tagName("a")) + .findElements(By.tagName("span")) + .get(1).getText().equals(paperName))); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 02fa0fc..1a4a1df 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -85,4 +85,8 @@ public class ConferencePage extends PageObject { webElement.click(); return webElement; } + + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } } \ No newline at end of file From 4e4e7ae1948ac8ccfe1c4c612358c6399f887b30 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 20:54:43 +0400 Subject: [PATCH 09/25] #103 add paper transition --- src/main/resources/public/css/conference.css | 4 +++ src/test/java/IndexConferenceTest.java | 26 +++++++++++++++++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/main/resources/public/css/conference.css b/src/main/resources/public/css/conference.css index 26ac40e..dc83057 100644 --- a/src/main/resources/public/css/conference.css +++ b/src/main/resources/public/css/conference.css @@ -162,6 +162,10 @@ body { white-space: nowrap; } +.dropdown-menu { + max-width: 445px; +} + .icon { diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index a2e0124..b3314ff 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -191,7 +191,7 @@ public class IndexConferenceTest extends TestTemplate { conferencePage.clickAddPaperBut(); List webElements = conferencePage.getPapers(); - String paperName = webElements.get(webElements.size() - 1).findElement(By.tagName("a")).findElements(By.tagName("span")).get(1).getText(); + 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)); @@ -200,8 +200,26 @@ public class IndexConferenceTest extends TestTemplate { && conferencePage.getPapers() .stream() .anyMatch(webElement -> webElement - .findElement(By.tagName("a")) - .findElements(By.tagName("span")) - .get(1).getText().equals(paperName))); + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName))); + } + + @Test + public void testTransitionToTheArticle() { + Map.Entry> 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.getConferenceFirst(); + + WebElement paper = conferencePage.getPapers().get(0); + String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); + paper.findElement(By.tagName("a")).click(); + + Assertions.assertThat(conferencePage.getName()) + .isEqualTo(paperName); } } From 46864069543d5c6f69572b68ab91c8e209069b1c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 21:15:49 +0400 Subject: [PATCH 10/25] #103 add undock article --- src/test/java/IndexConferenceTest.java | 38 ++++++++++++++++++++------ 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3314ff..84e51a2 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -159,17 +159,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectPaper(); + 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.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElement(By.className("paper-name")) @@ -187,17 +187,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getPapers(); + List 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.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElements(By.tagName("input")) @@ -215,11 +215,31 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); - WebElement paper = conferencePage.getPapers().get(0); + WebElement paper = conferencePage.getArticles().get(0); String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); paper.findElement(By.tagName("a")).click(); Assertions.assertThat(conferencePage.getName()) .isEqualTo(paperName); } + + @Test + public void testUndockArticle() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + } } From 6edcf8f5940fa3b3c0a0179d6910189412b8d230 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Fri, 10 May 2019 21:15:49 +0400 Subject: [PATCH 11/25] #103 add sort and filter test, fixed delete conference, if it has fk with event --- .../conference/service/ConferenceService.java | 1 + .../ulstu/timeline/service/EventService.java | 5 ++ src/test/java/IndexConferenceTest.java | 57 +++++++++++++++---- src/test/java/conference/ConferencePage.java | 15 +++-- src/test/java/conference/ConferencesPage.java | 10 ++++ 5 files changed, 71 insertions(+), 17 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 38de435..e0662a2 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -127,6 +127,7 @@ public class ConferenceService { @Transactional public void delete(Integer conferenceId) { if (conferenceRepository.exists(conferenceId)) { + eventService.removeConferencesEvent(conferenceRepository.findOne(conferenceId)); conferenceRepository.delete(conferenceId); } } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..cd56a52 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -203,4 +203,9 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void removeConferencesEvent(Conference conference) { + List eventList = eventRepository.findAllByConference(conference); + eventList.forEach(event -> eventRepository.delete(event.getId())); + } } diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index b3314ff..47af27f 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -159,22 +159,22 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.showAllowToAttachArticles(); - WebElement paper = conferencePage.selectPaper(); + 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.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement - .findElement(By.className("paper-name")) - .findElements(By.tagName("span")) - .get(1).getText().equals(paperName))); + .findElements(By.tagName("input")) + .get(1).getAttribute("value") + .equals(paperName))); } @Test @@ -187,17 +187,17 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); String conferenceId = conferencePage.getId(); - Integer paperCount = conferencePage.getPaperCount(); + Integer paperCount = conferencePage.getArticlesCount(); conferencePage.clickAddPaperBut(); - List webElements = conferencePage.getPapers(); + List 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.getPaperCount() - && conferencePage.getPapers() + Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() + && conferencePage.getArticles() .stream() .anyMatch(webElement -> webElement .findElements(By.tagName("input")) @@ -215,11 +215,44 @@ public class IndexConferenceTest extends TestTemplate { conferencesPage.getConferenceFirst(); - WebElement paper = conferencePage.getPapers().get(0); + WebElement paper = conferencePage.getArticles().get(0); String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); paper.findElement(By.tagName("a")).click(); Assertions.assertThat(conferencePage.getName()) .isEqualTo(paperName); } + + @Test + public void testUndockArticle() { + Map.Entry> 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.getConferenceFirst(); + String conferenceId = conferencePage.getId(); + Integer paperCount = conferencePage.getArticlesCount(); + + conferencePage.clickUndockArticleBut(); + conferencePage.clickSaveBut(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); + + Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + } + + @Test + public void testSortAndFilterConferenceList() { + Map.Entry> 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()); + } } diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 1a4a1df..50e545e 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -72,21 +72,26 @@ public class ConferencePage extends PageObject { driver.findElement(By.cssSelector("button[data-id=\"paperIds\"]")).click(); } - public List getPapers() { + public void clickAddPaperBut() { + driver.findElement(By.id("add-paper")).click(); + } + + + public List getArticles() { return driver.findElements(By.className("paper")); } - public Integer getPaperCount() { + public Integer getArticlesCount() { return driver.findElements(By.className("paper")).size(); } - public WebElement selectPaper() { + 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 clickAddPaperBut() { - driver.findElement(By.id("add-paper")).click(); + public void clickUndockArticleBut() { + driver.findElement(By.name("removePaper")).click(); } } \ No newline at end of file diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index b258420..795ccf3 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -19,4 +19,14 @@ public class ConferencesPage extends PageObject { public void getConferenceFirst() { 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(); + } } \ No newline at end of file From b2e8a43ceec6f280324bea07c33d838cfd9c32ef Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sat, 11 May 2019 00:51:57 +0400 Subject: [PATCH 12/25] #103 delete conf test --- src/test/java/IndexConferenceTest.java | 15 +++++++++++++++ src/test/java/conference/ConferencesPage.java | 8 ++++++++ 2 files changed, 23 insertions(+) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 47af27f..64b144d 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -255,4 +255,19 @@ public class IndexConferenceTest extends TestTemplate { Assert.assertEquals(1, conferencesPage.getConferencesList().size()); } + + @Test + public void testDeleteConf() throws InterruptedException { + Map.Entry> 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(2000); + conferencesPage.clickConfirm(); + + Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); + } } diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 795ccf3..9cccf3f 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -29,4 +29,12 @@ public class ConferencesPage extends PageObject { 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() { + driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/input[2]")).submit(); + } + + public void clickConfirm() { + driver.findElement(By.xpath("//*[@id=\"deleteConference\"]")).click(); + } } \ No newline at end of file From d846192046aae130e1882f0e889845a664c4180c Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 00:28:03 +0400 Subject: [PATCH 13/25] #111 fixes --- .../controller/ConferenceController.java | 7 ++++++- .../repository/ConferenceRepository.java | 8 ++++---- .../conference/service/ConferenceService.java | 13 +++---------- src/main/java/ru/ulstu/name/BaseRepository.java | 7 +++++++ src/main/java/ru/ulstu/name/BaseService.java | 16 ++++++++++++++++ src/main/java/ru/ulstu/name/NameContainer.java | 10 ---------- src/main/java/ru/ulstu/name/NameRepository.java | 7 ------- src/main/java/ru/ulstu/name/NameService.java | 11 ----------- 8 files changed, 36 insertions(+), 43 deletions(-) create mode 100644 src/main/java/ru/ulstu/name/BaseRepository.java create mode 100644 src/main/java/ru/ulstu/name/BaseService.java delete mode 100644 src/main/java/ru/ulstu/name/NameRepository.java delete mode 100644 src/main/java/ru/ulstu/name/NameService.java diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 4e11d32..48a2ef2 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -76,7 +76,12 @@ public class ConferenceController { public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { conferenceService.filterEmptyDeadlines(conferenceDto); conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); - conferenceService.checkUniqueName(conferenceDto, errors); + conferenceDto.setName(conferenceDto.getTitle()); + conferenceService.checkUniqueName(conferenceDto, + errors, + conferenceDto.getId(), + "title", + "Конференция с таким именем уже существует"); if (errors.hasErrors()) { return CONFERENCE_PAGE; } diff --git a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java index 5dfe7dd..2b0a428 100644 --- a/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java +++ b/src/main/java/ru/ulstu/conference/repository/ConferenceRepository.java @@ -5,13 +5,13 @@ import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import ru.ulstu.conference.model.Conference; -import ru.ulstu.name.NameRepository; +import ru.ulstu.name.BaseRepository; import ru.ulstu.user.model.User; import java.util.Date; import java.util.List; -public interface ConferenceRepository extends JpaRepository, NameRepository { +public interface ConferenceRepository extends JpaRepository, BaseRepository { @Query("SELECT c FROM Conference c LEFT JOIN c.users u WHERE (:user IS NULL OR u.user = :user) " + "AND (YEAR(c.beginDate) = :year OR :year IS NULL) ORDER BY begin_date DESC") List findByUserAndYear(@Param("user") User user, @Param("year") Integer year); @@ -27,6 +27,6 @@ public interface ConferenceRepository extends JpaRepository int updatePingConference(@Param("id") Integer id); @Override - @Query("SELECT title FROM Conference c WHERE c.title = :name") - String findByName(@Param("name") String name); + @Query("SELECT title FROM Conference c WHERE (c.title = :name) AND (:id IS NULL OR c.id != :id) ") + String findByNameAndNotId(@Param("name") String name, @Param("id") Integer id); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 9a10efb..8ffeb6f 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -13,7 +13,7 @@ import ru.ulstu.conference.model.ConferenceUser; import ru.ulstu.conference.repository.ConferenceRepository; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.name.NameService; +import ru.ulstu.name.BaseService; import ru.ulstu.paper.model.Paper; import ru.ulstu.paper.service.PaperService; import ru.ulstu.ping.service.PingService; @@ -32,7 +32,7 @@ import static org.springframework.util.ObjectUtils.isEmpty; import static ru.ulstu.core.util.StreamApiUtils.convert; @Service -public class ConferenceService extends NameService { +public class ConferenceService extends BaseService { private final static int MAX_DISPLAY_SIZE = 40; private final ConferenceRepository conferenceRepository; @@ -52,6 +52,7 @@ public class ConferenceService extends NameService { PingService pingService, ConferenceNotificationService conferenceNotificationService, EventService eventService) { + this.baseRepository = conferenceRepository; this.conferenceRepository = conferenceRepository; this.conferenceUserService = conferenceUserService; this.deadlineService = deadlineService; @@ -286,12 +287,4 @@ public class ConferenceService extends NameService { .filter(dto -> dto.getDate() != null || !org.springframework.util.StringUtils.isEmpty(dto.getDescription())) .collect(Collectors.toList())); } - - public void checkUniqueName(ConferenceDto conferenceDto, Errors errors) { - conferenceDto.setName(conferenceDto.getTitle()); - conferenceDto.setNameRepository(conferenceRepository); - if (checkUniqueName(conferenceDto)) { - errors.rejectValue("title", "errorCode", "Конференция с таким именем уже существует"); - } - } } diff --git a/src/main/java/ru/ulstu/name/BaseRepository.java b/src/main/java/ru/ulstu/name/BaseRepository.java new file mode 100644 index 0000000..b691ea2 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseRepository.java @@ -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); +} diff --git a/src/main/java/ru/ulstu/name/BaseService.java b/src/main/java/ru/ulstu/name/BaseService.java new file mode 100644 index 0000000..6619385 --- /dev/null +++ b/src/main/java/ru/ulstu/name/BaseService.java @@ -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); + } + } +} diff --git a/src/main/java/ru/ulstu/name/NameContainer.java b/src/main/java/ru/ulstu/name/NameContainer.java index bcccc80..4339fb2 100644 --- a/src/main/java/ru/ulstu/name/NameContainer.java +++ b/src/main/java/ru/ulstu/name/NameContainer.java @@ -4,16 +4,6 @@ public abstract class NameContainer { private String name = ""; - private NameRepository nameRepository; - - public NameRepository getNameRepository() { - return nameRepository; - } - - public void setNameRepository(NameRepository nameRepository) { - this.nameRepository = nameRepository; - } - public String getName() { return name; } diff --git a/src/main/java/ru/ulstu/name/NameRepository.java b/src/main/java/ru/ulstu/name/NameRepository.java deleted file mode 100644 index 99bd3ac..0000000 --- a/src/main/java/ru/ulstu/name/NameRepository.java +++ /dev/null @@ -1,7 +0,0 @@ -package ru.ulstu.name; - -import org.springframework.data.repository.query.Param; - -public interface NameRepository { - String findByName(@Param("name") String name); -} diff --git a/src/main/java/ru/ulstu/name/NameService.java b/src/main/java/ru/ulstu/name/NameService.java deleted file mode 100644 index 7d7bdc9..0000000 --- a/src/main/java/ru/ulstu/name/NameService.java +++ /dev/null @@ -1,11 +0,0 @@ -package ru.ulstu.name; - -import org.springframework.stereotype.Service; - -@Service -public abstract class NameService { - - public boolean checkUniqueName(NameContainer nameContainer) { - return nameContainer.getName().equals(nameContainer.getNameRepository().findByName(nameContainer.getName())); - } -} From a11e10dec45a37fcda54be3778f7d185f1ea62b9 Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 12 May 2019 01:00:26 +0400 Subject: [PATCH 14/25] #123 adding task timeline --- .../java/ru/ulstu/students/model/Task.java | 2 ++ .../ulstu/students/service/TaskService.java | 7 ++++- .../java/ru/ulstu/timeline/model/Event.java | 13 ++++++++ .../ru/ulstu/timeline/model/EventDto.java | 17 ++++++++++- .../timeline/repository/EventRepository.java | 3 ++ .../ulstu/timeline/service/EventService.java | 30 +++++++++++++++++++ .../db/changelog-20190511_000000-schema.xml | 13 ++++++++ src/main/resources/db/changelog-master.xml | 1 + 8 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/db/changelog-20190511_000000-schema.xml diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 8ec9081..2a03e37 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -67,6 +67,7 @@ public class Task extends BaseEntity { private Date updateDate = new Date(); @ManyToMany(fetch = FetchType.EAGER) + @Fetch(FetchMode.SUBSELECT) @JoinTable(name = "task_tags", joinColumns = {@JoinColumn(name = "task_id")}, inverseJoinColumns = {@JoinColumn(name = "tag_id")}) @@ -127,4 +128,5 @@ public class Task extends BaseEntity { public void setTags(List tags) { this.tags = tags; } + } diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index a8747c7..8f335ac 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -11,6 +11,7 @@ import ru.ulstu.students.model.TaskFilterDto; import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; import ru.ulstu.tags.service.TagService; +import ru.ulstu.timeline.service.EventService; import java.io.IOException; import java.util.Arrays; @@ -29,12 +30,14 @@ public class TaskService { private final TaskRepository taskRepository; private final DeadlineService deadlineService; private final TagService tagService; + private final EventService eventService; public TaskService(TaskRepository taskRepository, - DeadlineService deadlineService, TagService tagService) { + DeadlineService deadlineService, TagService tagService, EventService eventService) { this.taskRepository = taskRepository; this.deadlineService = deadlineService; this.tagService = tagService; + this.eventService = eventService; } public List findAll() { @@ -67,6 +70,7 @@ public class TaskService { public Integer create(TaskDto taskDto) throws IOException { Task newTask = copyFromDto(new Task(), taskDto); newTask = taskRepository.save(newTask); + eventService.createFromTask(newTask); return newTask.getId(); } @@ -86,6 +90,7 @@ public class TaskService { public Integer update(TaskDto taskDto) throws IOException { Task task = taskRepository.findOne(taskDto.getId()); taskRepository.save(copyFromDto(task, taskDto)); + eventService.updateTaskDeadlines(task); return task.getId(); } diff --git a/src/main/java/ru/ulstu/timeline/model/Event.java b/src/main/java/ru/ulstu/timeline/model/Event.java index 9252cec..e56c91c 100644 --- a/src/main/java/ru/ulstu/timeline/model/Event.java +++ b/src/main/java/ru/ulstu/timeline/model/Event.java @@ -5,6 +5,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.user.model.User; import javax.persistence.CascadeType; @@ -87,6 +88,10 @@ public class Event extends BaseEntity { @JoinColumn(name = "grant_id") private Grant grant; + @ManyToOne + @JoinColumn(name = "task_id") + private Task task; + public String getTitle() { return title; } @@ -190,4 +195,12 @@ public class Event extends BaseEntity { public void setGrant(Grant grant) { this.grant = grant; } + + public Task getTask() { + return task; + } + + public void setTask(Task task) { + this.task = task; + } } diff --git a/src/main/java/ru/ulstu/timeline/model/EventDto.java b/src/main/java/ru/ulstu/timeline/model/EventDto.java index 89df5d8..ccf0f0a 100644 --- a/src/main/java/ru/ulstu/timeline/model/EventDto.java +++ b/src/main/java/ru/ulstu/timeline/model/EventDto.java @@ -6,6 +6,7 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.conference.model.ConferenceDto; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.paper.model.PaperDto; +import ru.ulstu.students.model.TaskDto; import ru.ulstu.user.model.UserDto; import javax.validation.constraints.NotNull; @@ -29,6 +30,7 @@ public class EventDto { private PaperDto paperDto; private ConferenceDto conferenceDto; private GrantDto grantDto; + private TaskDto taskDto; @JsonCreator public EventDto(@JsonProperty("id") Integer id, @@ -42,7 +44,8 @@ public class EventDto { @JsonProperty("paperDto") PaperDto paperDto, @JsonProperty("recipients") List recipients, @JsonProperty("conferenceDto") ConferenceDto conferenceDto, - @JsonProperty("grantDto") GrantDto grantDto) { + @JsonProperty("grantDto") GrantDto grantDto, + @JsonProperty("taskDto") TaskDto taskDto) { this.id = id; this.title = title; this.period = period; @@ -55,6 +58,7 @@ public class EventDto { this.paperDto = paperDto; this.conferenceDto = conferenceDto; this.grantDto = grantDto; + this.taskDto = taskDto; } public EventDto(Event event) { @@ -76,6 +80,9 @@ public class EventDto { if (grantDto != null) { this.grantDto = new GrantDto(event.getGrant()); } + if (taskDto != null) { + this.taskDto = new TaskDto(event.getTask()); + } } public Integer getId() { @@ -137,4 +144,12 @@ public class EventDto { public void setGrantDto(GrantDto grantDto) { this.grantDto = grantDto; } + + public TaskDto getTaskDto() { + return taskDto; + } + + public void setTaskDto(TaskDto taskDto) { + this.taskDto = taskDto; + } } diff --git a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java index e01037a..7ebd3c9 100644 --- a/src/main/java/ru/ulstu/timeline/repository/EventRepository.java +++ b/src/main/java/ru/ulstu/timeline/repository/EventRepository.java @@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.Query; import ru.ulstu.conference.model.Conference; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import java.util.List; @@ -21,4 +22,6 @@ public interface EventRepository extends JpaRepository { List findAllByConference(Conference conference); List findAllByGrant(Grant grant); + + List findAllByTask(Task task); } diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index b935f16..9a2671c 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -8,6 +8,7 @@ import ru.ulstu.conference.model.Conference; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.paper.model.Paper; +import ru.ulstu.students.model.Task; import ru.ulstu.timeline.model.Event; import ru.ulstu.timeline.model.EventDto; import ru.ulstu.timeline.model.Timeline; @@ -203,4 +204,33 @@ public class EventService { eventRepository.delete(eventRepository.findAllByGrant(grant)); createFromGrant(grant); } + + public void createFromTask(Task newTask) { + List timelines = timelineService.findAll(); + Timeline timeline = timelines.isEmpty() ? new Timeline() : timelines.get(0); + + for (Deadline deadline : newTask.getDeadlines() + .stream() + .filter(d -> d.getDate().after(new Date()) || DateUtils.isSameDay(d.getDate(), new Date())) + .collect(Collectors.toList())) { + Event newEvent = new Event(); + newEvent.setTitle("Дедлайн задачи"); + newEvent.setStatus(Event.EventStatus.NEW); + newEvent.setExecuteDate(deadline.getDate()); + newEvent.setCreateDate(new Date()); + newEvent.setUpdateDate(new Date()); + newEvent.setDescription("Дедлайн '" + deadline.getDescription() + "' задачи '" + newTask.getTitle() + "'"); + newEvent.getRecipients().add(userService.getCurrentUser()); + newEvent.setTask(newTask); + eventRepository.save(newEvent); + + timeline.getEvents().add(newEvent); + timelineService.save(timeline); + } + } + + public void updateTaskDeadlines(Task task) { + eventRepository.delete(eventRepository.findAllByTask(task)); + createFromTask(task); + } } diff --git a/src/main/resources/db/changelog-20190511_000000-schema.xml b/src/main/resources/db/changelog-20190511_000000-schema.xml new file mode 100644 index 0000000..62e914f --- /dev/null +++ b/src/main/resources/db/changelog-20190511_000000-schema.xml @@ -0,0 +1,13 @@ + + + + + + + + + diff --git a/src/main/resources/db/changelog-master.xml b/src/main/resources/db/changelog-master.xml index 0dc15e5..98e3c17 100644 --- a/src/main/resources/db/changelog-master.xml +++ b/src/main/resources/db/changelog-master.xml @@ -40,4 +40,5 @@ + \ No newline at end of file From 5b4180e68525337b2876a68ce8cf5b461316cb30 Mon Sep 17 00:00:00 2001 From: ASH Date: Sun, 12 May 2019 11:04:43 +0400 Subject: [PATCH 15/25] #123 fixing layout --- src/main/resources/public/css/tasks.css | 36 +++++++++++++++++++ src/main/resources/public/js/tasks.js | 22 ++++++------ .../students/fragments/taskLineFragment.html | 12 +++---- 3 files changed, 53 insertions(+), 17 deletions(-) diff --git a/src/main/resources/public/css/tasks.css b/src/main/resources/public/css/tasks.css index 7e350ed..1c190b5 100644 --- a/src/main/resources/public/css/tasks.css +++ b/src/main/resources/public/css/tasks.css @@ -39,6 +39,42 @@ max-width: inherit; } +.task-row{ + + position: relative; +} + +.task-row .col:hover{ + + background-color: #f8f9fa; + +} + +.task-row .col > a{ + display: block; + text-decoration: none; +} + +.task-row .col:hover .remove-task{ + + visibility: visible; + +} + +.remove-task{ + visibility: hidden; + position: absolute; + right: -20px; + top: 50%; + transform: translate(-50%, -50%); + padding: 0 20px; +} + +.remove-task:hover{ + + background-color: #ebebeb; +} + .tag { display: inline-block; padding: .2em .6em .3em; diff --git a/src/main/resources/public/js/tasks.js b/src/main/resources/public/js/tasks.js index f756199..84b9567 100644 --- a/src/main/resources/public/js/tasks.js +++ b/src/main/resources/public/js/tasks.js @@ -70,17 +70,17 @@ $(document).ready(function () { }); $("span[data-role=remove]").click(removeTag); - $(".task-row").mouseenter(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "#f8f9fa"); - $(taskRow).find(".remove-task").removeClass("d-none"); - - }); - $(".task-row").mouseleave(function (event) { - var taskRow = $(event.target).closest(".task-row"); - $(taskRow).css("background-color", "white"); - $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); - }); +// $(".task-row").mouseenter(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "#f8f9fa"); +// $(taskRow).find(".remove-task").removeClass("d-none"); +// +// }); +// $(".task-row").mouseleave(function (event) { +// var taskRow = $(event.target).closest(".task-row"); +// $(taskRow).css("background-color", "white"); +// $(taskRow).closest(".task-row").find(".remove-task").addClass("d-none"); +// }); $('a[data-confirm]').click(function(ev) { var href = $(this).attr('href'); diff --git a/src/main/resources/templates/students/fragments/taskLineFragment.html b/src/main/resources/templates/students/fragments/taskLineFragment.html index baad17e..210863d 100644 --- a/src/main/resources/templates/students/fragments/taskLineFragment.html +++ b/src/main/resources/templates/students/fragments/taskLineFragment.html @@ -6,15 +6,15 @@ From fe53c86136284413d153e6fc34700851ce98926e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:42:50 +0400 Subject: [PATCH 16/25] #103 fixed delete conf test --- src/test/java/IndexConferenceTest.java | 71 +++++++++---------- src/test/java/conference/ConferencesPage.java | 4 +- src/test/java/core/PageObject.java | 3 + 3 files changed, 38 insertions(+), 40 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 64b144d..e893630 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -5,10 +5,11 @@ import conference.ConferencesDashboardPage; import conference.ConferencesPage; import core.PageObject; import core.TestTemplate; -import org.assertj.core.api.Assertions; 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; @@ -23,6 +24,7 @@ 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> navigationHolder = ImmutableMap.of( @@ -35,15 +37,7 @@ public class IndexConferenceTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void testStartApplication() { - getContext().goTo(applicationProperties.getBaseUrl()); - Assertions - .assertThat(getContext().getTitle()) - .isEqualTo("NG-Tracker"); - } - - @Test - public void testCreateNewConference() { + public void testA_CreateNewConference() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -60,7 +54,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testChangeConferenceNameAndSave() { + public void testB_ChangeConferenceNameAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -79,7 +73,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testAddDeadlineAndSave() { + public void testC_AddDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -109,7 +103,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testTakePartAndSave() { + public void testD_TakePartAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -130,7 +124,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testDeleteDeadlineAndSave() { + public void testE_DeleteDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -146,11 +140,11 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(deadlineCount - 1 == conferencePage.getDeadlineCount()); + Assert.assertEquals(deadlineCount - 1, (int) conferencePage.getDeadlineCount()); } @Test - public void testAttachArticle() { + public void testF_AttachArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -178,7 +172,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testAddArticle() { + public void testG_AddArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -205,26 +199,27 @@ public class IndexConferenceTest extends TestTemplate { .equals(paperName))); } - @Test - public void testTransitionToTheArticle() { - Map.Entry> 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.getConferenceFirst(); - - WebElement paper = conferencePage.getArticles().get(0); - String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); - paper.findElement(By.tagName("a")).click(); - - Assertions.assertThat(conferencePage.getName()) - .isEqualTo(paperName); - } +// @Test +// @Order(8) +// public void testTransitionToTheArticle() { +// Map.Entry> 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.getConferenceFirst(); +// +// WebElement paper = conferencePage.getArticles().get(0); +// String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); +// paper.findElement(By.tagName("a")).click(); +// +// Assertions.assertThat(conferencePage.getName()) +// .isEqualTo(paperName); +// } @Test - public void testUndockArticle() { + public void testH_UndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -244,7 +239,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testSortAndFilterConferenceList() { + public void testI_SortAndFilterConferenceList() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -257,7 +252,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testDeleteConf() throws InterruptedException { + public void testJ_DeleteConf() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -265,7 +260,7 @@ public class IndexConferenceTest extends TestTemplate { Integer size = conferencesPage.getConferencesList().size(); conferencesPage.deleteFirst(); - Thread.sleep(2000); + Thread.sleep(3000); conferencesPage.clickConfirm(); Assert.assertEquals(size - 1, conferencesPage.getConferencesList().size()); diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 9cccf3f..5129f89 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -31,10 +31,10 @@ public class ConferencesPage extends PageObject { } public void deleteFirst() { - driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/input[2]")).submit(); + js.executeScript("$('input[data-confirm]').click();"); } public void clickConfirm() { - driver.findElement(By.xpath("//*[@id=\"deleteConference\"]")).click(); + driver.findElement(By.id("deleteConference")).click(); } } \ No newline at end of file diff --git a/src/test/java/core/PageObject.java b/src/test/java/core/PageObject.java index d1fae83..f3e5cb8 100644 --- a/src/test/java/core/PageObject.java +++ b/src/test/java/core/PageObject.java @@ -1,14 +1,17 @@ package core; +import org.openqa.selenium.JavascriptExecutor; import org.openqa.selenium.WebDriver; public abstract class PageObject { protected WebDriver driver; + protected JavascriptExecutor js; public abstract String getSubTitle(); public PageObject setDriver(WebDriver driver) { this.driver = driver; + js = (JavascriptExecutor) driver; return this; } } From 70062992ae44493b6ec871a8a53ccd3aac23d29e Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:45:17 +0400 Subject: [PATCH 17/25] #103 clear code --- src/test/java/IndexConferenceTest.java | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index e893630..7796502 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -199,25 +199,6 @@ public class IndexConferenceTest extends TestTemplate { .equals(paperName))); } -// @Test -// @Order(8) -// public void testTransitionToTheArticle() { -// Map.Entry> 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.getConferenceFirst(); -// -// WebElement paper = conferencePage.getArticles().get(0); -// String paperName = paper.findElements(By.tagName("input")).get(1).getAttribute("value"); -// paper.findElement(By.tagName("a")).click(); -// -// Assertions.assertThat(conferencePage.getName()) -// .isEqualTo(paperName); -// } - @Test public void testH_UndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); From 5cbbb6c3190e2a28d793f8865722abef100475d4 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:49:49 +0400 Subject: [PATCH 18/25] #103 fix code style --- src/test/java/IndexConferenceTest.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7796502..c38414a 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -37,7 +37,7 @@ public class IndexConferenceTest extends TestTemplate { private ApplicationProperties applicationProperties; @Test - public void testA_CreateNewConference() { + public void testACreateNewConference() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -54,7 +54,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testB_ChangeConferenceNameAndSave() { + public void testBChangeConferenceNameAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -73,7 +73,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testC_AddDeadlineAndSave() { + public void testCAddDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -103,7 +103,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testD_TakePartAndSave() { + public void testDTakePartAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -124,7 +124,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testE_DeleteDeadlineAndSave() { + public void testEDeleteDeadlineAndSave() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -144,7 +144,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testF_AttachArticle() { + public void testFAttachArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -172,7 +172,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testG_AddArticle() { + public void testGAddArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -200,7 +200,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testH_UndockArticle() { + public void testHUndockArticle() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -216,7 +216,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(paperCount - 1 == conferencePage.getArticlesCount()); + Assert.assertEquals(paperCount - 1, (int) conferencePage.getArticlesCount()); } @Test From 451e7e5d04728e85a627852b3340b2b313b8e804 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Sun, 12 May 2019 13:50:46 +0400 Subject: [PATCH 19/25] #103 fix code style --- src/test/java/IndexConferenceTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index c38414a..7dbd39b 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -220,7 +220,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testI_SortAndFilterConferenceList() { + public void testISortAndFilterConferenceList() { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); @@ -233,7 +233,7 @@ public class IndexConferenceTest extends TestTemplate { } @Test - public void testJ_DeleteConf() throws InterruptedException { + public void testJDeleteConf() throws InterruptedException { Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); From e1907d316920f1e00ec15a72a2cfdd55665f238c Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:28:47 +0400 Subject: [PATCH 20/25] #121 change Paper to PaperDto in attaching papers --- .../ru/ulstu/grant/controller/GrantController.java | 5 ++--- src/main/java/ru/ulstu/grant/model/Grant.java | 1 - src/main/java/ru/ulstu/grant/model/GrantDto.java | 14 +++++++------- .../java/ru/ulstu/paper/service/PaperService.java | 8 ++++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/controller/GrantController.java b/src/main/java/ru/ulstu/grant/controller/GrantController.java index b28f8c0..ad5e992 100644 --- a/src/main/java/ru/ulstu/grant/controller/GrantController.java +++ b/src/main/java/ru/ulstu/grant/controller/GrantController.java @@ -13,7 +13,7 @@ import ru.ulstu.deadline.model.Deadline; import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.service.GrantService; -import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.user.model.User; import springfox.documentation.annotations.ApiIgnore; @@ -104,7 +104,6 @@ public class GrantController { return GRANT_PAGE; } - @PostMapping(value = "/grant", params = "createProject") public String createProject(@Valid GrantDto grantDto, Errors errors) throws IOException { if (errors.hasErrors()) { @@ -131,7 +130,7 @@ public class GrantController { } @ModelAttribute("allPapers") - public List getAllPapers() { + public List getAllPapers() { return grantService.getAllUncompletedPapers(); } diff --git a/src/main/java/ru/ulstu/grant/model/Grant.java b/src/main/java/ru/ulstu/grant/model/Grant.java index 760895e..e0cd9be 100644 --- a/src/main/java/ru/ulstu/grant/model/Grant.java +++ b/src/main/java/ru/ulstu/grant/model/Grant.java @@ -74,7 +74,6 @@ public class Grant extends BaseEntity implements UserContainer { @Fetch(FetchMode.SUBSELECT) private List files = new ArrayList<>(); - @ManyToOne(cascade = CascadeType.ALL) @JoinColumn(name = "project_id") private Project project; diff --git a/src/main/java/ru/ulstu/grant/model/GrantDto.java b/src/main/java/ru/ulstu/grant/model/GrantDto.java index e842b10..203d306 100644 --- a/src/main/java/ru/ulstu/grant/model/GrantDto.java +++ b/src/main/java/ru/ulstu/grant/model/GrantDto.java @@ -6,7 +6,7 @@ import org.apache.commons.lang3.StringUtils; import org.hibernate.validator.constraints.NotEmpty; import ru.ulstu.deadline.model.Deadline; import ru.ulstu.file.model.FileDataDto; -import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.project.model.ProjectDto; import ru.ulstu.user.model.UserDto; @@ -37,7 +37,7 @@ public class GrantDto { private boolean hasBAKPapers; private boolean hasScopusPapers; private List paperIds = new ArrayList<>(); - private List papers = new ArrayList<>(); + private List papers = new ArrayList<>(); private List removedDeadlineIds = new ArrayList<>(); public GrantDto() { @@ -54,12 +54,12 @@ public class GrantDto { @JsonProperty("project") ProjectDto project, @JsonProperty("authorIds") Set authorIds, @JsonProperty("authors") Set authors, - @JsonProperty("leader") Integer leaderId, + @JsonProperty("leaderId") Integer leaderId, @JsonProperty("wasLeader") boolean wasLeader, @JsonProperty("hasAge") boolean hasAge, @JsonProperty("hasDegree") boolean hasDegree, @JsonProperty("paperIds") List paperIds, - @JsonProperty("papers") List papers) { + @JsonProperty("papers") List papers) { this.id = id; this.title = title; this.status = status; @@ -92,7 +92,7 @@ public class GrantDto { this.hasAge = false; this.hasDegree = false; this.paperIds = convert(grant.getPapers(), paper -> paper.getId()); - this.papers = grant.getPapers(); + this.papers = convert(grant.getPapers(), PaperDto::new); } public Integer getId() { @@ -214,11 +214,11 @@ public class GrantDto { this.paperIds = paperIds; } - public List getPapers() { + public List getPapers() { return papers; } - public void setPapers(List papers) { + public void setPapers(List papers) { this.papers = papers; } diff --git a/src/main/java/ru/ulstu/paper/service/PaperService.java b/src/main/java/ru/ulstu/paper/service/PaperService.java index 0083de7..db810f5 100644 --- a/src/main/java/ru/ulstu/paper/service/PaperService.java +++ b/src/main/java/ru/ulstu/paper/service/PaperService.java @@ -248,12 +248,12 @@ public class PaperService { } } - public List findAllNotCompleted() { - return paperRepository.findByStatusNot(COMPLETED); + public List findAllNotCompleted() { + return convert(paperRepository.findByStatusNot(COMPLETED), PaperDto::new); } - public List findAllSelect(List paperIds) { - return sortPapers(paperRepository.findAllByIdIn(paperIds)); + public List findAllSelect(List paperIds) { + return convert(paperRepository.findAllByIdIn(paperIds), PaperDto::new); } public List getPaperAuthors() { From 99ec7af3191409e2f08fb437576655adc00c8448 Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:30:09 +0400 Subject: [PATCH 21/25] #121 reduce paper title --- .../ru/ulstu/grant/service/GrantService.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 83ef49e..45f9b2f 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -11,6 +11,7 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.grant.repository.GrantRepository; import ru.ulstu.paper.model.Paper; +import ru.ulstu.paper.model.PaperDto; import ru.ulstu.paper.service.PaperService; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; @@ -34,7 +35,7 @@ import static ru.ulstu.grant.model.Grant.GrantStatus.APPLICATION; @Service public class GrantService { - private final static int MAX_DISPLAY_SIZE = 40; + private final static int MAX_DISPLAY_SIZE = 50; private final GrantRepository grantRepository; private final ProjectService projectService; @@ -210,17 +211,16 @@ public class GrantService { .collect(toList()); } - public List getGrantPapers(List paperIds) { + public List getGrantPapers(List paperIds) { return paperService.findAllSelect(paperIds); - } - public List getAllPapers() { - return paperService.findAll(); - } - - public List getAllUncompletedPapers() { - return paperService.findAllNotCompleted(); + public List getAllUncompletedPapers() { + List papers = paperService.findAllNotCompleted(); + papers.stream() + .forEach(paper -> + paper.setTitle(StringUtils.abbreviate(paper.getTitle(), MAX_DISPLAY_SIZE))); + return papers; } public void attachPaper(GrantDto grantDto) { From f6830d499b03f45b7bf42e31fdde496e9ae2f9ec Mon Sep 17 00:00:00 2001 From: T-Midnight Date: Sun, 12 May 2019 15:31:50 +0400 Subject: [PATCH 22/25] #121 update view --- src/main/resources/templates/grants/grant.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index e357876..38047bf 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -184,9 +184,9 @@ value="Отобразить прикрепленную статью"/> From 6044d6f8e398e0aa6b5706066511a2133de304de Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 13 May 2019 19:08:21 +0400 Subject: [PATCH 23/25] #111 save method refactor --- .../controller/ConferenceController.java | 11 +---------- .../conference/service/ConferenceService.java | 16 +++++++++++++++- .../templates/conferences/conference.html | 7 ++++--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java index 48a2ef2..f9a4bac 100644 --- a/src/main/java/ru/ulstu/conference/controller/ConferenceController.java +++ b/src/main/java/ru/ulstu/conference/controller/ConferenceController.java @@ -74,18 +74,9 @@ public class ConferenceController { @PostMapping(value = "/conference", params = "save") public String save(@Valid ConferenceDto conferenceDto, Errors errors) throws IOException { - conferenceService.filterEmptyDeadlines(conferenceDto); - conferenceService.checkEmptyFieldsOfDeadline(conferenceDto, errors); - conferenceDto.setName(conferenceDto.getTitle()); - conferenceService.checkUniqueName(conferenceDto, - errors, - conferenceDto.getId(), - "title", - "Конференция с таким именем уже существует"); - if (errors.hasErrors()) { + if (!conferenceService.save(conferenceDto, errors)) { return CONFERENCE_PAGE; } - conferenceService.save(conferenceDto); return String.format(REDIRECT_TO, CONFERENCES_PAGE); } diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index 8ffeb6f..d3ef2da 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -91,12 +91,26 @@ public class ConferenceService extends BaseService { return new ConferenceDto(conferenceRepository.findOne(id)); } - public void save(ConferenceDto conferenceDto) throws IOException { + public boolean save(ConferenceDto conferenceDto, Errors errors) throws IOException { + conferenceDto.setName(conferenceDto.getTitle()); + filterEmptyDeadlines(conferenceDto); + checkEmptyFieldsOfDeadline(conferenceDto, errors); + checkUniqueName(conferenceDto, + errors, + conferenceDto.getId(), + "title", + "Конференция с таким именем уже существует"); + if (errors.hasErrors()) { + return false; + } + if (isEmpty(conferenceDto.getId())) { create(conferenceDto); } else { update(conferenceDto); } + + return true; } @Transactional diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index d5906b6..d629d4e 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -30,11 +30,12 @@ -

Incorrect title

-

+

Incorrect title

+

+
Date: Mon, 13 May 2019 20:13:53 +0400 Subject: [PATCH 24/25] #103 code refactoring --- src/test/java/IndexConferenceTest.java | 45 ++++++------------- src/test/java/conference/ConferencePage.java | 23 +++++++++- src/test/java/conference/ConferencesPage.java | 9 +++- 3 files changed, 42 insertions(+), 35 deletions(-) diff --git a/src/test/java/IndexConferenceTest.java b/src/test/java/IndexConferenceTest.java index 7dbd39b..269561f 100644 --- a/src/test/java/IndexConferenceTest.java +++ b/src/test/java/IndexConferenceTest.java @@ -48,9 +48,7 @@ public class IndexConferenceTest extends TestTemplate { conferencePage.setName(newConferenceName); conferencePage.clickSaveBut(); - Assert.assertTrue(conferencesPage.getConferencesList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); } @Test @@ -61,15 +59,13 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String newConferenceName = "test " + (new Date()).getTime(); conferencePage.clearName(); conferencePage.setName(newConferenceName); conferencePage.clickSaveBut(); - Assert.assertTrue(conferencesPage.getConferencesList() - .stream() - .anyMatch(webElement -> webElement.getText().equals(newConferenceName))); + Assert.assertTrue(conferencesPage.checkNameInList(newConferenceName)); } @Test @@ -80,7 +76,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer deadlineCount = conferencePage.getDeadlineCount(); @@ -94,12 +90,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); - Assert.assertTrue(conferencePage.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); - })); + Assert.assertTrue(conferencePage.checkDeadline(description, dateValue)); } @Test @@ -110,7 +101,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer membersCount = conferencePage.getMemberCount(); @@ -120,7 +111,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(membersCount + 1 == conferencePage.getMemberCount() - && conferencePage.getTakePartButDisabledValue().equals("true")); + && conferencePage.isTakePartButDisabledValueTrue()); } @Test @@ -131,7 +122,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer deadlineCount = conferencePage.getDeadlineCount(); @@ -151,7 +142,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); @@ -163,12 +154,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.getArticles() - .stream() - .anyMatch(webElement -> webElement - .findElements(By.tagName("input")) - .get(1).getAttribute("value") - .equals(paperName))); + && conferencePage.checkArticle(paperName)); } @Test @@ -179,7 +165,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); @@ -191,12 +177,7 @@ public class IndexConferenceTest extends TestTemplate { getContext().goTo(applicationProperties.getBaseUrl() + String.format("/conferences/conference?id=%s", conferenceId)); Assert.assertTrue(paperCount + 1 == conferencePage.getArticlesCount() - && conferencePage.getArticles() - .stream() - .anyMatch(webElement -> webElement - .findElements(By.tagName("input")) - .get(1).getAttribute("value") - .equals(paperName))); + && conferencePage.checkArticle(paperName)); } @Test @@ -207,7 +188,7 @@ public class IndexConferenceTest extends TestTemplate { ConferencesPage conferencesPage = (ConferencesPage) getContext().initPage(page.getKey()); ConferencePage conferencePage = (ConferencePage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); - conferencesPage.getConferenceFirst(); + conferencesPage.getFirstConference(); String conferenceId = conferencePage.getId(); Integer paperCount = conferencePage.getArticlesCount(); diff --git a/src/test/java/conference/ConferencePage.java b/src/test/java/conference/ConferencePage.java index 50e545e..ef0d941 100644 --- a/src/test/java/conference/ConferencePage.java +++ b/src/test/java/conference/ConferencePage.java @@ -56,8 +56,8 @@ public class ConferencePage extends PageObject { driver.findElement(By.id("take-part")).click(); } - public String getTakePartButDisabledValue() { - return driver.findElement(By.id("take-part")).getAttribute("disabled"); + public Boolean isTakePartButDisabledValueTrue() { + return driver.findElement(By.id("take-part")).getAttribute("disabled").equals("true"); } public Integer getMemberCount() { @@ -94,4 +94,23 @@ public class ConferencePage extends PageObject { 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)); + } + } \ No newline at end of file diff --git a/src/test/java/conference/ConferencesPage.java b/src/test/java/conference/ConferencesPage.java index 5129f89..c11429f 100644 --- a/src/test/java/conference/ConferencesPage.java +++ b/src/test/java/conference/ConferencesPage.java @@ -16,7 +16,7 @@ public class ConferencesPage extends PageObject { return driver.findElements(By.cssSelector("span.h6.float-left.m-2")); } - public void getConferenceFirst() { + public void getFirstConference() { driver.findElement(By.xpath("//*[@id=\"conferences\"]/div/div[2]/div[1]/div[1]/div/a")).click(); } @@ -37,4 +37,11 @@ public class ConferencesPage extends PageObject { public void clickConfirm() { driver.findElement(By.id("deleteConference")).click(); } + + + public boolean checkNameInList(String newConferenceName) { + return getConferencesList() + .stream() + .anyMatch(webElement -> webElement.getText().equals(newConferenceName)); + } } \ No newline at end of file From ab59cb524e4e3eecbbdd4bb56f475fe065445da5 Mon Sep 17 00:00:00 2001 From: Nightblade73 Date: Mon, 13 May 2019 20:26:13 +0400 Subject: [PATCH 25/25] #103 fix code style --- src/main/resources/public/js/conference.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/public/js/conference.js b/src/main/resources/public/js/conference.js index 18a8c67..8273557 100644 --- a/src/main/resources/public/js/conference.js +++ b/src/main/resources/public/js/conference.js @@ -25,4 +25,5 @@ $(document).ready(function () { $('#dataConfirmModal').modal({show:true}); return false; }); + });