Updates, sonar settings

master
Markus Kreth 7 years ago
parent 9426a24d36
commit 2d15c82150
  1. 12
      .classpath
  2. 4
      .project
  3. 2
      .settings/com.vaadin.integration.eclipse.prefs
  4. 1
      .settings/org.eclipse.core.resources.prefs
  5. 3
      .settings/org.eclipse.jdt.core.prefs
  6. 2
      .settings/org.eclipse.wst.common.project.facet.core.xml
  7. 8
      .settings/org.sonarlint.eclipse.core.prefs
  8. 97
      pom.xml
  9. 9
      src/main/java/de/kreth/clubhelperbackend/google/GoogleBaseAdapter.java
  10. 21
      src/main/java/de/kreth/clubhelperbackend/google/calendar/CalendarAdapter.java
  11. 2
      src/main/java/de/kreth/clubhelperbackend/google/calendar/CalendarResource.java
  12. 2
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/CalendarTaskRefresher.java
  13. 33
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/business/EventBusiness.java
  14. 3
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Adress.java
  15. 3
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/data/Attendance.java
  16. 6
      src/main/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/ui/components/CalendarComponent.java
  17. 5
      src/main/resources/simplelogger.properties
  18. 2
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDaoTest.java
  19. 56
      src/test/java/de/kreth/vaadin/clubhelper/vaadinclubhelper/dao/ClubEventDataTest.java
  20. 0
      transaction.log

@ -18,18 +18,13 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/> <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/classes" path="target/generated-resources/gwt"> <classpathentry excluding="**" kind="src" output="target/classes" path="target/generated-resources/gwt">
<attributes> <attributes>
<attribute name="ignore_optional_problems" value="true"/> <attribute name="ignore_optional_problems" value="true"/>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
@ -42,5 +37,10 @@
<attribute name="test" value="true"/> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>

@ -31,12 +31,12 @@
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name> <name>org.fusesource.ide.project.RiderProjectBuilder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand> <buildCommand>
<name>org.fusesource.ide.project.RiderProjectBuilder</name> <name>org.eclipse.m2e.core.maven2Builder</name>
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>

@ -1,2 +1,2 @@
com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.4.5","8.5.1"] com.vaadin.integration.eclipse.mavenLatestVersionsUpgrade=["8.4.5","8.5.2"]
eclipse.preferences.version=1 eclipse.preferences.version=1

@ -3,4 +3,5 @@ encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8 encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8 encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8 encoding//src/test/resources=UTF-8
encoding//target/generated-resources/gwt=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

@ -1,7 +1,10 @@
eclipse.preferences.version=1 eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8 org.eclipse.jdt.core.compiler.source=1.8

@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<faceted-project> <faceted-project>
<fixed facet="wst.jsdt.web"/> <fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jpt.jpa" version="2.1"/> <installed facet="jpt.jpa" version="2.1"/>
<installed facet="wst.jsdt.web" version="1.0"/> <installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.web" version="3.1"/> <installed facet="jst.web" version="3.1"/>
<installed facet="java" version="1.8"/>
</faceted-project> </faceted-project>

@ -0,0 +1,8 @@
autoEnabled=true
eclipse.preferences.version=1
extraProperties=
fileExclusions=
idePrefixKey=
projectKey=de.kreth.vaadin.clubhelper\:vaadin-clubhelper
serverId=kreth-development.de
sqPrefixKey=

