mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
#1611 - ENH: Add inRange expression (as half open expression) ... (property >= lowerValue and property < upperValue)
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
package io.ebeaninternal.server.expression;
|
||||
|
||||
import io.ebeaninternal.api.SpiExpression;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.StrictAssertions.assertThat;
|
||||
|
||||
public class InRangeExpressionTest extends BaseExpressionTest {
|
||||
|
||||
@Test
|
||||
public void addSql() {
|
||||
|
||||
DefaultExpressionRequest expReq = newExpressionRequest();
|
||||
|
||||
InRangeExpression exp = new InRangeExpression("startDate", 1, 2);
|
||||
exp.addSql(expReq);
|
||||
|
||||
assertThat(expReq.getSql()).isEqualTo("(startDate >= ? and startDate < ?) ");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void copyForPlanKey_isSameInstance() {
|
||||
|
||||
InRangeExpression exp = new InRangeExpression("startDate", 1, 2);
|
||||
SpiExpression other = exp.copyForPlanKey();
|
||||
|
||||
assertThat(exp).isSameAs(other);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByPlan_when_properties_match() {
|
||||
|
||||
InRangeExpression exp0 = new InRangeExpression("startDate", 1, 2);
|
||||
InRangeExpression exp1 = new InRangeExpression("startDate", 3, 4);
|
||||
|
||||
same(exp0, exp1);
|
||||
same(exp1, exp0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByPlan_when_properties_do_not_match() {
|
||||
|
||||
InRangeExpression exp0 = new InRangeExpression("startDate", 1, 2);
|
||||
InRangeExpression exp1 = new InRangeExpression("endDate", 1, 2);
|
||||
|
||||
different(exp0, exp1);
|
||||
different(exp1, exp0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByBind_when_values_do_not_match() {
|
||||
|
||||
InRangeExpression exp0 = new InRangeExpression("startDate", 1, 2);
|
||||
InRangeExpression exp1 = new InRangeExpression("startDate", 1, 3);
|
||||
|
||||
assertThat(exp0.isSameByBind(exp1)).isFalse();
|
||||
assertThat(exp1.isSameByBind(exp0)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void isSameByBind_when_values_match() {
|
||||
|
||||
InRangeExpression exp0 = new InRangeExpression("startDate", 1, 2);
|
||||
InRangeExpression exp1 = new InRangeExpression("startDate", 1, 2);
|
||||
|
||||
assertThat(exp0.isSameByBind(exp1)).isTrue();
|
||||
assertThat(exp1.isSameByBind(exp0)).isTrue();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.tests.basic;
|
||||
|
||||
import io.ebean.BaseTestCase;
|
||||
import io.ebean.Ebean;
|
||||
import io.ebean.Query;
|
||||
import org.junit.Test;
|
||||
import org.tests.model.basic.Order;
|
||||
import org.tests.model.basic.ResetBasicData;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
public class TestQueryWhereInRange extends BaseTestCase {
|
||||
|
||||
@Test
|
||||
public void inRange() {
|
||||
|
||||
ResetBasicData.reset();
|
||||
|
||||
LocalDate today = LocalDate.now();
|
||||
|
||||
Query<Order> query= Ebean.find(Order.class)
|
||||
.where().inRange("orderDate", today.minusDays(7), today)
|
||||
.isNotNull("id")
|
||||
.query();
|
||||
|
||||
query.findList();
|
||||
|
||||
sqlOf(query).contains("(order_date >= ? and order_date < ?)");
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user