mirror of
https://github.com/ebean-orm/ebean.git
synced 2026-11-12 22:41:35 +00:00
Refactor move tests from ebean-core to ebean-test
This commit is contained in:
1 parent
0b00a14fd3
commit
eab56d323b
1650 files changed
+185
-147
No files matched your search
@@ -0,0 +1,63 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.BeanState;
|
||||
import io.ebean.CacheMode;
|
||||
import io.ebean.DB;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.tests.model.basic.Address;
|
||||
import org.tests.model.basic.Customer;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class TestLazyLoadInCache extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void testLoadInCache() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
Map<Integer, Customer> map = DB.find(Customer.class)
|
||||
.select("id, name")
|
||||
.setBeanCacheMode(CacheMode.PUT)
|
||||
.setReadOnly(true)
|
||||
.order().asc("id")
|
||||
.findMap();
|
||||
|
||||
assertFalse(map.isEmpty());
|
||||
|
||||
Object id = map.keySet().iterator().next();
|
||||
|
||||
Customer cust1 = map.get(id);
|
||||
|
||||
Customer cust1B = DB.find(Customer.class)
|
||||
.setReadOnly(true)
|
||||
.setId(id)
|
||||
.findOne();
|
||||
|
||||
assertNotSame(cust1, cust1B);
|
||||
|
||||
Set<String> loadedProps = DB.beanState(cust1).loadedProps();
|
||||
|
||||
assertTrue(loadedProps.contains("name"));
|
||||
assertFalse(loadedProps.contains("status"));
|
||||
|
||||
cust1.getStatus();
|
||||
|
||||
// a readOnly reference
|
||||
Address billingAddress = cust1.getBillingAddress();
|
||||
BeanState billAddrState = DB.beanState(billingAddress);
|
||||
assertTrue(billAddrState.isReference());
|
||||
assertTrue(billAddrState.isReadOnly());
|
||||
|
||||
// lazy load .. no longer a reference
|
||||
billingAddress.getCity();
|
||||
assertFalse(billAddrState.isReference());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user