@ -10,12 +10,12 @@
<packaging>war</packaging> <packaging>war</packaging>
<name>vaadin-clubhelper</name> <name>vaadin-clubhelper</name>
<description>Demo project for Spring Boot</description> <description>Vaadin Administation Frontend for Clubhelper.</description>
<parent> <parent>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId> <artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.3.RELEASE</version> <version>2.0.6.RELEASE</version>
<relativePath /> <!-- lookup parent from repository --> <relativePath /> <!-- lookup parent from repository -->
</parent> </parent>
@ -23,15 +23,18 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<vaadin.version>8.4.4</vaadin.version> <vaadin.version>8.4.4</vaadin.version>
<google-api-version>1.23.0</google-api-version> <google-api-version>1.23.0</google-api-version>
<google-api-sheets-version>v4-rev488-1.23.0</google-api-sheets-version> <google-api-sheets-version>v4-rev488-1.23.0</google-api-sheets-version>
<google-api-calendar-version>v3-rev271-1.23.0</google-api-calendar-version> <google-api-calendar-version>v3-rev271-1.23.0</google-api-calendar-version>
<sonar.login>7af449877bbf41d707e8ae7d322b1d6e9b15a89d</sonar.login> <sonar.login>7af449877bbf41d707e8ae7d322b1d6e9b15a89d</sonar.login>
<sonar.jacoco.reportPaths>target/surefire-reports</sonar.jacoco.reportPaths> <sonar.jacoco.reportPaths>target/surefire-reports</sonar.jacoco.reportPaths>
<sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin> <sonar.java.coveragePlugin>jacoco</sonar.java.coveragePlugin>
<sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis> <sonar.dynamicAnalysis>reuseReports</sonar.dynamicAnalysis>
<sonar.jacoco.reportPath>${project.basedir}/../target/jacoco.exec</sonar.jacoco.reportPath> <sonar.jacoco.reportPath>${project.basedir}/target/jacoco.exec</sonar.jacoco.reportPath>
</properties> </properties>
@ -105,14 +108,23 @@
<artifactId>google-oauth-client-jetty</artifactId> <artifactId>google-oauth-client-jetty</artifactId>
<version>${google-api-version}</version> <version>${google-api-version}</version>
</dependency> </dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
</dependency> </dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>org.slf4j</groupId>
<artifactId>logback-classic</artifactId> <artifactId>slf4j-simple</artifactId>
</dependency> </dependency>
<!-- <dependency> -->
<!-- <groupId>ch.qos.logback</groupId> -->
<!-- <artifactId>logback-classic</artifactId> -->
<!-- </dependency> -->
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
@ -125,14 +137,19 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.h2database</groupId> <groupId>org.junit.jupiter</groupId>
<artifactId>h2</artifactId> <artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>commons-io</groupId> <groupId>org.junit.vintage</groupId>
<artifactId>commons-io</artifactId> <artifactId>junit-vintage-engine</artifactId>
<version>2.6</version> <scope>test</scope>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.hibernate</groupId> <groupId>org.hibernate</groupId>
@ -145,8 +162,28 @@
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>javax.xml.bind</groupId>
<artifactId>slf4j-simple</artifactId> <artifactId>jaxb-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.4.0-b180830.0438</version>
</dependency> </dependency>
</dependencies> </dependencies>
@ -168,7 +205,18 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId> <artifactId>spring-boot-maven-plugin</artifactId>
</plugin> </plugin>
<!-- <plugin> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-compiler-plugin</artifactId> -->
<!-- <version>3.8.0</version> -->
<!-- <dependencies> -->
<!-- <dependency> -->
<!-- <groupId>org.ow2.asm</groupId> -->
<!-- <artifactId>asm</artifactId> -->
<!-- <version>6.2</version> -->
<!-- </dependency> -->
<!-- </dependencies> -->
<!-- </plugin> -->
<plugin> <plugin>
<groupId>com.vaadin</groupId> <groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId> <artifactId>vaadin-maven-plugin</artifactId>
@ -189,6 +237,24 @@
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
-javaagent:${sonar.jacoco.jar}=destfile=${sonar.jacoco.reportPath}
</argLine>
<!-- <test>**/*.java</test> -->
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.1</version>
</dependency>
</dependencies>
</plugin>
<plugin> <plugin>
<groupId>org.jacoco</groupId> <groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId> <artifactId>jacoco-maven-plugin</artifactId>
@ -223,6 +289,11 @@
<id>vaadin-addons</id> <id>vaadin-addons</id>
<url>http://maven.vaadin.com/vaadin-addons</url> <url>http://maven.vaadin.com/vaadin-addons</url>
</repository> </repository>
<repository>
<id>jvnet-nexus-staging</id>
<url>http://maven.java.net/content/repositories/staging/</url>
<layout>default</layout>
</repository>
</repositories> </repositories>
</project> </project>

@ -60,9 +60,10 @@ public abstract class GoogleBaseAdapter {
} }
protected void checkRefreshToken(String serverName) throws IOException { protected void checkRefreshToken(String serverName) throws IOException {
synchronized (SCOPES) {
if (credential == null) { if (credential == null) {
credential = authorize(serverName); credential = authorize(serverName);
}
} }
if ((credential.getExpiresInSeconds() != null if ((credential.getExpiresInSeconds() != null
@ -87,7 +88,7 @@ public abstract class GoogleBaseAdapter {
* @return an authorized Credential object. * @return an authorized Credential object.
* @throws IOException * @throws IOException
*/ */
private synchronized Credential authorize(String serverName) private Credential authorize(String serverName)
throws IOException { throws IOException {
if (credential != null && (credential.getExpiresInSeconds() != null if (credential != null && (credential.getExpiresInSeconds() != null
&& credential.getExpiresInSeconds() < 3600)) { && credential.getExpiresInSeconds() < 3600)) {

@ -74,8 +74,8 @@ public class CalendarAdapter extends GoogleBaseAdapter {
throw new IllegalStateException( throw new IllegalStateException(
"Calendar " + calendarSummary + " not found!"); "Calendar " + calendarSummary + " not found!");
} }
Calendar cal = service.calendars().get(calendarId).execute();
return cal; return service.calendars().get(calendarId).execute();
} }
public List<Event> getAllEvents(String serverName) public List<Event> getAllEvents(String serverName)
@ -110,8 +110,8 @@ public class CalendarAdapter extends GoogleBaseAdapter {
oldestCal.add(java.util.Calendar.MONTH, -1); oldestCal.add(java.util.Calendar.MONTH, -1);
oldestCal.add(java.util.Calendar.YEAR, -1); oldestCal.add(java.util.Calendar.YEAR, -1);
oldestCal.add(java.util.Calendar.HOUR_OF_DAY, -1); oldestCal.add(java.util.Calendar.HOUR_OF_DAY, -1);
final long oldest = oldestCal.getTimeInMillis();
return oldest; return oldestCal.getTimeInMillis();
} }
List<CalendarListEntry> getCalendarList(String serverName) List<CalendarListEntry> getCalendarList(String serverName)
@ -154,18 +154,17 @@ public class CalendarAdapter extends GoogleBaseAdapter {
public void run() { public void run() {
try { try {
log.debug("Fetching events of calendar \"" + summary + "\""); log.debug("Fetching events of calendar \"{}\"", summary);
Calendar calendar = getCalendarBySummaryName(items, summary); Calendar calendar = getCalendarBySummaryName(items, summary);
DateTime timeMin = new DateTime(oldest); DateTime timeMin = new DateTime(oldest);
List<Event> items = service.events().list(calendar.getId()) List<Event> eventItems = service.events().list(calendar.getId())
.setTimeMin(timeMin).execute().getItems(); .setTimeMin(timeMin).execute().getItems();
items.forEach(item -> item.set("colorClass", colorClass)); eventItems.forEach(item -> item.set("colorClass", colorClass));
events.addAll(items); events.addAll(eventItems);
log.debug("Added " + items.size() + " Events for \"" + summary log.debug("Added {} Events for \"{}\"", eventItems.size(), summary);
+ "\"");
} catch (IOException e) { } catch (IOException e) {
log.error("Unable to fetch Events from " + summary, e); log.error("Unable to fetch Events from {}", summary, e);
} }
} }
} }

