mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
unit tests for: stateless updates which fails when executing without changes
This commit is contained in:
committed by
Rob Bygrave
parent
a22496a57d
commit
0d2101ca7c
@@ -1,5 +1,8 @@
|
||||
package com.avaje.tests.update;
|
||||
|
||||
import com.avaje.tests.model.basic.Customer;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.avaje.ebean.BaseTestCase;
|
||||
@@ -10,14 +13,19 @@ import com.avaje.tests.model.basic.EBasic.Status;
|
||||
|
||||
public class TestStatelessUpdate extends BaseTestCase {
|
||||
|
||||
private EbeanServer server;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
server = Ebean.getServer(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
// GlobalProperties.put("ebean.defaultUpdateNullProperties", "true");
|
||||
// GlobalProperties.put("ebean.defaultDeleteMissingChildren", "false");
|
||||
|
||||
EbeanServer server = Ebean.getServer(null);
|
||||
|
||||
EBasic e = new EBasic();
|
||||
e.setName("something");
|
||||
e.setStatus(Status.NEW);
|
||||
@@ -38,4 +46,58 @@ public class TestStatelessUpdate extends BaseTestCase {
|
||||
server.update(updateDeflt);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* I am expecting that Ebean detects there aren't any changes and don't execute any query.
|
||||
* Currently a {@link javax.persistence.PersistenceException} with message 'Invalid value "null" for parameter "SQL"' is thrown.
|
||||
*/
|
||||
@Test
|
||||
public void testWithoutChangesAndIgnoreNullValues() {
|
||||
// arrange
|
||||
EBasic basic = new EBasic();
|
||||
basic.setName("something");
|
||||
basic.setStatus(Status.NEW);
|
||||
basic.setDescription("wow");
|
||||
|
||||
server.save(basic);
|
||||
|
||||
// act
|
||||
EBasic basicWithoutChanges = new EBasic();
|
||||
basicWithoutChanges.setId(basic.getId());
|
||||
server.update(basicWithoutChanges, null, null, true, false);
|
||||
|
||||
// assert
|
||||
// Nothing to check, simply no exception should occur
|
||||
// maybe ensure that no update has been executed
|
||||
}
|
||||
|
||||
/**
|
||||
* Nice to have:
|
||||
* <br />
|
||||
* Assuming we have a Version column, it will always be generated an Update despite we have nothing to update.
|
||||
* It would be nice that this would be recognized and no update would happen.
|
||||
* <br />
|
||||
* <br />
|
||||
* This feature already works for normal Updates!
|
||||
* <br />
|
||||
* see: {@link com.avaje.tests.update.TestUpdatePartial#testWithoutChangesAndVersionColumn()}
|
||||
*/
|
||||
@Test
|
||||
public void testWithoutChangesAndVersionColumnAndIgnoreNullValues() {
|
||||
// arrange
|
||||
Customer customer = new Customer();
|
||||
customer.setName("something");
|
||||
|
||||
server.save(customer);
|
||||
|
||||
// act
|
||||
Customer customerWithoutChanges = new Customer();
|
||||
customerWithoutChanges.setId(customer.getId());
|
||||
server.update(customerWithoutChanges, null, null, true, false);
|
||||
|
||||
Customer result = Ebean.find(Customer.class, customer.getId());
|
||||
|
||||
// assert
|
||||
Assert.assertEquals(customer.getUpdtime().getTime(), result.getUpdtime().getTime());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,4 +39,23 @@ public class TestUpdatePartial extends BaseTestCase {
|
||||
Ebean.save(c3);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* If we have no changes detected, don't execute an Update and don't update the Version column.
|
||||
*/
|
||||
@Test
|
||||
public void testWithoutChangesAndVersionColumn() {
|
||||
// arrange
|
||||
Customer customer = new Customer();
|
||||
customer.setName("something");
|
||||
|
||||
Ebean.save(customer);
|
||||
|
||||
// act
|
||||
Customer customerWithoutChanges = Ebean.find(Customer.class, customer.getId());
|
||||
Ebean.save(customerWithoutChanges);
|
||||
|
||||
// assert
|
||||
Assert.assertEquals(customer.getUpdtime().getTime(), customerWithoutChanges.getUpdtime().getTime());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user