mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-13 06:42:57 +00:00
Test only change - refactor update TestBeanState
This commit is contained in:
1 parent
0be98d7989
commit
dd080c5933
2 files changed
+73
-74
No files matched your search
@@ -0,0 +1,73 @@
|
|||||||
|
package org.tests.batchload;
|
||||||
|
|
||||||
|
import io.ebean.BaseTestCase;
|
||||||
|
import io.ebean.BeanState;
|
||||||
|
import io.ebean.DB;
|
||||||
|
import io.ebean.bean.EntityBean;
|
||||||
|
import io.ebean.bean.EntityBeanIntercept;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.tests.model.basic.Customer;
|
||||||
|
import org.tests.model.basic.ResetBasicData;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
|
||||||
|
public class TestBeanState extends BaseTestCase {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void test() {
|
||||||
|
|
||||||
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
List<Customer> custs = DB.find(Customer.class).findList();
|
||||||
|
|
||||||
|
Customer customer = DB.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
||||||
|
.setUseCache(false)
|
||||||
|
.findOne();
|
||||||
|
|
||||||
|
BeanState beanState = DB.getBeanState(customer);
|
||||||
|
assertFalse(beanState.isNew());
|
||||||
|
assertFalse(beanState.isDirty());
|
||||||
|
assertFalse(beanState.isNewOrDirty());
|
||||||
|
assertNotNull(beanState.getLoadedProps());
|
||||||
|
|
||||||
|
customer.setName("dirtyNameProp");
|
||||||
|
assertTrue(beanState.isDirty());
|
||||||
|
assertThat(beanState.getChangedProps()).containsOnly("name");
|
||||||
|
|
||||||
|
EntityBeanIntercept ebi = ((EntityBean) customer)._ebean_getIntercept();
|
||||||
|
boolean[] dirtyProperties = ebi.getDirtyProperties();
|
||||||
|
for (int i = 0; i < dirtyProperties.length; i++) {
|
||||||
|
if (dirtyProperties[i]) {
|
||||||
|
String dirtyPropertyName = ebi.getProperty(i);
|
||||||
|
assertEquals("name", dirtyPropertyName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customer.setStatus(Customer.Status.INACTIVE);
|
||||||
|
|
||||||
|
assertTrue(beanState.isDirty());
|
||||||
|
assertThat(beanState.getChangedProps()).containsOnly("name", "status");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setDisableLazyLoad_expect_lazyLoadingDisabled() {
|
||||||
|
|
||||||
|
ResetBasicData.reset();
|
||||||
|
|
||||||
|
List<Customer> custs = DB.find(Customer.class).order("id").findList();
|
||||||
|
|
||||||
|
Customer customer = DB.find(Customer.class)
|
||||||
|
.setId(custs.get(0).getId())
|
||||||
|
.select("id")
|
||||||
|
.setUseCache(false)
|
||||||
|
.findOne();
|
||||||
|
|
||||||
|
BeanState beanState = DB.getBeanState(customer);
|
||||||
|
beanState.setDisableLazyLoad(true);
|
||||||
|
assertNull(customer.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,74 +0,0 @@
|
|||||||
package org.tests.batchload;
|
|
||||||
|
|
||||||
import io.ebean.BaseTestCase;
|
|
||||||
import io.ebean.BeanState;
|
|
||||||
import io.ebean.Ebean;
|
|
||||||
import io.ebean.bean.EntityBean;
|
|
||||||
import io.ebean.bean.EntityBeanIntercept;
|
|
||||||
import org.tests.model.basic.Customer;
|
|
||||||
import org.tests.model.basic.ResetBasicData;
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TestLoadOnDirty extends BaseTestCase {
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test() {
|
|
||||||
|
|
||||||
ResetBasicData.reset();
|
|
||||||
|
|
||||||
List<Customer> custs = Ebean.find(Customer.class).findList();
|
|
||||||
|
|
||||||
Customer customer = Ebean.find(Customer.class).setId(custs.get(0).getId()).select("name")
|
|
||||||
.setUseCache(false)
|
|
||||||
.findOne();
|
|
||||||
|
|
||||||
BeanState beanState = Ebean.getBeanState(customer);
|
|
||||||
Assert.assertTrue(!beanState.isNew());
|
|
||||||
Assert.assertTrue(!beanState.isDirty());
|
|
||||||
Assert.assertTrue(!beanState.isNewOrDirty());
|
|
||||||
Assert.assertNotNull(beanState.getLoadedProps());
|
|
||||||
|
|
||||||
customer.setName("dirtyNameProp");
|
|
||||||
Assert.assertTrue(beanState.isDirty());
|
|
||||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
|
||||||
Assert.assertEquals(1, beanState.getChangedProps().size());
|
|
||||||
|
|
||||||
EntityBeanIntercept ebi = ((EntityBean) customer)._ebean_getIntercept();
|
|
||||||
boolean[] dirtyProperties = ebi.getDirtyProperties();
|
|
||||||
for (int i = 0; i < dirtyProperties.length; i++) {
|
|
||||||
if (dirtyProperties[i]) {
|
|
||||||
String dirtyPropertyName = ebi.getProperty(i);
|
|
||||||
Assert.assertEquals("name", dirtyPropertyName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
customer.setStatus(Customer.Status.INACTIVE);
|
|
||||||
|
|
||||||
Assert.assertTrue(beanState.isDirty());
|
|
||||||
Assert.assertTrue(beanState.getChangedProps().contains("status"));
|
|
||||||
Assert.assertTrue(beanState.getChangedProps().contains("name"));
|
|
||||||
Assert.assertEquals(2, beanState.getChangedProps().size());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testDisableLazyLoad() {
|
|
||||||
|
|
||||||
ResetBasicData.reset();
|
|
||||||
|
|
||||||
List<Customer> custs = Ebean.find(Customer.class).order("id").findList();
|
|
||||||
|
|
||||||
Customer customer = Ebean.find(Customer.class)
|
|
||||||
.setId(custs.get(0).getId())
|
|
||||||
.select("id")
|
|
||||||
.setUseCache(false)
|
|
||||||
.findOne();
|
|
||||||
|
|
||||||
BeanState beanState = Ebean.getBeanState(customer);
|
|
||||||
beanState.setDisableLazyLoad(true);
|
|
||||||
Assert.assertNull(customer.getName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in new issue
Block a user