mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-19 23:02:24 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
@@ -0,0 +1,67 @@
|
||||
package org.tests.delete;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.Database;
|
||||
import io.ebean.Transaction;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.EBasicVer;
|
||||
import org.tests.model.converstation.Group;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestDeleteWithoutOptimisticLocking extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testSimpleBeanDelete_missingBean_returnsFalse() {
|
||||
|
||||
// delete by by without version loaded ... should not throw OptimisticLockException
|
||||
Contact ref = DB.reference(Contact.class, 999999);
|
||||
assertThat(DB.delete(ref)).isFalse();
|
||||
|
||||
assertThat(DB.delete(Contact.class, 999999)).isEqualTo(0);
|
||||
|
||||
// same as above but using Model.delete()
|
||||
Group modelRef = DB.reference(Group.class, 999999);
|
||||
assertThat(modelRef.delete()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleBeanDelete_existingBean_returnsTrue() {
|
||||
|
||||
EBasicVer basic = new EBasicVer("DelTest");
|
||||
DB.save(basic);
|
||||
|
||||
EBasicVer basicRef = DB.reference(EBasicVer.class, basic.getId());
|
||||
assertThat(DB.delete(basicRef)).isTrue();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSimpleBeanDelete_existingBeanWithJdbcBatch_returnsTrue() {
|
||||
|
||||
EBasicVer basic = new EBasicVer("DelTestBatch");
|
||||
DB.save(basic);
|
||||
|
||||
Database server = DB.getDefault();
|
||||
Transaction transaction = server.beginTransaction();
|
||||
try {
|
||||
transaction.setBatchMode(true);
|
||||
|
||||
// returns true even though the delete has not occurred yet
|
||||
assertThat(server.delete(DB.reference(EBasicVer.class, basic.getId()), transaction)).isTrue();
|
||||
|
||||
// returns true even though the bean does not exist
|
||||
assertThat(server.delete(DB.reference(EBasicVer.class, 999999), transaction)).isTrue();
|
||||
|
||||
transaction.commit();
|
||||
|
||||
assertThat(DB.find(EBasicVer.class, basic.getId())).isNull();
|
||||
|
||||
} finally {
|
||||
transaction.end();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user