diff --git a/src/main/java/ru/ulstu/conference/service/ConferenceService.java b/src/main/java/ru/ulstu/conference/service/ConferenceService.java index f742139..d877232 100644 --- a/src/main/java/ru/ulstu/conference/service/ConferenceService.java +++ b/src/main/java/ru/ulstu/conference/service/ConferenceService.java @@ -25,9 +25,9 @@ import ru.ulstu.user.service.UserService; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Collections; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/grant/service/GrantService.java b/src/main/java/ru/ulstu/grant/service/GrantService.java index 27841e3..542965a 100644 --- a/src/main/java/ru/ulstu/grant/service/GrantService.java +++ b/src/main/java/ru/ulstu/grant/service/GrantService.java @@ -1,6 +1,5 @@ package ru.ulstu.grant.service; -import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.stereotype.Service; diff --git a/src/main/java/ru/ulstu/project/controller/ProjectController.java b/src/main/java/ru/ulstu/project/controller/ProjectController.java index 87ae8df..a991e35 100644 --- a/src/main/java/ru/ulstu/project/controller/ProjectController.java +++ b/src/main/java/ru/ulstu/project/controller/ProjectController.java @@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.grant.model.Grant; import ru.ulstu.grant.model.GrantDto; import ru.ulstu.project.model.Project; import ru.ulstu.project.model.ProjectDto; diff --git a/src/main/java/ru/ulstu/project/model/Project.java b/src/main/java/ru/ulstu/project/model/Project.java index 07f0141..6b5f925 100644 --- a/src/main/java/ru/ulstu/project/model/Project.java +++ b/src/main/java/ru/ulstu/project/model/Project.java @@ -12,16 +12,16 @@ import ru.ulstu.grant.model.Grant; import ru.ulstu.timeline.model.Event; import ru.ulstu.user.model.User; +import javax.persistence.CascadeType; import javax.persistence.Entity; import javax.persistence.EnumType; import javax.persistence.Enumerated; -import javax.persistence.OneToMany; -import javax.persistence.CascadeType; -import javax.persistence.JoinColumn; -import javax.persistence.ManyToOne; import javax.persistence.FetchType; -import javax.persistence.ManyToMany; +import javax.persistence.JoinColumn; import javax.persistence.JoinTable; +import javax.persistence.ManyToMany; +import javax.persistence.ManyToOne; +import javax.persistence.OneToMany; import javax.validation.constraints.NotNull; import java.util.ArrayList; import java.util.Collections; diff --git a/src/main/java/ru/ulstu/students/model/Task.java b/src/main/java/ru/ulstu/students/model/Task.java index 2e63a3c..c3f195b 100644 --- a/src/main/java/ru/ulstu/students/model/Task.java +++ b/src/main/java/ru/ulstu/students/model/Task.java @@ -6,13 +6,8 @@ import org.hibernate.validator.constraints.NotBlank; import ru.ulstu.core.model.BaseEntity; import ru.ulstu.core.model.EventSource; import ru.ulstu.deadline.model.Deadline; -import ru.ulstu.deadline.service.DeadlineService; -import ru.ulstu.students.repository.SchedulerRepository; -import ru.ulstu.students.repository.TaskRepository; import ru.ulstu.tags.model.Tag; -import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.model.Event; -import ru.ulstu.timeline.service.EventService; import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; diff --git a/src/main/java/ru/ulstu/students/service/TaskService.java b/src/main/java/ru/ulstu/students/service/TaskService.java index f78f8f7..548e899 100644 --- a/src/main/java/ru/ulstu/students/service/TaskService.java +++ b/src/main/java/ru/ulstu/students/service/TaskService.java @@ -18,15 +18,15 @@ import ru.ulstu.tags.service.TagService; import ru.ulstu.timeline.service.EventService; import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; -import java.util.Set; import java.util.Map; +import java.util.Set; import java.util.TreeMap; -import java.util.ArrayList; -import java.util.Arrays; import java.util.stream.Collectors; import static org.springframework.util.ObjectUtils.isEmpty; diff --git a/src/main/java/ru/ulstu/timeline/service/EventService.java b/src/main/java/ru/ulstu/timeline/service/EventService.java index c22b9a3..868d576 100644 --- a/src/main/java/ru/ulstu/timeline/service/EventService.java +++ b/src/main/java/ru/ulstu/timeline/service/EventService.java @@ -18,7 +18,6 @@ import ru.ulstu.timeline.repository.EventRepository; import ru.ulstu.user.model.UserDto; import ru.ulstu.user.service.UserService; -import java.util.ArrayList; import java.util.Collections; import java.util.Date; import java.util.List; diff --git a/src/main/java/ru/ulstu/user/controller/UserController.java b/src/main/java/ru/ulstu/user/controller/UserController.java index c40ed8f..407986f 100644 --- a/src/main/java/ru/ulstu/user/controller/UserController.java +++ b/src/main/java/ru/ulstu/user/controller/UserController.java @@ -3,7 +3,6 @@ package ru.ulstu.user.controller; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.security.access.annotation.Secured; -import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -33,7 +32,6 @@ import ru.ulstu.user.service.UserSessionService; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import javax.validation.Valid; - import java.util.Map; import static ru.ulstu.user.controller.UserController.URL; diff --git a/src/main/java/ru/ulstu/user/controller/UserMvcController.java b/src/main/java/ru/ulstu/user/controller/UserMvcController.java index 044bde8..7f1c1b8 100644 --- a/src/main/java/ru/ulstu/user/controller/UserMvcController.java +++ b/src/main/java/ru/ulstu/user/controller/UserMvcController.java @@ -9,8 +9,8 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import ru.ulstu.configuration.Constants; import ru.ulstu.odin.controller.OdinController; -import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.User; +import ru.ulstu.user.model.UserDto; import ru.ulstu.user.model.UserListDto; import ru.ulstu.user.service.UserService; import ru.ulstu.user.service.UserSessionService; diff --git a/src/main/java/ru/ulstu/user/service/UserService.java b/src/main/java/ru/ulstu/user/service/UserService.java index 217215b..b731c1e 100644 --- a/src/main/java/ru/ulstu/user/service/UserService.java +++ b/src/main/java/ru/ulstu/user/service/UserService.java @@ -252,7 +252,7 @@ public class UserService implements UserDetailsService { mailService.sendChangePasswordMail(user); } - public boolean requestUserPasswordReset(String email) { + public boolean requestUserPasswordReset(String email) { User user = userRepository.findOneByEmailIgnoreCase(email); if (user == null) { throw new UserNotFoundException(email); diff --git a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java index d65e276..78a1c66 100644 --- a/src/main/java/ru/ulstu/utils/timetable/TimetableService.java +++ b/src/main/java/ru/ulstu/utils/timetable/TimetableService.java @@ -18,7 +18,7 @@ public class TimetableService { private static final String TIMETABLE_URL = "http://timetable.athene.tech/api/1.0/timetable?filter=%s"; private SimpleDateFormat lessonTimeFormat = new SimpleDateFormat("hh:mm"); - private long[] lessonsStarts = new long[] { + private long[] lessonsStarts = new long[]{ lessonTimeFormat.parse("8:00:00").getTime(), lessonTimeFormat.parse("9:40:00").getTime(), lessonTimeFormat.parse("11:30:00").getTime(), @@ -58,8 +58,8 @@ public class TimetableService { firstJan.set(Calendar.MONTH, 0); firstJan.set(Calendar.DAY_OF_MONTH, 1); - return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) - + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); + return (int) Math.round(Math.ceil((((currentDate.getTime() - firstJan.getTime().getTime()) / 86400000) + + DateUtils.addDays(firstJan.getTime(), 1).getTime() / 7) % 2)); } private TimetableResponse getTimetableForUser(String userFIO) throws RestClientException { @@ -67,7 +67,7 @@ public class TimetableService { return restTemplate.getForObject(String.format(TIMETABLE_URL, userFIO), TimetableResponse.class); } - public Lesson getCurrentLesson(String userFio) { + public Lesson getCurrentLesson(String userFio) { TimetableResponse response; try { response = getTimetableForUser(userFio); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Day.java b/src/main/java/ru/ulstu/utils/timetable/model/Day.java index e4e37f9..211165d 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Day.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Day.java @@ -4,7 +4,7 @@ import java.util.ArrayList; import java.util.List; -public class Day { +public class Day { private Integer day; private List> lessons = new ArrayList<>(); diff --git a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java index b1b1707..9c855bd 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/Lesson.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class Lesson { +public class Lesson { private String group; private String nameOfLesson; private String teacher; diff --git a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java index 925d9a8..118c979 100644 --- a/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java +++ b/src/main/java/ru/ulstu/utils/timetable/model/TimetableResponse.java @@ -1,6 +1,6 @@ package ru.ulstu.utils.timetable.model; -public class TimetableResponse { +public class TimetableResponse { private Response response; private String error; diff --git a/src/main/resources/templates/conferences/conference.html b/src/main/resources/templates/conferences/conference.html index 201aa01..106f014 100644 --- a/src/main/resources/templates/conferences/conference.html +++ b/src/main/resources/templates/conferences/conference.html @@ -156,14 +156,16 @@ - + Имя статьи - + Имя статьи diff --git a/src/main/resources/templates/grants/fragments/grantLineFragment.html b/src/main/resources/templates/grants/fragments/grantLineFragment.html index 877f1d7..821cf89 100644 --- a/src/main/resources/templates/grants/fragments/grantLineFragment.html +++ b/src/main/resources/templates/grants/fragments/grantLineFragment.html @@ -8,10 +8,16 @@
- - + + + + + diff --git a/src/main/resources/templates/grants/fragments/grantStatusFragment.html b/src/main/resources/templates/grants/fragments/grantStatusFragment.html index 569f5ee..bf866d2 100644 --- a/src/main/resources/templates/grants/fragments/grantStatusFragment.html +++ b/src/main/resources/templates/grants/fragments/grantStatusFragment.html @@ -25,7 +25,7 @@
- + \ No newline at end of file diff --git a/src/main/resources/templates/grants/grant.html b/src/main/resources/templates/grants/grant.html index acb7f7b..04a86a7 100644 --- a/src/main/resources/templates/grants/grant.html +++ b/src/main/resources/templates/grants/grant.html @@ -49,7 +49,7 @@
-
+
+
diff --git a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html index 62d2466..48b6bae 100644 --- a/src/main/resources/templates/papers/fragments/paperDashboardFragment.html +++ b/src/main/resources/templates/papers/fragments/paperDashboardFragment.html @@ -7,7 +7,8 @@
- +

- - - - + + + + diff --git a/src/main/resources/templates/papers/fragments/paperStatusFragment.html b/src/main/resources/templates/papers/fragments/paperStatusFragment.html index 321370a..a142722 100644 --- a/src/main/resources/templates/papers/fragments/paperStatusFragment.html +++ b/src/main/resources/templates/papers/fragments/paperStatusFragment.html @@ -4,34 +4,35 @@ - +
- +
- +
- +
- +
- +
- +
- +
- +
- +
\ No newline at end of file diff --git a/src/main/resources/templates/papers/paper.html b/src/main/resources/templates/papers/paper.html index 2fbfa3a..e77ccbb 100644 --- a/src/main/resources/templates/papers/paper.html +++ b/src/main/resources/templates/papers/paper.html @@ -530,6 +530,7 @@ } } + @@ -35,7 +35,8 @@
- +
diff --git a/src/main/resources/templates/users/fragments/userDashboardFragment.html b/src/main/resources/templates/users/fragments/userDashboardFragment.html index 267bbf8..3095cca 100644 --- a/src/main/resources/templates/users/fragments/userDashboardFragment.html +++ b/src/main/resources/templates/users/fragments/userDashboardFragment.html @@ -7,9 +7,13 @@
-

-

-

+

+
+

+
+

+

Онлайн

diff --git a/src/test/java/GrantTest.java b/src/test/java/GrantTest.java new file mode 100644 index 0000000..b824852 --- /dev/null +++ b/src/test/java/GrantTest.java @@ -0,0 +1,225 @@ +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Iterables; +import core.PageObject; +import core.TestTemplate; +import grant.GrantPage; +import grant.GrantsDashboardPage; +import grant.GrantsPage; +import org.junit.Assert; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.MethodSorters; +import org.openqa.selenium.WebElement; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; +import ru.ulstu.NgTrackerApplication; +import ru.ulstu.configuration.ApplicationProperties; + +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; + +@RunWith(SpringRunner.class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT) +public class GrantTest extends TestTemplate { + private final Map> navigationHolder = ImmutableMap.of( + new GrantsPage(), Arrays.asList("ГРАНТЫ", "/grants/grants"), + new GrantPage(), Arrays.asList("РЕДАКТИРОВАНИЕ ГРАНТА", "/grants/grant?id=0"), + new GrantsDashboardPage(), Arrays.asList("Гранты", "/grants/dashboard") + ); + + @Autowired + private ApplicationProperties applicationProperties; + + @Test + public void aCreateNewGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 0).getKey()); + + String newGrantName = "test grant" + (new Date()); + grantPage.setTitle(newGrantName); + String deadlineDate = new Date().toString(); + String deadlineDescription = "test deadline description"; + grantPage.setDeadline(deadlineDate, 0, deadlineDescription); + grantPage.setLeader(); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantName)); + } + + @Test + public void bCreateBlankGrant() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 1); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantPage grantPage = (GrantPage) getContext().initPage(page.getKey()); + + grantPage.saveGrant(); + + Assert.assertTrue(grantPage.checkBlankFields()); + } + + @Test + public void cUpdateGrantTitle() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String newGrantTitle = "test " + (new Date()); + grantPage.setTitle(newGrantTitle); + grantPage.saveGrant(); + + Assert.assertTrue(grantsPage.findGrantByTitle(newGrantTitle)); + } + + @Test + public void dAttachPaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer countPapers = grantPage.getAttachedPapers().size(); + + Assert.assertEquals(countPapers + 1, grantPage.attachPaper().size()); + } + + @Test + public void eDeletePaper() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + Integer oldCountPapers = grantPage.getAttachedPapers().size(); + if (oldCountPapers == 0) { + oldCountPapers = grantPage.attachPaper().size(); + } + + Assert.assertEquals(oldCountPapers - 1, grantPage.deletePaper().size()); + } + + @Test + public void fAddDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + String description = "deadline test"; + String date = "08.08.2019"; + String dateValue = "2019-08-08"; + grantPage.addDeadline(); + grantPage.setDeadline(date, deadlineCount, description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(grantPage.checkDeadline(description, dateValue)); + } + + @Test + public void gDeleteDeadline() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + Integer deadlineCount = grantPage.getDeadlineCount(); + + grantPage.deleteDeadline(); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + Integer newDeadlineCount = grantPage.getDeadlineCount(); + Assert.assertEquals(deadlineCount - 1, (int) newDeadlineCount); + } + + @Test + public void hAddAuthor() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.addAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + Assert.assertEquals(authorsCount + 1, (int) newAuthorsCount); + } + + @Test + public void iDeleteAuthor() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + WebElement grant = grantsPage.getFirstGrantWithoutClick(); + String grantTitle = grantsPage.getGrantTitle(grant); + Integer authorsCount = grantsPage.getAuthorsCount(grant); + + grantsPage.getFirstGrant(); + grantPage.deleteAuthor(); + grantPage.saveGrant(); + + grant = grantsPage.getGrantByTitle(grantTitle); + Integer newAuthorsCount = grantsPage.getAuthorsCount(grant); + + authorsCount = (authorsCount == 0) ? 0 : authorsCount - 1; + + Assert.assertEquals((int) authorsCount, (int) newAuthorsCount); + } + + @Test + public void jUpdateGrantDescription() { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + GrantPage grantPage = (GrantPage) getContext().initPage(Iterables.get(navigationHolder.entrySet(), 1).getKey()); + + String description = "newDescriptionForGrant"; + grantsPage.getFirstGrant(); + String grantId = grantPage.getId(); + grantPage.setDescription(description); + grantPage.saveGrant(); + + getContext().goTo(applicationProperties.getBaseUrl() + String.format("/grants/grant?id=%s", grantId)); + + Assert.assertTrue(description.equals(grantPage.getDescription())); + } + + @Test + public void kDeleteGrant() throws InterruptedException { + Map.Entry> page = Iterables.get(navigationHolder.entrySet(), 0); + getContext().goTo(applicationProperties.getBaseUrl() + page.getValue().get(1)); + GrantsPage grantsPage = (GrantsPage) getContext().initPage(page.getKey()); + + Integer size = grantsPage.getGrantsList().size(); + grantsPage.deleteFirst(); + Assert.assertEquals(size - 1, grantsPage.getGrantsList().size()); + } +} diff --git a/src/test/java/grant/GrantPage.java b/src/test/java/grant/GrantPage.java new file mode 100644 index 0000000..fe13956 --- /dev/null +++ b/src/test/java/grant/GrantPage.java @@ -0,0 +1,149 @@ +package grant; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; +import org.openqa.selenium.support.ui.Select; + +import java.util.List; + +public class GrantPage extends PageObject { + @Override + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } + + public String getId() { + return driver.findElement(By.id("id")).getAttribute("value"); + } + + public void setTitle(String name) { + driver.findElement(By.id("title")).clear(); + driver.findElement(By.id("title")).sendKeys(name); + } + + public String getTitle() { + return driver.findElement(By.id("title")).getAttribute("value"); + } + + public void setDeadline(String date, Integer i, String description) { + driver.findElement(By.id(String.format("deadlines%d.date", i))).sendKeys(date); + driver.findElement(By.id(String.format("deadlines%d.description", i))).sendKeys(description); + } + + public void setLeader() { + WebElement webElement = driver.findElement(By.id("leaderId")); + Select selectLeader = new Select(webElement); + selectLeader.selectByVisibleText("Романов"); + } + + public void saveGrant() { + driver.findElement(By.id("sendMessageButton")).click(); + } + + public boolean checkBlankFields() { + return driver.findElements(By.className("alert-danger")).size() > 0; + } + + public List getAttachedPapers() { + try { + return driver.findElement(By.className("div-selected-papers")).findElements(By.tagName("div")); + } catch (Exception ex) { + return null; + } + } + + public List attachPaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + if (selectedOptions.size() >= allOptions.size()) { + for (int i = 0; i < allOptions.size(); i++) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } + } + } else { + select.selectByVisibleText(allOptions.get(0).getText()); + selectedOptions.add(allOptions.get(0)); + return selectedOptions; + } + return null; + } + + public List deletePaper() { + WebElement selectPapers = driver.findElement(By.id("allPapers")); + Select select = new Select(selectPapers); + select.deselectByVisibleText(select.getFirstSelectedOption().getText()); + return select.getAllSelectedOptions(); + } + + public List getDeadlineList() { + return driver.findElements(By.id("deadlines")); + } + + public Integer getDeadlineCount() { + return getDeadlineList().size(); + } + + public void addDeadline() { + driver.findElement(By.id("addDeadline")).click(); + } + + public boolean checkDeadline(String description, String dateValue) { + return getDeadlineList() + .stream() + .anyMatch(webElement -> { + return webElement.findElement(By.className("div-deadline-description")).findElement( + By.tagName("input")).getAttribute("value").equals(description) + && webElement.findElement(By.className("form-deadline-date")).getAttribute("value").equals(dateValue); + }); + } + + public void deleteDeadline() { + driver.findElements(By.className("btn-delete-deadline")).get(0).click(); + } + + public List addAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + List allOptions = select.getOptions(); + int i = 0; + while (i < selectedOptions.size()) { + if (!allOptions.get(i).equals(selectedOptions.get(i))) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + return selectedOptions; + } else { + i++; + } + } + if (selectedOptions.size() != allOptions.size()) { + select.selectByVisibleText(allOptions.get(i).getText()); + selectedOptions.add(allOptions.get(i)); + } + return selectedOptions; + } + + public void deleteAuthor() { + WebElement selectAuthors = driver.findElement(By.id("authors")); + Select select = new Select(selectAuthors); + List selectedOptions = select.getAllSelectedOptions(); + if (selectedOptions.size() != 0) { + select.deselectByVisibleText(selectedOptions.get(0).getText()); + } + } + + public void setDescription(String description) { + driver.findElement(By.id("comment")).clear(); + driver.findElement(By.id("comment")).sendKeys(description); + } + + public String getDescription() { + return driver.findElement(By.id("comment")).getText(); + } +} diff --git a/src/test/java/grant/GrantsDashboardPage.java b/src/test/java/grant/GrantsDashboardPage.java new file mode 100644 index 0000000..036e785 --- /dev/null +++ b/src/test/java/grant/GrantsDashboardPage.java @@ -0,0 +1,11 @@ +package grant; + +import core.PageObject; +import org.openqa.selenium.By; + +public class GrantsDashboardPage extends PageObject { + @Override + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } +} diff --git a/src/test/java/grant/GrantsPage.java b/src/test/java/grant/GrantsPage.java new file mode 100644 index 0000000..33c388d --- /dev/null +++ b/src/test/java/grant/GrantsPage.java @@ -0,0 +1,66 @@ +package grant; + +import core.PageObject; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.util.List; + +public class GrantsPage extends PageObject { + @Override + public String getSubTitle() { + return driver.findElement(By.tagName("h2")).getText(); + } + + public List getGrantsList() { + return driver.findElements(By.className("grant-row")); + } + + public boolean findGrantByTitle(String grantTitle) { + return getGrantsList() + .stream() + .map(el -> el.findElement(By.cssSelector("span.h6"))) + .anyMatch(webElement -> webElement.getText().equals(grantTitle)); + } + + public void deleteFirst() throws InterruptedException { + WebElement findDeleteButton = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div")); + findDeleteButton.click(); + Thread.sleep(3000); + WebElement grant = driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[2]")); + grant.click(); + WebElement ok = driver.findElement(By.id("dataConfirmOK")); + ok.click(); + } + + public void getFirstGrant() { + driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]/div/a[1]")).click(); + } + + public WebElement getFirstGrantWithoutClick() { + return driver.findElement(By.xpath("//*[@id=\"grants\"]/div/div[2]/div[1]/div[1]")); + } + + public String getGrantTitle(WebElement webElement) { + return webElement.findElement(By.cssSelector("span.h6")).getText(); + } + + public WebElement getGrantByTitle(String title) { + List list = getGrantsList(); + for (int i = 0; i < list.size(); i++) { + if (getGrantTitle(list.get(i)).equals(title)) { + return list.get(i); + } + } + return null; + } + + public Integer getAuthorsCount(WebElement webElement) { + String authors = webElement.findElement(By.className("text-muted")).getText(); + if (!authors.equals("")) { + String[] mas = authors.split(","); + return mas.length; + } + return 0; + } +} diff --git a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java index 4015f3b..25a201b 100644 --- a/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java +++ b/src/test/java/ru/ulstu/project/service/ProjectServiceTest.java @@ -20,7 +20,10 @@ import ru.ulstu.user.model.User; import ru.ulstu.user.service.UserService; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Date; +import java.util.List; import static junit.framework.TestCase.assertTrue; import static org.junit.Assert.assertEquals;