mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Re-add test and fix compile error
This commit is contained in:
@@ -9,7 +9,11 @@ import org.tests.model.basic.UTMaster;
|
||||
import javax.persistence.OptimisticLockException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class TestIUDVanilla extends BaseTestCase {
|
||||
|
||||
@@ -79,4 +83,27 @@ public class TestIUDVanilla extends BaseTestCase {
|
||||
e0.setVersion(42);
|
||||
assertThrows(OptimisticLockException.class, () -> e0.update());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOptimisticLockException() {
|
||||
UTMaster e0 = new UTMaster("optLock");
|
||||
DB.save(e0);
|
||||
|
||||
e0 = DB.find(UTMaster.class).where().eq("name", "optLock").findOne();
|
||||
UTMaster e1 = DB.find(UTMaster.class).where().eq("name", "optLock").findOne();
|
||||
|
||||
int oldVersion = e0.getVersion();
|
||||
e0.setDescription("foo");
|
||||
e0.save();
|
||||
assertThat(e0.getVersion()).isGreaterThan(oldVersion);
|
||||
|
||||
e1.setDescription("bar");
|
||||
oldVersion = e1.getVersion();
|
||||
assertThatThrownBy(e1::save).isInstanceOf(OptimisticLockException.class);
|
||||
// after optimisticLockExecption, a restore of version is expected
|
||||
assertThat(e1.getVersion()).isEqualTo(oldVersion);
|
||||
// and subsequent saves must fail
|
||||
assertThatThrownBy(e1::save).isInstanceOf(OptimisticLockException.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user