@ -60,7 +60,7 @@ public class CalendarResource {
return new ArrayList<>(configs.values()); return new ArrayList<>(configs.values());
} }
public class CalendarKonfig { public static class CalendarKonfig {
private String name; private String name;
private String color; private String color;

@ -17,7 +17,7 @@ import de.kreth.vaadin.clubhelper.vaadinclubhelper.data.ClubEvent;
@Component @Component
public class CalendarTaskRefresher { public class CalendarTaskRefresher {
private static final long RATE = 1000 * 60 * 10; private static final long RATE = 1000L * 60 * 10;
private final Logger log = LoggerFactory.getLogger(getClass()); private final Logger log = LoggerFactory.getLogger(getClass());
@Autowired @Autowired

@ -4,6 +4,7 @@ import java.io.BufferedWriter;
import java.io.File; import java.io.File;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -41,7 +42,7 @@ public class EventBusiness {
if (forceRefresh == false) { if (forceRefresh == false) {
List<ClubEvent> list = dao.listAll(); List<ClubEvent> list = dao.listAll();
log.trace("Returning events from database: {}"); log.trace("Returning events from database: {}", list);
return list; return list;
} }
@ -54,12 +55,11 @@ public class EventBusiness {
List<ClubEvent> list = new ArrayList<>(); List<ClubEvent> list = new ArrayList<>();
try { try {
if (forceRefresh) {
File f = new File("google_events.json");
f.delete();
out = new BufferedWriter(new FileWriter(f));
} File f = new File("google_events.json");
Files.delete(f.toPath());
out = new BufferedWriter(new FileWriter(f));
String remoteHost = "localhost"; String remoteHost = "localhost";
CalendarAdapter adapter = new CalendarAdapter(); CalendarAdapter adapter = new CalendarAdapter();
List<com.google.api.services.calendar.model.Event> events = adapter List<com.google.api.services.calendar.model.Event> events = adapter
@ -71,24 +71,25 @@ public class EventBusiness {
out.newLine(); out.newLine();
} }
if ("cancelled".equals(ev.getStatus()) == false) { if ("cancelled".equals(ev.getStatus())) {
list.add(ClubEvent.parse(ev));
} else {
log.debug("Cancelled: {}", ev.getSummary()); log.debug("Cancelled: {}", ev.getSummary());
} else {
list.add(ClubEvent.parse(ev));
} }
} }
} catch (GeneralSecurityException | IOException } catch (GeneralSecurityException | IOException
| InterruptedException e) { | InterruptedException e) {
log.error("Error loading events from google.", e); log.error("Error loading events from google.", e);
} } finally {
if (out != null) {
if (out != null) { try {
try { out.close();
out.close(); } catch (IOException e) {
} catch (IOException e) { log.error("Error writing File", e);
log.error("Error writing File", e); }
} }
} }
return Collections.unmodifiableList(list); return Collections.unmodifiableList(list);
} }

@ -40,9 +40,6 @@ public class Adress implements Serializable {
@ManyToOne @ManyToOne
private Person person; private Person person;
public Adress() {
}
public int getId() { public int getId() {
return this.id; return this.id;
} }

@ -36,9 +36,6 @@ public class Attendance implements Serializable {
@ManyToOne @ManyToOne
private Person person; private Person person;
public Attendance() {
}
public int getId() { public int getId() {
return this.id; return this.id;
} }

@ -24,7 +24,7 @@ public class CalendarComponent extends CustomComponent {
private static final long serialVersionUID = -9152173211931554059L; private static final long serialVersionUID = -9152173211931554059L;
private DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uu"); private transient DateTimeFormatter dfMonth = DateTimeFormatter.ofPattern("MMMM uu");
private Label monthName; private Label monthName;
@ -41,8 +41,6 @@ public class CalendarComponent extends CustomComponent {
.withMonth(Month.from(LocalDateTime.now())); .withMonth(Month.from(LocalDateTime.now()));
calendar.setCaption("Events"); calendar.setCaption("Events");
calendar.setSizeFull(); calendar.setSizeFull();
// calendar.setHandler(this::onNextMonth);
// calendar.setHandler(this::onPrevMonth);
updateMonthText(calendar.getStartDate()); updateMonthText(calendar.getStartDate());
@ -76,7 +74,7 @@ public class CalendarComponent extends CustomComponent {
calendar.markAsDirty(); calendar.markAsDirty();
} }
class ClubEventProvider extends BasicItemProvider<ClubEvent> { static class ClubEventProvider extends BasicItemProvider<ClubEvent> {
private static final long serialVersionUID = -5415397258827236704L; private static final long serialVersionUID = -5415397258827236704L;

@ -1,2 +1,3 @@
org.slf4j.simpleLogger.defaultLogLevel = trace org.slf4j.simpleLogger.defaultLogLevel = warn
log4j.logger.org.hibernate.type=trace log4j.logger.org.hibernate.type=info
log4j.logger.org.jboss.logging=warn

@ -7,8 +7,8 @@ import java.time.ZonedDateTime;
import java.util.List; import java.util.List;
import org.hibernate.query.Query; import org.hibernate.query.Query;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

@ -42,6 +42,27 @@ public class ClubEventDataTest extends AbstractDatabaseTest {
return p; return p;
} }
public List<Person> insertPersons(int count) {
List<Person> inserted = new ArrayList<>();
Transaction tx = session.beginTransaction();
for (int i=0; i<count; i++) {
Person p = new Person();
p.setPrename("prename_" + i);
p.setSurname("surname_" + i);
p.setBirth(new Date());
session.save(p);
inserted.add(p);
}
tx.commit();
for (Person p: inserted) {
assertTrue("not saved: " + p , p.getId()>0);
}
return inserted;
}
@Test @Test
public void testInsertEvent() { public void testInsertEvent() {
ClubEvent ev = creteEvent(); ClubEvent ev = creteEvent();
@ -155,6 +176,41 @@ public class ClubEventDataTest extends AbstractDatabaseTest {
assertEquals(2, entries.size()); assertEquals(2, entries.size());
} }
@Test
public void testChangeEventParticipantsRapidly() {
ClubEvent ev = creteEvent();
ev.setPersons(new HashSet<>());
Transaction tx = session.beginTransaction();
session.save(ev);
tx.commit();
ev = session.byId(ClubEvent.class).load(ev.getId());
List<Person> persons = insertPersons(6);
for (Person p: persons) {
ev.getPersons().add(p);
tx = session.beginTransaction();
session.merge(ev);
tx.commit();
}
ev.getPersons().remove(persons.get(2));
tx = session.beginTransaction();
session.merge(ev);
tx.commit();
ev.getPersons().remove(persons.get(4));
tx = session.beginTransaction();
session.merge(ev);
tx.commit();
ev.getPersons().add(persons.get(2));
ev.getPersons().add(persons.get(4));
tx = session.beginTransaction();
session.merge(ev);
tx.commit();
List<ClubeventHasPerson> result = loadEventPersons();
assertEquals(6, result.size());
}
private ClubEvent creteEvent() { private ClubEvent creteEvent() {
ClubEvent ev = ClubEventBuilder.builder().withId("id").withAllDay(true) ClubEvent ev = ClubEventBuilder.builder().withId("id").withAllDay(true)
.withCaption("caption").withDescription("description") .withCaption("caption").withDescription("description")

Loading…
Cancel
Save