mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add more tests for cascade save on tree structure
This commit is contained in:
@@ -3,6 +3,7 @@ package org.tests.cascade;
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Transaction;
|
||||
import org.ebeantest.LoggedSqlCollector;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -10,6 +11,11 @@ import org.tests.model.site.DataContainer;
|
||||
import org.tests.model.site.Site;
|
||||
import org.tests.model.site.SiteAddress;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class TestMultiCascadeBatch extends BaseTestCase {
|
||||
|
||||
private Transaction txn;
|
||||
@@ -26,6 +32,31 @@ public class TestMultiCascadeBatch extends BaseTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void save() {
|
||||
|
||||
Site grandparent = new Site();
|
||||
grandparent.setName("grandparent");
|
||||
Site parent = new Site();
|
||||
parent.setName("parent");
|
||||
Site child = new Site();
|
||||
child.setName("child");
|
||||
grandparent.setChildren(Collections.singletonList(parent));
|
||||
parent.setChildren(Collections.singletonList(child));
|
||||
|
||||
LoggedSqlCollector.start();
|
||||
grandparent.save();
|
||||
|
||||
final List<String> sql = LoggedSqlCollector.stop();
|
||||
|
||||
assertThat(sql).hasSize(5);
|
||||
assertThat(sql.get(0)).contains("insert into site (id, name");
|
||||
assertThat(sql.get(1)).contains("insert into site (id, name");
|
||||
assertSqlBind(sql.get(2));
|
||||
assertThat(sql.get(3)).contains("insert into site (id, name");
|
||||
assertSqlBind(sql.get(4));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleCascadeInsideTransaction() {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user