Failing test for OneToOne with SoftDelete join missing deleted predicate

This commit is contained in:
Rob Bygrave
2023-10-10 21:24:35 +13:00
parent 3ae4c8981e
commit 80fc0723c8
2 changed files with 106 additions and 0 deletions
@@ -0,0 +1,59 @@
package org.tests.model.softdelete;
import io.ebean.annotation.SoftDelete;
import jakarta.persistence.*;
@SuppressWarnings("unused")
@Entity
public class ESoftDelOneBOwner {
@Id
long id;
String name;
@ManyToOne
ESoftDelOneB oneb;
@SoftDelete
boolean deleted;
@Version
long version;
public ESoftDelOneBOwner(String name) {
this.name = name;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public ESoftDelOneB oneb() {
return oneb;
}
public void setOneb(ESoftDelOneB oneb) {
this.oneb = oneb;
}
public long getVersion() {
return version;
}
public void setVersion(long version) {
this.version = version;
}
}
@@ -0,0 +1,47 @@
package org.tests.softdelete;
import io.ebean.DB;
import io.ebean.test.LoggedSql;
import io.ebean.xtest.BaseTestCase;
import org.junit.jupiter.api.Test;
import org.tests.model.softdelete.ESoftDelOneA;
import org.tests.model.softdelete.ESoftDelOneB;
import org.tests.model.softdelete.ESoftDelOneBOwner;
import static org.assertj.core.api.Assertions.assertThat;
class TestSoftDeleteOtoImported extends BaseTestCase {
@Test
void extraJoinToOtoImported_expect_softDeletePredicate() {
ESoftDelOneB b = new ESoftDelOneB("xbImported");
DB.save(b);
ESoftDelOneA a = new ESoftDelOneA("xaImported");
a.setOneb(b);
DB.save(a);
ESoftDelOneBOwner co = new ESoftDelOneBOwner("xoImport");
co.setOneb(b);
DB.save(co);
LoggedSql.start();
var listResult = DB.find(ESoftDelOneBOwner.class)
.where()
.eq("oneb.onea.name", "xaImported")
.findList();
var countResult = DB.find(ESoftDelOneBOwner.class)
.where()
.eq("oneb.onea.name", "xaImported")
.findCount();
var sql = LoggedSql.stop();
assertThat(sql).hasSize(2);
assertThat(listResult).hasSize(1);
assertThat(countResult).isEqualTo(1);
assertThat(sql.get(0)).contains("and t2.deleted = ");
assertThat(sql.get(1)).contains("and t2.deleted = ");
}
}