No effective change - Add test for OneToOne orphanRemoval=true and String Ids (non generated ids)

This commit is contained in:
rob bygrave
2018-08-14 22:09:01 +12:00
parent 80975acfbf
commit 340b100a1a
3 changed files with 105 additions and 0 deletions
@@ -0,0 +1,19 @@
package org.tests.model.onetoone;
import javax.persistence.Entity;
import javax.persistence.Id;
@Entity
public class OtoAone {
@Id
private String id;
private String description;
public OtoAone(String id, String description){
this.id = id;
this.description = description;
}
}
@@ -0,0 +1,47 @@
package org.tests.model.onetoone;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.OneToOne;
@Entity
public class OtoAtwo {
@Id
private String id;
private String description;
@OneToOne(orphanRemoval=true, cascade = CascadeType.ALL)
private OtoAone aone;
public OtoAtwo(String id, String description){
this.id = id;
this.description = description;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public OtoAone getAone() {
return aone;
}
public void setAone(OtoAone aone) {
this.aone = aone;
}
}
@@ -0,0 +1,39 @@
package org.tests.model.onetoone;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import org.ebeantest.LoggedSqlCollector;
import org.junit.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class TestOneToOneOrphanStringId extends BaseTestCase {
@Test
public void test() {
OtoAone a = new OtoAone("a", "a test");
OtoAtwo b = new OtoAtwo("b", "b test");
b.setAone(a);
LoggedSqlCollector.start();
Ebean.save(b);
List<String> inserts = LoggedSqlCollector.current();
assertThat(inserts).hasSize(2);
assertThat(inserts.get(0)).contains("insert into oto_aone");
assertThat(inserts.get(1)).contains("insert into oto_atwo");
Ebean.delete(b);
List<String> deletes = LoggedSqlCollector.stop();
assertThat(deletes).hasSize(2);
assertThat(deletes.get(0)).contains("delete from oto_atwo");
assertThat(deletes.get(1)).contains("delete from oto_aone");
}
}