#1100 - Refactor OrmQueryPlanKey to use string expression for where

This commit is contained in:
rob bygrave
2017-08-31 02:11:49 +12:00
parent a695fb59b2
commit f83c7fdac8
54 changed files with 359 additions and 723 deletions
@@ -7,8 +7,8 @@ import io.ebean.FetchConfig;
import io.ebean.Query;
import io.ebeaninternal.server.querydefn.DefaultOrmQuery;
import io.ebeaninternal.server.querydefn.OrmQueryDetail;
import org.tests.model.basic.Order;
import org.junit.Test;
import org.tests.model.basic.Order;
import static org.assertj.core.api.Assertions.assertThat;
@@ -305,12 +305,16 @@ public class DefaultServer_createOrmQueryRequestTest extends BaseTestCase {
}
private void assertSame(OrmQueryDetail detail1, OrmQueryDetail detail2) {
assertThat(detail1.isSameByPlan(detail2)).isTrue();
assertThat(detail1.queryPlanHash()).isEqualTo(detail2.queryPlanHash());
assertThat(hash(detail1)).isEqualTo(hash(detail2));
}
private void assertDifferent(OrmQueryDetail detail1, OrmQueryDetail detail2) {
assertThat(detail1.isSameByPlan(detail2)).isFalse();
assertThat(detail1.queryPlanHash()).isNotEqualTo(detail2.queryPlanHash());
assertThat(hash(detail1)).isNotEqualTo(hash(detail2));
}
private String hash(OrmQueryDetail detail1) {
StringBuilder sb = new StringBuilder();
detail1.queryPlanHash(sb);
return sb.toString();
}
}
@@ -8,12 +8,12 @@ import java.util.Map;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class AllEqualsExpressionTest {
public class AllEqualsExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 10))).isTrue();
same(exp("a", 10), exp("a", 10));
}
@Test
@@ -25,55 +25,55 @@ public class AllEqualsExpressionTest {
@Test
public void isSameByPlan_when_diffBindValue() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 20))).isTrue();
same(exp("a", 10), exp("a", 20));
}
@Test
public void isSameByPlan_when_multiple() {
assertThat(exp("a", 10, "b", 20, "c", 30).isSameByPlan(exp("a", 10, "b", 20, "c", 30))).isTrue();
same(exp("a", 10, "b", 20, "c", 30), exp("a", 10, "b", 20, "c", 30));
}
@Test
public void isSameByPlan_when_less() {
assertThat(exp("a", 10, "b", 20, "c", 30).isSameByPlan(exp("a", 10, "b", 20))).isFalse();
different(exp("a", 10, "b", 20, "c", 30), exp("a", 10, "b", 20));
}
@Test
public void isSameByPlan_when_more() {
assertThat(exp("a", 10, "b", 20).isSameByPlan(exp("a", 10, "b", 20, "c", 30))).isFalse();
different(exp("a", 10, "b", 20), exp("a", 10, "b", 20, "c", 30));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", 10).isSameByPlan(exp("b", 10))).isFalse();
different(exp("a", 10), exp("b", 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", 10), new NoopExpression());
}
@Test
public void isSameByPlan_when_diffBindByNull_last() {
assertThat(exp("a", 10).isSameByPlan(exp("a", null))).isFalse();
different(exp("a", 10), exp("a", null));
}
@Test
public void isSameByPlan_when_diffBindByNull_first() {
assertThat(exp("a", null).isSameByPlan(exp("a", 10))).isFalse();
different(exp("a", null), exp("a", 10));
}
@Test
public void isSameByPlan_when_differentExpressionType() {
assertThat(exp("a", null).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", null), new NoopExpression());
}
@Test
@@ -1,13 +1,32 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebeaninternal.api.SpiExpression;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import org.tests.model.basic.Order;
import static org.assertj.core.api.StrictAssertions.assertThat;
public abstract class BaseExpressionTest extends BaseTestCase {
protected DefaultExpressionRequest newExpressionRequest() {
BeanDescriptor<Order> desc = getBeanDescriptor(Order.class);
return new DefaultExpressionRequest(desc);
}
protected String hash(SpiExpression expression) {
StringBuilder sb = new StringBuilder();
if (expression != null) {
expression.queryPlanHash(sb);
}
return sb.toString();
}
protected void same(SpiExpression one, SpiExpression two){
assertThat(hash(one)).isEqualTo(hash(two));
}
protected void different(SpiExpression one, SpiExpression two){
assertThat(hash(one)).isNotEqualTo(hash(two));
}
}
@@ -33,8 +33,8 @@ public class BetweenExpressionTest extends BaseExpressionTest {
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
BetweenExpression exp1 = new BetweenExpression("startDate", 3, 4);
assertThat(exp0.isSameByPlan(exp1)).isTrue();
assertThat(exp1.isSameByPlan(exp0)).isTrue();
same(exp0, exp1);
same(exp1, exp0);
}
@Test
@@ -43,8 +43,8 @@ public class BetweenExpressionTest extends BaseExpressionTest {
BetweenExpression exp0 = new BetweenExpression("startDate", 1, 2);
BetweenExpression exp1 = new BetweenExpression("endDate", 1, 2);
assertThat(exp0.isSameByPlan(exp1)).isFalse();
assertThat(exp1.isSameByPlan(exp0)).isFalse();
different(exp0, exp1);
different(exp1, exp0);
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class BetweenPropertyExpressionTest {
public class BetweenPropertyExpressionTest extends BaseExpressionTest {
@NotNull
private BetweenPropertyExpression exp(String lowProperty, String highProperty, Object value) {
@@ -21,22 +21,22 @@ public class BetweenPropertyExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "b", 10))).isTrue();
same(exp("a", "b", 10), exp("a", "b", 10));
}
@Test
public void isSameByPlan_when_diffValue() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "b", 20))).isTrue();
same(exp("a", "b", 10), exp("a", "b", 20));
}
@Test
public void isSameByPlan_when_diffProperty() {
assertThat(exp("a", "b", 10).isSameByPlan(exp("a", "c", 10))).isFalse();
different(exp("a", "b", 10), exp("a", "c", 10));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(exp("a", "b", 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "b", 10), new NoopExpression());
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class CaseInsensitiveEqualExpressionTest {
public class CaseInsensitiveEqualExpressionTest extends BaseExpressionTest {
CaseInsensitiveEqualExpression exp(String propName, String value) {
return new CaseInsensitiveEqualExpression(propName, value);
@@ -14,25 +14,25 @@ public class CaseInsensitiveEqualExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "10").isSameByPlan(exp("a", "10"))).isTrue();
same(exp("a", "10"), exp("a", "10"));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", "10").isSameByPlan(exp("a", "20"))).isTrue();
same(exp("a", "10"), exp("a", "20"));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", "10").isSameByPlan(exp("b", "10"))).isFalse();
different(exp("a", "10"), exp("b", "10"));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", "10").isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "10"), new NoopExpression());
}
@Test
@@ -1,24 +1,22 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebean.LikeType;
import io.ebean.Query;
import io.ebean.bean.EntityBean;
import io.ebean.event.BeanQueryRequest;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import io.ebeaninternal.api.ManyWhereJoins;
import io.ebeaninternal.api.SpiQuery;
import io.ebeaninternal.server.core.OrmQueryRequest;
import io.ebeaninternal.server.deploy.BeanDescriptor;
import org.junit.Test;
import org.tests.model.basic.Address;
import org.tests.model.basic.Customer;
import org.tests.model.basic.ResetBasicData;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class DefaultExampleExpressionTest extends BaseTestCase {
public class DefaultExampleExpressionTest extends BaseExpressionTest {
Customer customer() {
@@ -68,7 +66,7 @@ public class DefaultExampleExpressionTest extends BaseTestCase {
prepare(expr);
HashQueryPlanBuilder builder = new HashQueryPlanBuilder();
StringBuilder builder = new StringBuilder();
expr.queryPlanHash(builder);
TDSpiExpressionRequest req = new TDSpiExpressionRequest(customerBeanDescriptor());
@@ -100,25 +98,25 @@ public class DefaultExampleExpressionTest extends BaseTestCase {
@Test
public void isSameByPlan_whenSame() {
assertThat(prepare(exp()).isSameByPlan(prepare(exp()))).isTrue();
same(prepare(exp()), prepare(exp()));
}
@Test
public void isSameByPlan_when_diffBindValue_stillSame() {
assertThat(prepare(exp()).isSameByPlan(prepare(expDiffName()))).isTrue();
same(prepare(exp()), prepare(expDiffName()));
}
@Test
public void isSameByPlan_when_extraExpression_then_different() {
assertThat(prepare(exp()).isSameByPlan(prepare(expExtra()))).isFalse();
different(prepare(exp()), prepare(expExtra()));
}
@Test
public void isSameByPlan_when_lessExpression_then_different() {
assertThat(prepare(expExtra()).isSameByPlan(prepare(exp()))).isFalse();
different(prepare(expExtra()), prepare(exp()));
}
}
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class DefaultExpressionListTest {
public class DefaultExpressionListTest extends BaseExpressionTest {
DefaultExpressionList exp() {
@@ -13,57 +13,57 @@ public class DefaultExpressionListTest {
return new DefaultExpressionList<>(null, new DefaultExpressionFactory(true, true), null);
}
DefaultExpressionList spi(ExpressionList list) {
private DefaultExpressionList spi(ExpressionList list) {
return (DefaultExpressionList) list;
}
@Test
public void isSameByPlan_when_same() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10).eq("b", 20)))).isTrue();
same(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10).eq("b", 20)));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(new NoopExpression())).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,new NoopExpression());
}
@Test
public void isSameByPlan_when_less() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10)));
}
@Test
public void isSameByPlan_when_lessEmptyLast() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp()))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp()));
}
@Test
public void isSameByPlan_when_lessEmptyFirst() {
assertThat(spi(exp())
.isSameByPlan(spi(exp().eq("a", 10)))).isFalse();
different(spi(exp())
,spi(exp().eq("a", 10)));
}
@Test
public void isSameByPlan_when_more() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("a", 10).eq("b", 20).eq("c", 30)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("a", 10).eq("b", 20).eq("c", 30)));
}
@Test
public void isSameByPlan_when_diffProperties() {
assertThat(spi(exp().eq("a", 10).eq("b", 20))
.isSameByPlan(spi(exp().eq("c", 10).eq("b", 20)))).isFalse();
different(spi(exp().eq("a", 10).eq("b", 20))
,spi(exp().eq("c", 10).eq("b", 20)));
}
@@ -8,7 +8,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class ExistsQueryExpressionTest {
public class ExistsQueryExpressionTest extends BaseExpressionTest {
@NotNull
@@ -19,37 +19,37 @@ public class ExistsQueryExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "a", 10))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "a", 20))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 20));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(false, "a", 10))).isFalse();
different(exp(true, "a", 10), exp(false, "a", 10));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp(true, "a", 10).isSameByPlan(exp(true, "b", 10))).isFalse();
different(exp(true, "a", 10), exp(true, "b", 10));
}
@Test
public void isSameByBind_when_sameBindValues() {
assertThat(exp(true, "a", 10).isSameByBind(exp(true, "a", 10))).isTrue();
same(exp(true, "a", 10), exp(true, "a", 10));
}
@Test
public void isSameByBind_when_sameMultipleBindValues() {
assertThat(exp(true, "a", 10, "ABC", 20).isSameByBind(exp(true, "a", 10, "ABC", 20))).isTrue();
same(exp(true, "a", 10, "ABC", 20), exp(true, "a", 10, "ABC", 20));
}
@Test
@@ -6,7 +6,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class IdExpressionTest {
public class IdExpressionTest extends BaseExpressionTest {
@NotNull
@@ -17,13 +17,13 @@ public class IdExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(10).isSameByPlan(exp(10))).isTrue();
same(exp(10), exp(10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(10).isSameByPlan(exp(20))).isTrue();
same(exp(10), exp(20));
}
@Test
@@ -7,7 +7,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class IdInExpressionTest {
public class IdInExpressionTest extends BaseExpressionTest {
@NotNull
@@ -18,19 +18,19 @@ public class IdInExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp(10).isSameByPlan(exp(10))).isTrue();
same(exp(10), exp(10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp(10).isSameByPlan(exp(20))).isTrue();
same(exp(10), exp(20));
}
@Test
public void isSameByPlan_when_diffBindCount() {
assertThat(exp(10).isSameByPlan(exp(10, 20))).isFalse();
different(exp(10), exp(10, 20));
}
@Test
@@ -1,7 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebeaninternal.api.HashQueryPlanBuilder;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.ArrayList;
@@ -9,10 +7,8 @@ import java.util.Arrays;
import java.util.List;
import static org.assertj.core.api.StrictAssertions.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
public class InExpressionTest {
public class InExpressionTest extends BaseExpressionTest {
@Test
@@ -26,13 +22,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -47,13 +37,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -67,13 +51,7 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertNotEquals(b1.build(), b2.build());
different(ex1, ex2);
}
@Test
@@ -87,16 +65,10 @@ public class InExpressionTest {
ex1.prepareExpression(null);
ex2.prepareExpression(null);
HashQueryPlanBuilder b1 = new HashQueryPlanBuilder();
ex1.queryPlanHash(b1);
HashQueryPlanBuilder b2 = new HashQueryPlanBuilder();
ex2.queryPlanHash(b2);
assertEquals(b1.build(), b2.build());
same(ex1, ex2);
}
List<Integer> values(int... vals) {
private List<Integer> values(int... vals) {
ArrayList list = new ArrayList<Integer>();
for (int val : vals) {
list.add(val);
@@ -104,7 +76,6 @@ public class InExpressionTest {
return list;
}
@NotNull
private InExpression exp(String propName, boolean not, Object... values) {
InExpression ex = new InExpression(propName, Arrays.asList(values), not);
ex.prepareExpression(null);
@@ -114,31 +85,31 @@ public class InExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10))).isTrue();
same(exp("a", false, 10), exp("a", false, 10));
}
@Test
public void isSameByPlan_when_diffPropertyName() {
assertThat(exp("a", false, 10).isSameByPlan(exp("b", false, 10))).isFalse();
different(exp("a", false, 10), exp("b", false, 10));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", true, 10))).isFalse();
different(exp("a", false, 10), exp("a", true, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10, 20))).isFalse();
different(exp("a", false, 10), exp("a", false, 10, 20));
}
@Test
public void isSameByPlan_when_diffBindCount() {
assertThat(exp("a", false, 10).isSameByPlan(exp("a", false, 10, 20))).isFalse();
different(exp("a", false, 10), exp("a", false, 10, 20));
}
@Test
@@ -7,7 +7,7 @@ import java.util.Arrays;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class InQueryExpressionTest {
public class InQueryExpressionTest extends BaseExpressionTest {
@NotNull
@@ -18,31 +18,31 @@ public class InQueryExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sql", 10))).isTrue();
same(exp("name", true, "sql", 10), exp("name", true, "sql", 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sql", 20))).isTrue();
same(exp("name", true, "sql", 10), exp("name", true, "sql", 20));
}
@Test
public void isSameByPlan_when_diffNPropertyName() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("nameDiff", true, "sql", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("nameDiff", true, "sql", 10));
}
@Test
public void isSameByPlan_when_diffNot() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", false, "sql", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("name", false, "sql", 10));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp("name", true, "sql", 10).isSameByPlan(exp("name", true, "sqlDiff", 10))).isFalse();
different(exp("name", true, "sql", 10), exp("name", true, "sqlDiff", 10));
}
@Test
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class JsonPathExpressionTest {
public class JsonPathExpressionTest extends BaseExpressionTest {
@NotNull
private JsonPathExpression exp(String propertyName, String path, Op operator, Object value) {
@@ -15,37 +15,37 @@ public class JsonPathExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.EQ, 10))).isTrue();
same(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.EQ, 20))).isTrue();
same(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.EQ, 20));
}
@Test
public void isSameByPlan_when_diffPath() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "pathDiff", Op.EQ, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("a", "pathDiff", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("b", "path", Op.EQ, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("b", "path", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffOperator_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(exp("a", "path", Op.LT, 10))).isFalse();
different(exp("a", "path", Op.EQ, 10), exp("a", "path", Op.LT, 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", "path", Op.EQ, 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", "path", Op.EQ, 10), new NoopExpression());
}
@Test
@@ -5,9 +5,7 @@ import io.ebean.Expression;
import io.ebean.Junction;
import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class JunctionExpressionTest {
public class JunctionExpressionTest extends BaseExpressionTest {
Expression eq(String propName, int value) {
return Expr.eq(propName, value);
@@ -34,28 +32,28 @@ public class JunctionExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(and(exp(eq("a", 10), eq("b", 10)))
.isSameByPlan(and(exp(eq("a", 10), eq("b", 10))))).isTrue();
same(and(exp(eq("a", 10), eq("b", 10))),
and(exp(eq("a", 10), eq("b", 10))));
}
@Test
public void copyForPlanKey_isSameByPlan_when_same() {
assertThat(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey())
.isSameByPlan(and(exp(eq("a", 10), eq("b", 10))))).isTrue();
same(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey()),
and(exp(eq("a", 10), eq("b", 10))));
}
@Test
public void copyForPlanKey_isSameByPlan_when_diff() {
assertThat(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey())
.isSameByPlan(and(exp(eq("a", 10), eq("c", 10))))).isFalse();
different(and(exp(eq("a", 10), eq("b", 10)).copyForPlanKey()),
and(exp(eq("a", 10), eq("c", 10))));
}
@Test
public void isSameByPlan_when_diffType() {
assertThat(and(exp(eq("a", 10), eq("b", 10)))
.isSameByPlan(or(exp(eq("a", 10), eq("b", 10))))).isFalse();
different(and(exp(eq("a", 10), eq("b", 10))),
or(exp(eq("a", 10), eq("b", 10))));
}
}
@@ -17,36 +17,36 @@ public class LikeExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", true, LikeType.STARTS_WITH))).isTrue();
same(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", true, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffBind_then_stillSame() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "bor", true, LikeType.STARTS_WITH))).isTrue();
same(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "bor", true, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffCaseInsensitive() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", false, LikeType.STARTS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", false, LikeType.STARTS_WITH));
}
@Test
public void isSameByPlan_when_diffLikeType() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("a", "rob", true, LikeType.ENDS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("a", "rob", true, LikeType.ENDS_WITH));
}
@Test
public void isSameByPlan_when_diffProperty() {
assertThat(exp("a", "rob", true, LikeType.STARTS_WITH)
.isSameByPlan(exp("b", "rob", true, LikeType.STARTS_WITH))).isFalse();
different(exp("a", "rob", true, LikeType.STARTS_WITH)
, exp("b", "rob", true, LikeType.STARTS_WITH));
}
@@ -2,65 +2,65 @@ package io.ebeaninternal.server.expression;
import io.ebean.Expr;
import io.ebean.Expression;
import org.tests.model.basic.Order;
import org.junit.Test;
import org.tests.model.basic.Order;
import static org.assertj.core.api.Assertions.assertThat;
public class LogicExpressionTest extends BaseExpressionTest {
Expression eq(String propName, int value) {
private Expression eq(String propName, int value) {
return Expr.eq(propName, value);
}
LogicExpression and(Expression a, Expression b) {
private LogicExpression and(Expression a, Expression b) {
return new LogicExpression.And(a, b);
}
LogicExpression or(Expression a, Expression b) {
private LogicExpression or(Expression a, Expression b) {
return new LogicExpression.Or(a, b);
}
@Test
public void isSameByPlan_when_same() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("b", 10)))).isTrue();
same(and(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("b", 10)));
}
@Test
public void isSameByPlan_when_diffBind_then_stillSame() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 20), eq("b", 20)))).isTrue();
same(and(eq("a", 10), eq("b", 10))
, and(eq("a", 20), eq("b", 20)));
}
@Test
public void isSameByPlan_when_diffExp1_then_diff() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("c", 10), eq("b", 10)))).isFalse();
different(and(eq("a", 10), eq("b", 10))
, and(eq("c", 10), eq("b", 10)));
}
@Test
public void isSameByPlan_when_diffExp2_then_diff() {
assertThat(and(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("c", 10)))).isFalse();
different(and(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("c", 10)));
}
@Test
public void isSameByPlan_when_diffType_then_diff() {
assertThat(or(eq("a", 10), eq("b", 10))
.isSameByPlan(and(eq("a", 10), eq("c", 10)))).isFalse();
different(or(eq("a", 10), eq("b", 10))
, and(eq("a", 10), eq("c", 10)));
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(or(eq("a", 10), eq("b", 10))
.isSameByPlan(new NoopExpression())).isFalse();
different(or(eq("a", 10), eq("b", 10))
, new NoopExpression());
}
@Test
@@ -1,6 +1,5 @@
package io.ebeaninternal.server.expression;
import io.ebean.BaseTestCase;
import io.ebean.Ebean;
import io.ebean.Query;
import org.junit.Test;
@@ -10,7 +9,7 @@ import org.tests.model.onetoone.album.Cover;
import static org.assertj.core.api.Assertions.assertThat;
public class NoopExpressionTest extends BaseTestCase {
public class NoopExpressionTest extends BaseExpressionTest {
@Test
public void test() {
@@ -55,13 +54,13 @@ public class NoopExpressionTest extends BaseTestCase {
@Test
public void isSameByPlan_when_same() {
assertThat(new NoopExpression().isSameByPlan(new NoopExpression())).isTrue();
same(new NoopExpression(), new NoopExpression());
}
@Test
public void isSameByPlan_when_diffExpressionType() {
assertThat(new NoopExpression().isSameByPlan(null)).isFalse();
different(new NoopExpression(), null);
}
@Test
@@ -7,7 +7,7 @@ import org.junit.Test;
import static io.ebean.Expr.eq;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class NotExpressionTest {
public class NotExpressionTest extends BaseExpressionTest {
NotExpression not(Expression expression) {
@@ -17,29 +17,25 @@ public class NotExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("a", 10)))).isTrue();
same(not(eq("a", 10)), not(eq("a", 10)));
}
@Test
public void isSameByPlan_when_sameByPlan() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("a", 20)))).isTrue();
same(not(eq("a", 10)), not(eq("a", 20)));
}
@Test
public void isSameByPlan_when_different() {
assertThat(not(eq("a", 10))
.isSameByPlan(not(eq("b", 10)))).isFalse();
different(not(eq("a", 10)), not(eq("b", 10)));
}
@Test
public void isSameByPlan_when_differentExpressionType() {
assertThat(not(eq("a", 10))
.isSameByPlan(new NoopExpression())).isFalse();
different(not(eq("a", 10)), new NoopExpression());
}
@Test
@@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class NullExpressionTest extends BaseExpressionTest {
NullExpression nullExp(String propertyName, boolean notNull) {
private NullExpression nullExp(String propertyName, boolean notNull) {
NullExpression expr = new NullExpression(propertyName, notNull);
expr.containsMany(getBeanDescriptor(Order.class), new ManyWhereJoins());
return expr;
@@ -74,22 +74,22 @@ public class NullExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_true() throws Exception {
assertThat(nullExp("customer.name", false)
.isSameByPlan(nullExp("customer.name", false))).isTrue();
same(nullExp("customer.name", false),
nullExp("customer.name", false));
}
@Test
public void isSameByPlan_false_when_notNullDiff() throws Exception {
assertThat(new NullExpression("customer.name", false)
.isSameByPlan(new NullExpression("customer.name", true))).isFalse();
different(new NullExpression("customer.name", false),
new NullExpression("customer.name", true));
}
@Test
public void isSameByPlan_false_when_propertyNameDiff() throws Exception {
assertThat(new NullExpression("customer.startDate", true)
.isSameByPlan(new NullExpression("customer.name", true))).isFalse();
different(new NullExpression("customer.startDate", true),
new NullExpression("customer.name", true));
}
}
@@ -5,7 +5,7 @@ import org.junit.Test;
import static org.assertj.core.api.StrictAssertions.assertThat;
public class RawExpressionTest {
public class RawExpressionTest extends BaseExpressionTest {
@NotNull
private RawExpression exp(String sql, Object... values) {
@@ -14,17 +14,17 @@ public class RawExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 10))).isTrue();
same(exp("a", 10), exp("a", 10));
}
@Test
public void isSameByPlan_when_diffBindValues() {
assertThat(exp("a", 10).isSameByPlan(exp("a", 20))).isTrue();
same(exp("a", 10), exp("a", 20));
}
@Test
public void isSameByPlan_when_diffSql() {
assertThat(exp("a", 10).isSameByPlan(exp("b", 10))).isFalse();
different(exp("a", 10), exp("b", 10));
}
@Test
@@ -1,14 +1,12 @@
package io.ebeaninternal.server.expression;
import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class SimpleExpressionTest extends BaseExpressionTest {
@NotNull
private SimpleExpression exp(String propertyName, Op operator, Object value) {
return new SimpleExpression(propertyName, operator, value);
}
@@ -16,31 +14,31 @@ public class SimpleExpressionTest extends BaseExpressionTest {
@Test
public void isSameByPlan_when_same() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.EQ, 10))).isTrue();
same(exp("a", Op.EQ, 10), exp("a", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffBind_same() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.EQ, 20))).isTrue();
same(exp("a", Op.EQ, 10), exp("a", Op.EQ, 20));
}
@Test
public void isSameByPlan_when_diffProperty_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("b", Op.EQ, 10))).isFalse();
different(exp("a", Op.EQ, 10), exp("b", Op.EQ, 10));
}
@Test
public void isSameByPlan_when_diffOperator_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(exp("a", Op.LT, 10))).isFalse();
different(exp("a", Op.EQ, 10), exp("a", Op.LT, 10));
}
@Test
public void isSameByPlan_when_diffType_diff() {
assertThat(exp("a", Op.EQ, 10).isSameByPlan(new NoopExpression())).isFalse();
different(exp("a", Op.EQ, 10), new NoopExpression());
}
@Test