mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
unit test for: ensuring many relations won't be deleted on a partial stateless update when using BeanPersistAdapter
This commit is contained in:
committed by
Rob Bygrave
parent
1451ec0084
commit
b012720a5e
@@ -19,5 +19,17 @@ public class CustomerPersistAdapter extends BeanPersistAdapter {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean preUpdate(BeanPersistRequest<?> request) {
|
||||
|
||||
Customer customer = (Customer) request.getBean();
|
||||
|
||||
if (customer.getContacts() != null) {
|
||||
String test = "accessed";
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.avaje.tests.update;
|
||||
|
||||
import com.avaje.tests.model.basic.Contact;
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
@@ -11,6 +12,8 @@ import com.avaje.ebean.EbeanServer;
|
||||
import com.avaje.tests.model.basic.EBasic;
|
||||
import com.avaje.tests.model.basic.EBasic.Status;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TestStatelessUpdate extends BaseTestCase {
|
||||
|
||||
private EbeanServer server;
|
||||
@@ -100,4 +103,35 @@ public class TestStatelessUpdate extends BaseTestCase {
|
||||
// assert
|
||||
Assert.assertEquals(customer.getUpdtime().getTime(), result.getUpdtime().getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* Many relations mustn't be deleted when having a {@link com.avaje.ebean.event.BeanPersistAdapter} which is accessing this many field.
|
||||
*/
|
||||
@Test
|
||||
public void testStatelessUpdateWithPersistAdapterAndIgnoreNullValues() {
|
||||
|
||||
// arrange
|
||||
Contact contact = new Contact();
|
||||
contact.setFirstName("wobu :P");
|
||||
|
||||
Customer customer = new Customer();
|
||||
customer.setName("something");
|
||||
customer.setContacts(new ArrayList<Contact>());
|
||||
customer.getContacts().add(contact);
|
||||
|
||||
server.save(customer);
|
||||
|
||||
// act
|
||||
Customer customerWithChange = new Customer();
|
||||
customerWithChange.setId(customer.getId());
|
||||
customerWithChange.setName("new name");
|
||||
|
||||
server.update(customerWithChange, null, null, true, false);
|
||||
|
||||
Customer result = Ebean.find(Customer.class, customer.getId());
|
||||
|
||||
// assert
|
||||
Assert.assertNotNull(result.getContacts());
|
||||
Assert.assertFalse("the contacts mustn't be deleted", result.getContacts().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user