Re-add test and fix compile error

This commit is contained in:
Jonas Pöhler committed 2021-09-13 17:04:22 +02:00
1 parent 12fe54da24
commit a582db9101
2 files changed
+29 -2

No files matched your search

@@ -293,7 +293,7 @@ public final class PersistRequestBean<T> extends PersistRequest implements BeanP
private void onFailedUpdateUndoGeneratedProperties() { private void onFailedUpdateUndoGeneratedProperties() {
for (BeanProperty prop : beanDescriptor.propertiesGenUpdate()) { for (BeanProperty prop : beanDescriptor.propertiesGenUpdate()) {
Object oldVal = intercept.getOrigValue(prop.getPropertyIndex()); Object oldVal = intercept.getOrigValue(prop.propertyIndex());
prop.setValue(entityBean, oldVal); prop.setValue(entityBean, oldVal);
} }
} }
@@ -9,7 +9,11 @@ import org.tests.model.basic.UTMaster;
import javax.persistence.OptimisticLockException; import javax.persistence.OptimisticLockException;
import java.sql.Timestamp; 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 { public class TestIUDVanilla extends BaseTestCase {
@@ -79,4 +83,27 @@ public class TestIUDVanilla extends BaseTestCase {
e0.setVersion(42); e0.setVersion(42);
assertThrows(OptimisticLockException.class, () -> e0.update()); 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);
}
} }