mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
Merge branch 'feature/1656'
This commit is contained in:
@@ -809,10 +809,6 @@ public class TDSpiEbeanServer implements SpiEbeanServer {
|
||||
public void update(Object bean, Transaction t) throws OptimisticLockException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(Object bean, Transaction transaction, boolean deleteMissingChildren) throws OptimisticLockException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void insert(Object bean) {
|
||||
}
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class COOne {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@OneToMany(cascade = ALL, orphanRemoval = true)
|
||||
private List<COOneMany> children;
|
||||
|
||||
public COOne(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<COOneMany> getChildren() {
|
||||
return children;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import io.ebean.annotation.SoftDelete;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
@Entity
|
||||
public class COOneMany {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
@SoftDelete
|
||||
private boolean deleted;
|
||||
|
||||
private String name;
|
||||
|
||||
public COOneMany(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean isDeleted() {
|
||||
return deleted;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class CORoot {
|
||||
|
||||
@Id
|
||||
private long id;
|
||||
|
||||
private final String name;
|
||||
|
||||
@OneToOne(cascade = ALL, orphanRemoval = true)
|
||||
private COOne one;
|
||||
|
||||
public CORoot(String name, COOne one) {
|
||||
this.name = name;
|
||||
this.one = one;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public COOne getOne() {
|
||||
return one;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.DB;
|
||||
import io.ebean.text.json.JsonContext;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class TestCascadeOrphanStatelessUpdate extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void update() {
|
||||
|
||||
final CORoot orig = setup();
|
||||
|
||||
CORoot root = DB.find(CORoot.class, orig.getId());
|
||||
assertNotNull(root);
|
||||
assertThat(root.getOne().getChildren()).hasSize(3);
|
||||
|
||||
final JsonContext jsonContext = DB.json();
|
||||
String asJson = jsonContext.toJson(root);
|
||||
|
||||
final CORoot deserialized = jsonContext.toBean(CORoot.class, asJson);
|
||||
|
||||
final COOne one = deserialized.getOne();
|
||||
COOneMany removed0 = one.getChildren().remove(0);
|
||||
COOneMany removed1 = one.getChildren().remove(1);
|
||||
|
||||
one.getChildren().add(new COOneMany("m3"));
|
||||
one.getChildren().add(new COOneMany("m4"));
|
||||
|
||||
DB.update(deserialized);
|
||||
|
||||
CORoot saved = DB.find(CORoot.class, orig.getId());
|
||||
assertNotNull(saved);
|
||||
assertThat(saved.getOne().getChildren()).hasSize(3);
|
||||
|
||||
List<COOneMany> softDeleted = DB.find(COOneMany.class)
|
||||
.setIncludeSoftDeletes()
|
||||
.where()
|
||||
.idIn(asList(removed0.getId(), removed1.getId()))
|
||||
.findList();
|
||||
|
||||
assertThat(softDeleted).hasSize(2);
|
||||
assertThat(softDeleted.stream().map(COOneMany::getId).collect(toList()))
|
||||
.contains(removed0.getId(), removed1.getId());
|
||||
}
|
||||
|
||||
private CORoot setup() {
|
||||
COOne one = new COOne("one");
|
||||
one.getChildren().add(new COOneMany("m0"));
|
||||
one.getChildren().add(new COOneMany("m1"));
|
||||
one.getChildren().add(new COOneMany("m2"));
|
||||
|
||||
CORoot root = new CORoot("r0", one);
|
||||
DB.save(root);
|
||||
|
||||
return root;
|
||||
}
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
package org.tests.cascade;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.annotation.IgnorePlatform;
|
||||
import io.ebean.annotation.Platform;
|
||||
import io.ebean.bean.BeanCollection;
|
||||
import org.tests.model.basic.TSDetailTwo;
|
||||
import org.tests.model.basic.TSMasterTwo;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class TestPrivateOwnedNoCascadeRemove extends BaseTestCase {
|
||||
|
||||
@IgnorePlatform(Platform.NUODB)
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
TSMasterTwo m0 = new TSMasterTwo();
|
||||
m0.setName("m1");
|
||||
|
||||
m0.addDetail(new TSDetailTwo("m1 detail 1"));
|
||||
m0.addDetail(new TSDetailTwo("m1 detail 2"));
|
||||
|
||||
Ebean.save(m0);
|
||||
|
||||
TSMasterTwo master = Ebean.find(TSMasterTwo.class, m0.getId());
|
||||
List<TSDetailTwo> details = master.getDetails();
|
||||
|
||||
TSDetailTwo removedDetail = details.remove(1);
|
||||
|
||||
BeanCollection<?> bc = (BeanCollection<?>) details;
|
||||
Set<?> modifyRemovals = bc.getModifyRemovals();
|
||||
|
||||
Assert.assertNotNull(modifyRemovals);
|
||||
Assert.assertTrue(modifyRemovals.size() == 1);
|
||||
Assert.assertTrue(modifyRemovals.contains(removedDetail));
|
||||
|
||||
Ebean.save(master);
|
||||
|
||||
TSMasterTwo masterReload = Ebean.find(TSMasterTwo.class, m0.getId());
|
||||
List<TSDetailTwo> detailsReload = masterReload.getDetails();
|
||||
|
||||
// the removed bean has really been removed
|
||||
Assert.assertTrue(detailsReload.size() == 1);
|
||||
|
||||
try {
|
||||
Ebean.delete(masterReload);
|
||||
Assert.fail("delete should error");
|
||||
} catch (Exception e) {
|
||||
Assert.assertTrue("delete failed", true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,13 +1,12 @@
|
||||
package org.tests.inheritance;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToOne;
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
import static javax.persistence.FetchType.LAZY;
|
||||
|
||||
/**
|
||||
* Model class to reference an organization tree node.
|
||||
@@ -22,9 +21,8 @@ public class OrganizationTreeNode {
|
||||
|
||||
private String name;
|
||||
|
||||
@OneToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parentTreeNode")
|
||||
@OneToOne(cascade = ALL, fetch = LAZY, mappedBy = "parentTreeNode", orphanRemoval = true)
|
||||
@NotNull
|
||||
@PrivateOwned
|
||||
private OrganizationNode organizationNode;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.PERSIST;
|
||||
|
||||
@Entity
|
||||
public class AnimalShelter {
|
||||
|
||||
@@ -20,8 +19,7 @@ public class AnimalShelter {
|
||||
|
||||
String name;
|
||||
|
||||
@OneToMany(cascade = CascadeType.PERSIST, mappedBy = "shelter")
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = PERSIST, mappedBy = "shelter", orphanRemoval = true)
|
||||
List<Animal> animals;
|
||||
|
||||
public Long getId() {
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.UpdateMode;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table(name = "t_mapsuper1")
|
||||
@UpdateMode(updateChangesOnly = true)
|
||||
public class TMapSuperEntity extends TMappedSuper2 {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -1,74 +0,0 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* A basic entity to test simple things.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ts_detail_two")
|
||||
public class TSDetailTwo {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
boolean active;
|
||||
|
||||
@ManyToOne
|
||||
TSMasterTwo master;
|
||||
|
||||
public TSDetailTwo(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public TSDetailTwo() {
|
||||
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public TSMasterTwo getMaster() {
|
||||
return master;
|
||||
}
|
||||
|
||||
public void setMaster(TSMasterTwo master) {
|
||||
this.master = master;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
package org.tests.model.basic;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* A basic entity to test simple things.
|
||||
*/
|
||||
@Entity
|
||||
@Table(name = "ts_master_two")
|
||||
public class TSMasterTwo {
|
||||
|
||||
@Id
|
||||
Integer id;
|
||||
|
||||
String name;
|
||||
|
||||
String description;
|
||||
|
||||
boolean active;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL, mappedBy = "master")
|
||||
@PrivateOwned(cascadeRemove = false)
|
||||
List<TSDetailTwo> details;
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public boolean isActive() {
|
||||
return active;
|
||||
}
|
||||
|
||||
public void setActive(boolean active) {
|
||||
this.active = active;
|
||||
}
|
||||
|
||||
public List<TSDetailTwo> getDetails() {
|
||||
return details;
|
||||
}
|
||||
|
||||
public void setDetails(List<TSDetailTwo> details) {
|
||||
this.details = details;
|
||||
}
|
||||
|
||||
public void addDetail(TSDetailTwo detail) {
|
||||
if (details == null) {
|
||||
details = new ArrayList<>();
|
||||
}
|
||||
details.add(detail);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.tests.model.embedded;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Embedded;
|
||||
import javax.persistence.Entity;
|
||||
@@ -20,8 +18,7 @@ public class EEmbOuter {
|
||||
@Version
|
||||
private int updateCount;
|
||||
|
||||
@OneToMany(cascade = CascadeType.ALL)
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
List<EEmbInner> inners;
|
||||
|
||||
@Embedded
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package org.tests.model.selfref;
|
||||
|
||||
import io.ebean.annotation.PrivateOwned;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@@ -23,8 +21,7 @@ public class ResourceFile extends BaseResourceFile {
|
||||
@JoinColumn(name = "parentresourcefileid", nullable = true)
|
||||
private ResourceFile parent;
|
||||
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "parent")
|
||||
@PrivateOwned
|
||||
@OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY, mappedBy = "parent", orphanRemoval = true)
|
||||
private Set<ResourceFile> alternatives = new HashSet<>();
|
||||
|
||||
@Column(name = "name", length = 128, nullable = false)
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
package org.tests.model.softdelete;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.OneToMany;
|
||||
import java.util.List;
|
||||
|
||||
import static javax.persistence.CascadeType.ALL;
|
||||
|
||||
@Entity
|
||||
public class EsdMaster extends BaseSoftDelete {
|
||||
|
||||
String name;
|
||||
|
||||
@OneToMany(mappedBy = "master", cascade = CascadeType.ALL)
|
||||
@OneToMany(mappedBy = "master", cascade = ALL, orphanRemoval = true)
|
||||
List<EsdDetail> details;
|
||||
|
||||
public EsdMaster(String name) {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package org.tests.softdelete;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.DB;
|
||||
import io.ebeantest.LoggedSql;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.softdelete.EsdDetail;
|
||||
@@ -21,8 +21,7 @@ public class TestSoftDeleteStatelessUpdate extends BaseTestCase {
|
||||
master.getDetails().add(new EsdDetail("d2"));
|
||||
master.getDetails().add(new EsdDetail("d3"));
|
||||
|
||||
|
||||
Ebean.save(master);
|
||||
DB.save(master);
|
||||
|
||||
EsdMaster upd = new EsdMaster("m1-modified");
|
||||
upd.setId(master.getId());
|
||||
@@ -38,7 +37,7 @@ public class TestSoftDeleteStatelessUpdate extends BaseTestCase {
|
||||
|
||||
LoggedSql.start();
|
||||
|
||||
Ebean.getDefaultServer().update(upd, null, true);
|
||||
DB.update(upd);
|
||||
|
||||
List<String> sql = LoggedSql.collect();
|
||||
assertThat(sql).hasSize(5);
|
||||
@@ -47,7 +46,7 @@ public class TestSoftDeleteStatelessUpdate extends BaseTestCase {
|
||||
assertThat(sql.get(1)).contains("update esd_detail set deleted=true where master_id = ? and not");
|
||||
}
|
||||
|
||||
EsdMaster fetchedWithSoftDeletes = Ebean.find(EsdMaster.class)
|
||||
EsdMaster fetchedWithSoftDeletes = DB.find(EsdMaster.class)
|
||||
.setId(master.getId())
|
||||
.setIncludeSoftDeletes()
|
||||
.fetch("details")
|
||||
@@ -59,7 +58,7 @@ public class TestSoftDeleteStatelessUpdate extends BaseTestCase {
|
||||
assertThat(sql).hasSize(1);
|
||||
assertThat(sql.get(0)).contains("left join esd_detail t1 on t1.master_id = t0.id where t0.id = ?");
|
||||
|
||||
EsdMaster fetchedWithOutSoftDeletes = Ebean.find(EsdMaster.class)
|
||||
EsdMaster fetchedWithOutSoftDeletes = DB.find(EsdMaster.class)
|
||||
.setId(master.getId())
|
||||
.fetch("details")
|
||||
.findOne();
|
||||
|
||||
@@ -3,13 +3,12 @@ package org.tests.update;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.EbeanServer;
|
||||
import io.ebean.TransactionalTestCase;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Contact;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.EBasic;
|
||||
import org.tests.model.basic.EBasic.Status;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import javax.persistence.EntityNotFoundException;
|
||||
import java.util.ArrayList;
|
||||
@@ -20,7 +19,9 @@ import java.util.Set;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
|
||||
@@ -48,7 +49,7 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
updateAll.setId(e.getId());
|
||||
updateAll.setName("updAllProps");
|
||||
|
||||
server.update(updateAll, null, false);
|
||||
server.update(updateAll);
|
||||
|
||||
eBasic = server.find(EBasic.class, e.getId());
|
||||
assertEquals(e.getStatus(), eBasic.getStatus());
|
||||
@@ -170,14 +171,14 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
customerWithChange.setName("new name");
|
||||
|
||||
// contacts is not loaded
|
||||
Assert.assertFalse(containsContacts(customerWithChange));
|
||||
assertFalse(containsContacts(customerWithChange));
|
||||
server.update(customerWithChange);
|
||||
|
||||
Customer result = Ebean.find(Customer.class, customer.getId());
|
||||
|
||||
// assert null list was ignored (missing children not deleted)
|
||||
Assert.assertNotNull(result.getContacts());
|
||||
Assert.assertFalse("the contacts mustn't be deleted", result.getContacts().isEmpty());
|
||||
assertFalse("the contacts mustn't be deleted", result.getContacts().isEmpty());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,14 +209,14 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
customerWithChange.getContacts();
|
||||
|
||||
// contacts has been initialised to empty BeanList
|
||||
Assert.assertTrue(containsContacts(customerWithChange));
|
||||
assertTrue(containsContacts(customerWithChange));
|
||||
server.update(customerWithChange);
|
||||
|
||||
Customer result = Ebean.find(Customer.class, customer.getId());
|
||||
|
||||
// assert empty bean list was ignore (missing children not deleted)
|
||||
Assert.assertNotNull(result.getContacts());
|
||||
Assert.assertFalse("the contacts mustn't be deleted", result.getContacts().isEmpty());
|
||||
assertFalse("the contacts mustn't be deleted", result.getContacts().isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -240,14 +241,13 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
// with Ebean enhancement this loads the an empty contacts BeanList
|
||||
customerWithChange.setContacts(Collections.<Contact>emptyList());
|
||||
|
||||
Assert.assertTrue(containsContacts(customerWithChange));
|
||||
assertTrue(containsContacts(customerWithChange));
|
||||
server.update(customerWithChange);
|
||||
|
||||
Customer result = Ebean.find(Customer.class, customer.getId());
|
||||
|
||||
// assert empty bean list was ignore (missing children not deleted)
|
||||
Assert.assertNotNull(result.getContacts());
|
||||
Assert.assertTrue("the contacts were deleted", result.getContacts().isEmpty());
|
||||
assertThat(result.getContacts()).hasSize(1);
|
||||
}
|
||||
|
||||
private boolean containsContacts(Customer cust) {
|
||||
@@ -316,9 +316,7 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
updateContact1.setId(contact1.getId());
|
||||
updateContact1.setLastName("contact1-changed");
|
||||
|
||||
|
||||
Contact updateContact3 = new Contact();
|
||||
//updateContact3.setId(contact3.getId());
|
||||
updateContact3.setLastName("contact3-added");
|
||||
|
||||
Customer updateCustomer = new Customer();
|
||||
@@ -326,31 +324,25 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
updateCustomer.getContacts().add(updateContact1);
|
||||
updateCustomer.getContacts().add(updateContact3);
|
||||
|
||||
// not adding contact2 so it will get deleted
|
||||
//updateCustomer.getContacts().add(updateContact2);
|
||||
|
||||
server.update(updateCustomer);
|
||||
|
||||
|
||||
// assert
|
||||
Customer assCustomer = server.find(Customer.class, customer.getId());
|
||||
List<Contact> assContacts = assCustomer.getContacts();
|
||||
assertEquals(2, assContacts.size());
|
||||
assertThat(assContacts).hasSize(3);
|
||||
Set<Integer> ids = new LinkedHashSet<>();
|
||||
Set<String> names = new LinkedHashSet<>();
|
||||
for (Contact contact : assContacts) {
|
||||
ids.add(contact.getId());
|
||||
names.add(contact.getLastName());
|
||||
}
|
||||
Assert.assertTrue(ids.contains(contact1.getId()));
|
||||
Assert.assertTrue(ids.contains(updateContact3.getId()));
|
||||
Assert.assertFalse(ids.contains(contact2.getId()));
|
||||
|
||||
Assert.assertTrue(names.contains(updateContact1.getLastName()));
|
||||
Assert.assertTrue(names.contains(updateContact3.getLastName()));
|
||||
assertTrue(ids.contains(contact1.getId()));
|
||||
assertTrue(ids.contains(updateContact3.getId()));
|
||||
assertTrue(ids.contains(contact2.getId()));
|
||||
assertTrue(names.contains(updateContact1.getLastName()));
|
||||
assertTrue(names.contains(updateContact3.getLastName()));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testStatelessRecursiveUpdateWithChangesInDetailOnlyAnd() {
|
||||
// arrange
|
||||
@@ -383,9 +375,7 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
updateCustomer.getContacts().add(updateContact3);
|
||||
|
||||
// not adding contact2 but it won't be deleted in this case
|
||||
boolean deleteMissingChildren = false;
|
||||
server.update(updateCustomer, null, deleteMissingChildren);
|
||||
|
||||
server.update(updateCustomer);
|
||||
|
||||
// assert
|
||||
Customer assCustomer = server.find(Customer.class, customer.getId());
|
||||
@@ -400,12 +390,12 @@ public class TestStatelessUpdate extends TransactionalTestCase {
|
||||
ids.add(contact.getId());
|
||||
names.add(contact.getLastName());
|
||||
}
|
||||
Assert.assertTrue(ids.contains(contact1.getId()));
|
||||
Assert.assertTrue(ids.contains(updateContact3.getId()));
|
||||
Assert.assertTrue(ids.contains(contact2.getId()));
|
||||
assertTrue(ids.contains(contact1.getId()));
|
||||
assertTrue(ids.contains(updateContact3.getId()));
|
||||
assertTrue(ids.contains(contact2.getId()));
|
||||
|
||||
Assert.assertTrue(names.contains(updateContact1.getLastName()));
|
||||
Assert.assertTrue(names.contains(contact2.getLastName()));
|
||||
Assert.assertTrue(names.contains(updateContact3.getLastName()));
|
||||
assertTrue(names.contains(updateContact1.getLastName()));
|
||||
assertTrue(names.contains(contact2.getLastName()));
|
||||
assertTrue(names.contains(updateContact3.getLastName()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user