#566 - Refactor internals - OrmQueryDetailProperties with final FetchConfig

This commit is contained in:
Robin Bygrave committed 2016-02-17 16:33:38 +13:00
1 parent 5c6d6608ef
commit 27045baf44
11 files changed
+314 -108

No files matched your search

@@ -1,5 +1,8 @@
package com.avaje.ebeaninternal.server.querydefn;
import com.avaje.ebean.BaseTestCase;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import com.avaje.tests.model.basic.Order;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
@@ -7,7 +10,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
public class OrmQueryDetailTest {
public class OrmQueryDetailTest extends BaseTestCase {
OrmQueryDetail parse(String query) {
return new OrmQueryDetailParser(query).parse();
@@ -115,4 +118,56 @@ public class OrmQueryDetailTest {
assertThat(detail.getFetchPaths()).containsExactly("details", "customer", "details.product");
}
@Test
public void markQueryJoins_when_allowOne_expect_stillFetchJoin() {
OrmQueryDetail detail = new OrmQueryDetail();
detail.fetch("details", null, null);
detail.markQueryJoins(orderDesc(), null, true);
assertThat(detail.getChunk("details", false).isQueryFetch()).isFalse();
}
@Test
public void markQueryJoins_when_allowNone_expect_queryJoin() {
OrmQueryDetail detail = new OrmQueryDetail();
detail.fetch("details", null, null);
detail.markQueryJoins(orderDesc(), null, false);
assertThat(detail.getChunk("details", false).isQueryFetch()).isTrue();
}
@Test
public void markQueryJoins_when_allowOneButSecond_expect_queryJoin() {
OrmQueryDetail detail = new OrmQueryDetail();
detail.fetch("details", null, null);
detail.fetch("customer.contacts", null, null);
detail.markQueryJoins(orderDesc(), null, true);
assertThat(detail.getChunk("details", false).isQueryFetch()).isFalse();
assertThat(detail.getChunk("customer.contacts", false).isQueryFetch()).isTrue();
}
@Test
public void markQueryJoins_when_allowNone_expect_bothQueryJoin() {
OrmQueryDetail detail = new OrmQueryDetail();
detail.fetch("details", null, null);
detail.fetch("customer.contacts", null, null);
detail.markQueryJoins(orderDesc(), null, false);
assertThat(detail.getChunk("details", false).isQueryFetch()).isTrue();
assertThat(detail.getChunk("customer.contacts", false).isQueryFetch()).isTrue();
}
BeanDescriptor<Order> orderDesc() {
return getBeanDescriptor(Order.class);
}
}
@@ -74,7 +74,7 @@ public class OrmQueryPropertiesParserTest {
public void when_hasLazy() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy");
assertThat(res.lazyFetchBatch).isEqualTo(0);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(0);
assertThat(res.included).isNull();
}
@@ -82,7 +82,7 @@ public class OrmQueryPropertiesParserTest {
public void when_hasLazyValue() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20)");
assertThat(res.lazyFetchBatch).isEqualTo(20);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
assertThat(res.included).isNull();
}
@@ -90,7 +90,7 @@ public class OrmQueryPropertiesParserTest {
public void when_hasLazyValue_last() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("name,+lazy(20)");
assertThat(res.lazyFetchBatch).isEqualTo(20);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
assertThat(res.included).containsExactly("name");
}
@@ -98,7 +98,7 @@ public class OrmQueryPropertiesParserTest {
public void when_hasLazyValue_first() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+lazy(20),id,name");
assertThat(res.lazyFetchBatch).isEqualTo(20);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
assertThat(res.included).containsExactly("id", "name");
}
@@ -106,17 +106,16 @@ public class OrmQueryPropertiesParserTest {
public void when_allProperties() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("+query(4),+lazy(5)");
assertThat(res.lazyFetchBatch).isEqualTo(5);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(5);
assertThat(res.included).isNull();
}
@Test
public void when_everything_set() throws Exception {
OrmQueryPropertiesParser.Response res = OrmQueryPropertiesParser.parse("id, name +readonly +lazy(20) +query(30) +cache");
assertThat(res.lazyFetchBatch).isEqualTo(20);
assertThat(res.queryFetchBatch).isEqualTo(30);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(20);
assertThat(res.fetchConfig.getQueryBatchSize()).isEqualTo(30);
assertThat(res.readOnly).isTrue();
assertThat(res.cache).isTrue();
assertThat(res.included).containsExactly("id", "name");
@@ -125,8 +124,8 @@ public class OrmQueryPropertiesParserTest {
private void assertAllDefaults(OrmQueryPropertiesParser.Response res) {
assertThat(res.cache).isFalse();
assertThat(res.readOnly).isFalse();
assertThat(res.lazyFetchBatch).isEqualTo(-1);
assertThat(res.queryFetchBatch).isEqualTo(-1);
assertThat(res.fetchConfig.getLazyBatchSize()).isEqualTo(-1);
assertThat(res.fetchConfig.getQueryBatchSize()).isEqualTo(-1);
assertThat(res.included).isNull();
}
}