#1782 - ENH: Add truncate(Class<?>... types) and truncate(String... tables)

This commit is contained in:
rob bygrave committed 2019-08-10 21:40:23 +12:00
1 parent cb6f0335b1
commit bb7df71391
17 files changed
+167 -56

No files matched your search

@@ -1,6 +1,7 @@
package org.tests.model.nofk;
import io.ebean.BaseTestCase;
import io.ebean.DB;
import io.ebean.Ebean;
import io.ebean.bean.EntityBean;
import io.ebean.bean.EntityBeanIntercept;
@@ -21,9 +22,8 @@ public class Test2NoFk extends BaseTestCase {
@Before
public void setup() {
// Reset t
Ebean.find(EFile2NoFk.class).delete();
Ebean.find(EUserNoFk.class).delete();
Ebean.find(EUserNoFkSoftDel.class).delete();
DB.truncate(EFile2NoFk.class, EUserNoFk.class, EUserNoFkSoftDel.class);
assertThat(DB.find(EFile2NoFk.class).findCount()).isEqualTo(0);
// There are two user accounts persisted in our database
EUserNoFk root = new EUserNoFk();
@@ -0,0 +1,46 @@
package org.tests.model.nofk;
import io.ebean.DB;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class TestTruncate {
@Test
public void test_truncateByClass() {
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
insertRows();
assertRowCounts(1);
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
assertRowCounts(0);
}
@Test
public void test_truncateByTable() {
DB.truncate(EUserNoFkSoftDel.class, EUserNoFk.class);
insertRows();
assertRowCounts(1);
DB.truncate("euser_no_fk_soft_del", "euser_no_fk");
assertRowCounts(0);
}
private void insertRows() {
EUserNoFk root = new EUserNoFk();
root.setUserName("root");
DB.save(root);
EUserNoFkSoftDel rootSoftDel = new EUserNoFkSoftDel();
rootSoftDel.setUserName("root");
DB.save(rootSoftDel);
}
private void assertRowCounts(int expected) {
assertThat(DB.find(EUserNoFk.class).findCount()).isEqualTo(expected);
assertThat(DB.find(EUserNoFkSoftDel.class).findCount()).isEqualTo(expected);
}
}