mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Add test only for orphan removal to TestOrphanRemovalOverwrite
Using clear() and add() when the same id value is used
This commit is contained in:
@@ -28,6 +28,11 @@ public class OmBeanListChild extends Model {
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public OmBeanListChild setId(Long id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+38
-2
@@ -1,17 +1,20 @@
|
||||
package org.tests.model.orphanremoval;
|
||||
|
||||
import io.ebean.DB;
|
||||
import io.ebean.test.LoggedSql;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
public class TestOrphanRemovalOverwrite {
|
||||
class TestOrphanRemovalOverwrite {
|
||||
|
||||
@Test
|
||||
public void testOverwritingMapping() {
|
||||
void testOverwritingMapping() {
|
||||
OmBeanListParent parent = new OmBeanListParent();
|
||||
parent.save();
|
||||
|
||||
@@ -37,4 +40,37 @@ public class TestOrphanRemovalOverwrite {
|
||||
assertEquals(child, refreshedChild);
|
||||
assertEquals(childList, parent.getChildren());
|
||||
}
|
||||
|
||||
@Test
|
||||
void clearAddAll() {
|
||||
OmBeanListChild c1 = new OmBeanListChild("c1");
|
||||
OmBeanListChild c2 = new OmBeanListChild("c2");
|
||||
|
||||
OmBeanListParent parent = new OmBeanListParent();
|
||||
parent.getChildren().add(c1);
|
||||
parent.getChildren().add(c2);
|
||||
parent.save();
|
||||
|
||||
|
||||
OmBeanListChild c3 = new OmBeanListChild("c3");
|
||||
c3.setId(c1.getId());
|
||||
|
||||
OmBeanListParent p1 = DB.find(OmBeanListParent.class, parent.getId());
|
||||
List<OmBeanListChild> children = p1.getChildren();
|
||||
children.clear();
|
||||
children.add(c3);
|
||||
|
||||
LoggedSql.start();
|
||||
DB.save(p1);
|
||||
|
||||
List<String> sql = LoggedSql.stop();
|
||||
assertThat(sql).hasSize(7);
|
||||
assertThat(sql.get(0)).contains("delete from om_bean_list_child where id=?");
|
||||
assertThat(sql.get(1)).contains(" -- bind");
|
||||
assertThat(sql.get(2)).contains(" -- bind");
|
||||
assertThat(sql.get(3)).contains(" -- executeBatch()");
|
||||
assertThat(sql.get(4)).contains(" insert into om_bean_list_child");
|
||||
assertThat(sql.get(5)).contains(" -- bind");
|
||||
assertThat(sql.get(6)).contains(" -- executeBatch()");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user