PersonView is opened in Test.

master
Markus Kreth 7 years ago
parent 80298b48a6
commit 2302062176
  1. 12
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/MainUi.java
  2. 1
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  3. 22
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/PersonGrid.java
  4. 152
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/tests/VaadinClubhelperApplicationTests.java

@ -112,14 +112,14 @@ public class MainUi extends UI {
ClubEvent ev = (ClubEvent) event.getCalendarItem(); ClubEvent ev = (ClubEvent) event.getCalendarItem();
LOGGER.debug("Opening detail view for {}", ev); LOGGER.debug("Opening detail view for {}", ev);
// contentLayout.removeComponent(personGrid); contentLayout.removeComponent(personGrid);
// contentLayout.addComponent(personGrid); contentLayout.addComponent(personGrid);
eventBusiness.setSelected(null); eventBusiness.setSelected(null);
// personGrid.setEnabled(false); personGrid.setEnabled(false);
// personGrid.setEvent(ev); personGrid.setEvent(ev);
// personGrid.setVisible(true); personGrid.setEnabled(true);
// personGrid.setEnabled(true); personGrid.setVisible(true);
eventBusiness.setSelected(ev); eventBusiness.setSelected(ev);
} }

@ -71,6 +71,7 @@ public class CalendarComponent extends CustomComponent {
dataProvider = new ClubEventProvider(); dataProvider = new ClubEventProvider();
calendar = new Calendar<>(dataProvider).withMonth(Month.from(LocalDateTime.now())); calendar = new Calendar<>(dataProvider).withMonth(Month.from(LocalDateTime.now()));
calendar.setId("calendar.calendar"); calendar.setId("calendar.calendar");
calendar.setCaption("Events"); calendar.setCaption("Events");
calendar.setSizeFull(); calendar.setSizeFull();
calendar.addListener(ev -> calendarEvent(ev)); calendar.addListener(ev -> calendarEvent(ev));

@ -61,7 +61,7 @@ public class PersonGrid extends CustomComponent {
public PersonGrid(GroupDao groupDao) { public PersonGrid(GroupDao groupDao) {
textTitle = new TextField(); textTitle = new TextField();
textTitle.setId("person.title"); textTitle.setId("event.title");
textTitle.setStyleName("title_label"); textTitle.setStyleName("title_label");
textTitle.setCaption("Veranstaltung"); textTitle.setCaption("Veranstaltung");
textTitle.setEnabled(false); textTitle.setEnabled(false);
@ -165,11 +165,15 @@ public class PersonGrid extends CustomComponent {
} }
private void selectItems(Person... items) { private void selectItems(Person... items) {
log.debug("Selecting Persons: {}", Arrays.asList(items));
MultiSelect<Person> asMultiSelect = grid.asMultiSelect(); MultiSelect<Person> asMultiSelect = grid.asMultiSelect();
asMultiSelect.deselectAll(); asMultiSelect.deselectAll();
if (items == null || items.length == 0) {
log.debug("No Persons selected.");
} else {
log.debug("Selecting Persons: {}", Arrays.asList(items));
asMultiSelect.select(items); asMultiSelect.select(items);
} }
}
public void deselectItems(Person... items) { public void deselectItems(Person... items) {
grid.asMultiSelect().deselect(items); grid.asMultiSelect().deselect(items);
@ -217,9 +221,21 @@ public class PersonGrid extends CustomComponent {
} }
public void setEvent(ClubEvent ev) { public void setEvent(ClubEvent ev) {
if (ev != null) {
setCaption(ev.getCaption()); setCaption(ev.getCaption());
setTitle(ev.getCaption()); setTitle(ev.getCaption());
selectItems(ev.getPersons().toArray(new Person[0]));
Set<Person> persons = ev.getPersons();
if (persons != null) {
selectItems(persons.toArray(new Person[0]));
} else {
selectItems(new Person[0]);
}
} else {
setCaption("");
setTitle("");
}
} }
} }

@ -5,17 +5,27 @@ import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import java.awt.GraphicsEnvironment; import java.awt.GraphicsEnvironment;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.time.YearMonth; import java.time.YearMonth;
import java.time.ZonedDateTime; import java.time.ZonedDateTime;
import java.time.format.TextStyle; import java.time.format.TextStyle;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction; import javax.persistence.EntityTransaction;
import javax.persistence.TypedQuery;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.hibernate.Session;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
@ -31,6 +41,7 @@ import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWeb
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.web.server.LocalServerPort; import org.springframework.boot.web.server.LocalServerPort;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.business.CalendarTaskRefresher;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEventBuilder; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEventBuilder;
import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef; import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.GroupDef;
@ -41,6 +52,9 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.Person;
public class VaadinClubhelperApplicationTests { public class VaadinClubhelperApplicationTests {
private static ChromeOptions options; private static ChromeOptions options;
private static final AtomicInteger idCount = new AtomicInteger();
@LocalServerPort @LocalServerPort
int port; int port;
@ -49,6 +63,7 @@ public class VaadinClubhelperApplicationTests {
private WebDriver driver; private WebDriver driver;
private ZonedDateTime now; private ZonedDateTime now;
private WebDriverWait driverWait;
@BeforeAll @BeforeAll
static void setupDriverConfiguration() { static void setupDriverConfiguration() {
@ -60,28 +75,44 @@ public class VaadinClubhelperApplicationTests {
options = new ChromeOptions(); options = new ChromeOptions();
options.setHeadless(GraphicsEnvironment.isHeadless()); options.setHeadless(GraphicsEnvironment.isHeadless());
System.setProperty(CalendarTaskRefresher.SKIP_EVENT_UPDATE, Boolean.TRUE.toString());
} }
@BeforeEach @BeforeEach
void setUp() throws Exception { void setUp() throws Exception {
now = ZonedDateTime.now(); now = ZonedDateTime.now();
insertDataIntoDatabase();
driver = new ChromeDriver(options);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(5L, TimeUnit.SECONDS);
driver.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);
driver.manage().timeouts().setScriptTimeout(10, TimeUnit.SECONDS);
driverWait = new WebDriverWait(driver, 45L);
}
public void insertDataIntoDatabase() {
TypedQuery<GroupDef> query = em.createQuery("FROM groupDef", GroupDef.class);
if (!query.getResultList().isEmpty()) {
return;
}
EntityTransaction tx = em.getTransaction(); EntityTransaction tx = em.getTransaction();
tx.begin(); tx.begin();
GroupDef g1 = new GroupDef(); GroupDef adminGroup = new GroupDef();
g1.setName("ADMIN"); adminGroup.setName("ADMIN");
GroupDef g2 = new GroupDef(); GroupDef competitorGroup = new GroupDef();
g1.setName("Wettkämpfer"); competitorGroup.setName("Wettkämpfer");
GroupDef g3 = new GroupDef(); GroupDef participantGroup = new GroupDef();
g1.setName("ACTIVE"); participantGroup.setName("ACTIVE");
em.persist(g1); em.persist(adminGroup);
em.persist(g2); em.persist(competitorGroup);
em.persist(g3); em.persist(participantGroup);
ClubEvent ev = new ClubEventBuilder().withAllDay(true).withId("id").withCaption("caption") ClubEvent ev = new ClubEventBuilder().withAllDay(true).withId("id" + idCount.incrementAndGet())
.withDescription("description").withiCalUID("iCalUID").withLocation("location") .withCaption("caption").withDescription("description").withiCalUID("iCalUID").withLocation("location")
.withOrganizerDisplayName("mtv_allgemein").withStart(now).withEnd(now.plusDays(2)).build(); .withOrganizerDisplayName("mtv_allgemein").withStart(now).withEnd(now.plusDays(2)).build();
em.persist(ev); em.persist(ev);
@ -98,26 +129,40 @@ public class VaadinClubhelperApplicationTests {
holidayEnd = now.plusDays(30); holidayEnd = now.plusDays(30);
} }
ClubEvent holiday = new ClubEventBuilder().withAllDay(true).withId("holiday").withCaption("holiday") ClubEvent holiday = new ClubEventBuilder().withAllDay(true).withId("holiday" + idCount.incrementAndGet())
.withDescription("holiday").withiCalUID("iCalUID").withLocation("") .withCaption("holiday").withDescription("holiday").withiCalUID("iCalUID").withLocation("")
.withOrganizerDisplayName("Schulferien").withStart(holidayStart).withEnd(holidayEnd).build(); .withOrganizerDisplayName("Schulferien").withStart(holidayStart).withEnd(holidayEnd).build();
em.persist(holiday); em.persist(holiday);
Person p = new Person(); Person p = new Person();
p.setPrename("prename"); p.setPrename("prename");
p.setSurname("surname"); p.setSurname("Allgroups");
p.setBirth(now.minusYears(13).toLocalDate()); p.setBirth(now.minusYears(13).toLocalDate());
p.setUsername("username"); p.setUsername("Allgroups");
p.setPassword("password"); p.setPassword("password");
p.setPersongroups(Arrays.asList(adminGroup, competitorGroup, participantGroup));
em.persist(p);
List<GroupDef> persongroups = Arrays.asList(g1, g2, g3); p = new Person();
p.setPersongroups(persongroups); p.setPrename("prename");
p.setSurname("participant");
p.setBirth(now.minusYears(10).toLocalDate());
p.setUsername("Allgroups");
p.setPassword("password");
p.setPersongroups(Arrays.asList(participantGroup));
em.persist(p); em.persist(p);
tx.commit(); p = new Person();
p.setPrename("prename");
p.setSurname("competitor");
p.setBirth(now.minusYears(10).toLocalDate());
p.setUsername("Allgroups");
p.setPassword("password");
p.setPersongroups(Arrays.asList(competitorGroup, participantGroup));
em.persist(p);
driver = new ChromeDriver(options); tx.commit();
} }
@AfterEach @AfterEach
@ -125,15 +170,38 @@ public class VaadinClubhelperApplicationTests {
if (driver != null) { if (driver != null) {
driver.close(); driver.close();
} }
org.hibernate.Session session = (Session) em;
session.doWork(connection -> {
String TABLE_NAME = "TABLE_NAME";
String[] TABLE_TYPES = { "TABLE" };
ResultSet tables = connection.getMetaData().getTables(null, null, null, TABLE_TYPES);
Set<String> tableNames = new HashSet<>();
while (tables.next()) {
tableNames.add(tables.getString(TABLE_NAME));
}
tables.close();
Statement stm = connection.createStatement();
while (tableNames.size() > 0) {
for (Iterator<String> iter = tableNames.iterator(); iter.hasNext();) {
String tableName = iter.next();
try {
stm.executeUpdate("DELETE FROM " + tableName);
iter.remove();
} catch (SQLException e) {
System.out.println("Must be later: " + tableName);
}
}
}
});
} }
@Test @Test
public void verifyMonthViewComplete() { public void verifyMonthViewComplete() {
WebDriverWait driverWait = new WebDriverWait(driver, 45L);
driver.get("http://localhost:" + port); loadApplication();
driverWait.until(dr -> dr.findElements(By.id("calendar.month")).size() > 0);
WebElement monthLabel = driver.findElement(By.id("calendar.month")); WebElement monthLabel = driver.findElement(By.id("calendar.month"));
String month = monthLabel.getText(); String month = monthLabel.getText();
@ -143,9 +211,8 @@ public class VaadinClubhelperApplicationTests {
List<WebElement> days = driver.findElements(By.className("v-calendar-day-number")); List<WebElement> days = driver.findElements(By.className("v-calendar-day-number"));
assertThat(days, Matchers.hasSize(Matchers.greaterThanOrEqualTo(now.getMonth().length(true)))); assertThat(days, Matchers.hasSize(Matchers.greaterThanOrEqualTo(now.getMonth().length(true))));
WebElement today = findElementWithContent(String.valueOf(now.getDayOfMonth())); WebElement today = driver.findElement(By.className("v-calendar-month-day-today"));
WebElement parentElement = today.findElement(By.xpath("./..")); WebElement todayContent = today.findElement(By.className("v-calendar-event-start"));
WebElement todayContent = parentElement.findElement(By.className("v-calendar-event"));
assertEquals("caption", todayContent.getText()); assertEquals("caption", todayContent.getText());
List<WebElement> allEventElements = driver.findElements(By.className("v-calendar-event")); List<WebElement> allEventElements = driver.findElements(By.className("v-calendar-event"));
@ -153,6 +220,39 @@ public class VaadinClubhelperApplicationTests {
} }
@Test
public void verifyPersonViewForEvent() {
loadApplication();
clickTodaysEvent();
By filterGroupId = By.id("person.filter.groups");
waitFor(filterGroupId);
WebElement titleElement = driver.findElement(By.id("event.title"));
assertEquals("caption", titleElement.getAttribute("value"));
// driver.findElement(By.id("person.grid")).findElement(By.tagName("table"));
}
public void clickTodaysEvent() {
WebElement today = findElementWithContent("caption");
today.click();
}
public void loadApplication() {
driver.get("http://localhost:" + port);
waitFor(By.id("calendar.month"));
}
public void waitFor(final By idMonth) {
driverWait.until(dr -> {
return dr.findElements(idMonth).size() > 0 && dr.findElements(idMonth).get(0).isDisplayed();
});
}
public WebElement findElementWithContent(String content) { public WebElement findElementWithContent(String content) {
return driver.findElement(By.xpath(String.format("//*[contains(text(), '%s')]", content))); return driver.findElement(By.xpath(String.format("//*[contains(text(), '%s')]", content)));
} }

Loading…
Cancel
Save