DATACMNS-867 - First draft.
This commit is contained in:
7
src/test/java/org/springframework/data/querydsl/QPageRequestUnitTests.java
Normal file → Executable file
7
src/test/java/org/springframework/data/querydsl/QPageRequestUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.AbstractPageRequest;
|
||||
@@ -41,7 +40,7 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
QUser user = QUser.user;
|
||||
QPageRequest pageRequest = new QPageRequest(0, 10, user.firstname.asc());
|
||||
|
||||
assertThat(pageRequest.getSort(), is(new QSort(user.firstname.asc())));
|
||||
assertThat(pageRequest.getSort()).isEqualTo(new QSort(user.firstname.asc()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,6 +49,6 @@ public class QPageRequestUnitTests extends AbstractPageRequestUnitTests {
|
||||
QUser user = QUser.user;
|
||||
QPageRequest pageRequest = new QPageRequest(0, 10, new QSort(user.firstname.asc()));
|
||||
|
||||
assertThat(pageRequest.getSort(), is(new QSort(user.firstname.asc())));
|
||||
assertThat(pageRequest.getSort()).isEqualTo(new QSort(user.firstname.asc()));
|
||||
}
|
||||
}
|
||||
|
||||
66
src/test/java/org/springframework/data/querydsl/QSortUnitTests.java
Normal file → Executable file
66
src/test/java/org/springframework/data/querydsl/QSortUnitTests.java
Normal file → Executable file
@@ -15,15 +15,13 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.querydsl.QQSortUnitTests_WrapperToWrapWrapperForUserWrapper.*;
|
||||
import static org.springframework.data.querydsl.QQSortUnitTests_WrapperToWrapWrapperForUserWrapper_WrapperForUserWrapper.*;
|
||||
import static org.springframework.data.querydsl.QQSortUnitTests_WrapperToWrapWrapperForUserWrapper_WrapperForUserWrapper_UserWrapper.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.domain.Sort.Direction;
|
||||
@@ -53,58 +51,54 @@ public class QSortUnitTests {
|
||||
new QSort((List<OrderSpecifier<?>>) null);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test // DATACMNS-402
|
||||
public void sortBySingleProperty() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc());
|
||||
|
||||
assertThat(qsort.getOrderSpecifiers().size(), is(1));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(0), is(user.firstname.asc()));
|
||||
assertThat(qsort.getOrderFor("firstname"), is(new Sort.Order(Sort.Direction.ASC, "firstname")));
|
||||
assertThat(qsort.getOrderSpecifiers()).hasSize(1);
|
||||
assertThat(qsort.getOrderSpecifiers().get(0)).isEqualTo(user.firstname.asc());
|
||||
assertThat(qsort.getOrderFor("firstname")).isEqualTo(new Sort.Order(Sort.Direction.ASC, "firstname"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyProperties() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc(), user.lastname.desc());
|
||||
|
||||
assertThat(qsort.getOrderSpecifiers().size(), is(2));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(0), is(user.firstname.asc()));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(1), is(user.lastname.desc()));
|
||||
assertThat(qsort.getOrderFor("firstname"), is(new Sort.Order(Sort.Direction.ASC, "firstname")));
|
||||
assertThat(qsort.getOrderFor("lastname"), is(new Sort.Order(Sort.Direction.DESC, "lastname")));
|
||||
assertThat(qsort.getOrderSpecifiers()).hasSize(2);
|
||||
assertThat(qsort.getOrderSpecifiers().get(0)).isEqualTo(user.firstname.asc());
|
||||
assertThat(qsort.getOrderSpecifiers().get(1)).isEqualTo(user.lastname.desc());
|
||||
assertThat(qsort.getOrderFor("firstname")).isEqualTo(new Sort.Order(Sort.Direction.ASC, "firstname"));
|
||||
assertThat(qsort.getOrderFor("lastname")).isEqualTo(new Sort.Order(Sort.Direction.DESC, "lastname"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyPropertiesWithAnd() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc()).and(new QSort(user.lastname.desc()));
|
||||
|
||||
assertThat(qsort.getOrderSpecifiers().size(), is(2));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(0), is(user.firstname.asc()));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(1), is(user.lastname.desc()));
|
||||
assertThat(qsort.getOrderFor("firstname"), is(new Sort.Order(Sort.Direction.ASC, "firstname")));
|
||||
assertThat(qsort.getOrderFor("lastname"), is(new Sort.Order(Sort.Direction.DESC, "lastname")));
|
||||
assertThat(qsort.getOrderSpecifiers()).hasSize(2);
|
||||
assertThat(qsort.getOrderSpecifiers().get(0)).isEqualTo(user.firstname.asc());
|
||||
assertThat(qsort.getOrderSpecifiers().get(1)).isEqualTo(user.lastname.desc());
|
||||
assertThat(qsort.getOrderFor("firstname")).isEqualTo(new Sort.Order(Sort.Direction.ASC, "firstname"));
|
||||
assertThat(qsort.getOrderFor("lastname")).isEqualTo(new Sort.Order(Sort.Direction.DESC, "lastname"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test // DATACMNS-402
|
||||
public void sortByMultiplyPropertiesWithAndAndVarArgs() {
|
||||
|
||||
QUser user = QUser.user;
|
||||
QSort qsort = new QSort(user.firstname.asc()).and(user.lastname.desc());
|
||||
|
||||
assertThat(qsort.getOrderSpecifiers().size(), is(2));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(0), is(user.firstname.asc()));
|
||||
assertThat((OrderSpecifier<String>) qsort.getOrderSpecifiers().get(1), is(user.lastname.desc()));
|
||||
assertThat(qsort.getOrderFor("firstname"), is(new Sort.Order(Sort.Direction.ASC, "firstname")));
|
||||
assertThat(qsort.getOrderFor("lastname"), is(new Sort.Order(Sort.Direction.DESC, "lastname")));
|
||||
assertThat(qsort.getOrderSpecifiers()).hasSize(2);
|
||||
assertThat(qsort.getOrderSpecifiers().get(0)).isEqualTo(user.firstname.asc());
|
||||
assertThat(qsort.getOrderSpecifiers().get(1)).isEqualTo(user.lastname.desc());
|
||||
assertThat(qsort.getOrderFor("firstname")).isEqualTo(new Sort.Order(Sort.Direction.ASC, "firstname"));
|
||||
assertThat(qsort.getOrderFor("lastname")).isEqualTo(new Sort.Order(Sort.Direction.DESC, "lastname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
@@ -115,8 +109,8 @@ public class QSortUnitTests {
|
||||
|
||||
Sort sort = qsort;
|
||||
|
||||
assertThat(sort.getOrderFor("firstname"), is(new Sort.Order(Sort.Direction.ASC, "firstname")));
|
||||
assertThat(sort.getOrderFor("lastname"), is(new Sort.Order(Sort.Direction.DESC, "lastname")));
|
||||
assertThat(sort.getOrderFor("firstname")).isEqualTo(new Sort.Order(Sort.Direction.ASC, "firstname"));
|
||||
assertThat(sort.getOrderFor("lastname")).isEqualTo(new Sort.Order(Sort.Direction.DESC, "lastname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-402
|
||||
@@ -126,8 +120,8 @@ public class QSortUnitTests {
|
||||
QSort sort = new QSort(user.firstname.asc());
|
||||
|
||||
Sort result = sort.and(new Sort(Direction.ASC, "lastname"));
|
||||
assertThat(result, is(Matchers.<Order> iterableWithSize(2)));
|
||||
assertThat(result, hasItems(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, "firstname")));
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result).contains(new Order(Direction.ASC, "lastname"), new Order(Direction.ASC, "firstname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-566
|
||||
@@ -137,9 +131,9 @@ public class QSortUnitTests {
|
||||
QSort sort = new QSort(user.dateOfBirth.yearMonth().asc());
|
||||
|
||||
Sort result = sort.and(new Sort(Direction.ASC, "lastname"));
|
||||
assertThat(result, is(Matchers.<Order> iterableWithSize(2)));
|
||||
assertThat(result, hasItems(new Order(Direction.ASC, "lastname"),
|
||||
new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString())));
|
||||
assertThat(result).hasSize(2);
|
||||
assertThat(result).contains(new Order(Direction.ASC, "lastname"),
|
||||
new Order(Direction.ASC, user.dateOfBirth.yearMonth().toString()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
@@ -147,7 +141,7 @@ public class QSortUnitTests {
|
||||
|
||||
QSort sort = new QSort(userWrapper.user.firstname.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "user.firstname")));
|
||||
assertThat(sort).contains(new Order(Direction.ASC, "user.firstname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
@@ -155,7 +149,7 @@ public class QSortUnitTests {
|
||||
|
||||
QSort sort = new QSort(wrapperForUserWrapper.wrapper.user.firstname.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "wrapper.user.firstname")));
|
||||
assertThat(sort).contains(new Order(Direction.ASC, "wrapper.user.firstname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-621
|
||||
@@ -163,7 +157,7 @@ public class QSortUnitTests {
|
||||
|
||||
QSort sort = new QSort(wrapperToWrapWrapperForUserWrapper.wrapperForUserWrapper.wrapper.user.firstname.asc());
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "wrapperForUserWrapper.wrapper.user.firstname")));
|
||||
assertThat(sort).contains(new Order(Direction.ASC, "wrapperForUserWrapper.wrapper.user.firstname"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-755
|
||||
@@ -173,7 +167,7 @@ public class QSortUnitTests {
|
||||
|
||||
QSort sort = new QSort(new OrderSpecifier<String>(com.querydsl.core.types.Order.ASC, path));
|
||||
|
||||
assertThat(sort, hasItems(new Order(Direction.ASC, "firstname")));
|
||||
assertThat(sort).contains(new Order(Direction.ASC, "firstname"));
|
||||
}
|
||||
|
||||
@com.querydsl.core.annotations.QueryEntity
|
||||
|
||||
11
src/test/java/org/springframework/data/querydsl/QueryDslUtilsUnitTests.java
Normal file → Executable file
11
src/test/java/org/springframework/data/querydsl/QueryDslUtilsUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.querydsl.QueryDslUtils.*;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -30,14 +29,14 @@ public class QueryDslUtilsUnitTests {
|
||||
|
||||
@Test // DATACMNS-883
|
||||
public void rendersDotPathForPathTraversalContainingAnyExpression() {
|
||||
assertThat(toDotPath(QUser.user.addresses.any().street), is("addresses.street"));
|
||||
assertThat(QueryDslUtils.toDotPath(QUser.user.addresses.any().street)).isEqualTo("addresses.street");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-941
|
||||
public void skipsIntermediateDelegates() {
|
||||
|
||||
assertThat(toDotPath(QUser.user.as(QSpecialUser.class).as(QSpecialUser.class).specialProperty),
|
||||
is("specialProperty"));
|
||||
assertThat(toDotPath(QUser.user.as(QSpecialUser.class).specialProperty), is("specialProperty"));
|
||||
assertThat(toDotPath(QUser.user.as(QSpecialUser.class).as(QSpecialUser.class).specialProperty))
|
||||
.isEqualTo("specialProperty");
|
||||
assertThat(toDotPath(QUser.user.as(QSpecialUser.class).specialProperty)).isEqualTo("specialProperty");
|
||||
}
|
||||
}
|
||||
|
||||
7
src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java
Normal file → Executable file
7
src/test/java/org/springframework/data/querydsl/QuerydslRepositoryInvokerAdapterUnitTests.java
Normal file → Executable file
@@ -20,7 +20,6 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -76,7 +75,7 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@SuppressWarnings({ "deprecation", "unchecked" })
|
||||
@SuppressWarnings("unchecked")
|
||||
public void forwardsMethodsToDelegate() {
|
||||
|
||||
adapter.hasDeleteMethod();
|
||||
@@ -97,10 +96,6 @@ public class QuerydslRepositoryInvokerAdapterUnitTests {
|
||||
adapter.invokeFindOne(any(Serializable.class));
|
||||
verify(delegate, times(1)).invokeFindOne(any(Serializable.class));
|
||||
|
||||
adapter.invokeQueryMethod(any(Method.class), any(Map.class), any(Pageable.class), any(Sort.class));
|
||||
verify(delegate, times(1)).invokeQueryMethod(any(Method.class), any(Map.class), any(Pageable.class),
|
||||
any(Sort.class));
|
||||
|
||||
adapter.invokeQueryMethod(any(Method.class), (MultiValueMap<String, String>) any(MultiValueMap.class),
|
||||
any(Pageable.class), any(Sort.class));
|
||||
verify(delegate, times(1)).invokeQueryMethod(any(Method.class),
|
||||
|
||||
9
src/test/java/org/springframework/data/querydsl/SimpleEntityPathResolverUnitTests.java
Normal file → Executable file
9
src/test/java/org/springframework/data/querydsl/SimpleEntityPathResolverUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -33,15 +32,13 @@ public class SimpleEntityPathResolverUnitTests {
|
||||
|
||||
@Test
|
||||
public void createsRepositoryFromDomainClassCorrectly() throws Exception {
|
||||
|
||||
assertThat((QUser) resolver.createPath(User.class), isA(QUser.class));
|
||||
assertThat(resolver.createPath(User.class)).isInstanceOf(QUser.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void resolvesEntityPathForInnerClassCorrectly() throws Exception {
|
||||
|
||||
assertThat((QSimpleEntityPathResolverUnitTests_NamedUser) resolver.createPath(NamedUser.class),
|
||||
isA(QSimpleEntityPathResolverUnitTests_NamedUser.class));
|
||||
assertThat(resolver.createPath(NamedUser.class)).isInstanceOf(QSimpleEntityPathResolverUnitTests_NamedUser.class);
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
69
src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java
Normal file → Executable file
69
src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsFactoryUnitTests.java
Normal file → Executable file
@@ -15,16 +15,14 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl.binding;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
@@ -37,7 +35,6 @@ import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.querydsl.core.types.dsl.StringPath;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QuerydslBindingsFactory}.
|
||||
@@ -49,8 +46,6 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
|
||||
static final TypeInformation<?> USER_TYPE = ClassTypeInformation.from(User.class);
|
||||
|
||||
public @Rule ExpectedException exception = ExpectedException.none();
|
||||
|
||||
QuerydslBindingsFactory factory;
|
||||
|
||||
@Before
|
||||
@@ -65,17 +60,19 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
Repositories repositories = mock(Repositories.class);
|
||||
|
||||
when(repositories.hasRepositoryFor(User.class)).thenReturn(true);
|
||||
when(repositories.getRepositoryFor(User.class)).thenReturn(new SampleRepo());
|
||||
when(repositories.getRepositoryFor(User.class)).thenReturn(Optional.of(new SampleRepo()));
|
||||
|
||||
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
||||
ReflectionTestUtils.setField(factory, "repositories", repositories);
|
||||
ReflectionTestUtils.setField(factory, "repositories", Optional.of(repositories));
|
||||
|
||||
QuerydslBindings bindings = factory.createBindingsFor(null, USER_TYPE);
|
||||
MultiValueBinding<Path<Object>, Object> binding = bindings
|
||||
QuerydslBindings bindings = factory.createBindingsFor(USER_TYPE, Optional.empty());
|
||||
Optional<MultiValueBinding<Path<Object>, Object>> binding = bindings
|
||||
.getBindingForPath(PropertyPathInformation.of("firstname", User.class));
|
||||
|
||||
assertThat(binding.bind((Path) QUser.user.firstname, Collections.singleton("rand")),
|
||||
is((Predicate) QUser.user.firstname.contains("rand")));
|
||||
assertThat(binding).hasValueSatisfying(it -> {
|
||||
Optional<Predicate> bind = it.bind((Path) QUser.user.firstname, Collections.singleton("rand"));
|
||||
assertThat(bind).hasValue(QUser.user.firstname.contains("rand"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -86,45 +83,34 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
when(beanFactory.getBean(SpecificBinding.class)).thenReturn(new SpecificBinding());
|
||||
|
||||
QuerydslBindingsFactory factory = new QuerydslBindingsFactory(SimpleEntityPathResolver.INSTANCE);
|
||||
ReflectionTestUtils.setField(factory, "beanFactory", beanFactory);
|
||||
ReflectionTestUtils.setField(factory, "beanFactory", Optional.of(beanFactory));
|
||||
|
||||
QuerydslBindings bindings = factory.createBindingsFor(SpecificBinding.class, USER_TYPE);
|
||||
MultiValueBinding<Path<Object>, Object> binding = bindings
|
||||
QuerydslBindings bindings = factory.createBindingsFor(USER_TYPE, Optional.of(SpecificBinding.class));
|
||||
Optional<MultiValueBinding<Path<Object>, Object>> binding = bindings
|
||||
.getBindingForPath(PropertyPathInformation.of("firstname", User.class));
|
||||
|
||||
assertThat(binding.bind((Path) QUser.user.firstname, Collections.singleton("rand")),
|
||||
is((Predicate) QUser.user.firstname.eq("RAND")));
|
||||
assertThat(binding).hasValueSatisfying(it -> {
|
||||
Optional<Predicate> bind = it.bind((Path) QUser.user.firstname, Collections.singleton("rand"));
|
||||
assertThat(bind).hasValue(QUser.user.firstname.eq("RAND"));
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void rejectsPredicateResolutionIfDomainTypeCantBeAutoDetected() {
|
||||
|
||||
exception.expect(IllegalStateException.class);
|
||||
exception.expectMessage(QuerydslPredicate.class.getSimpleName());
|
||||
exception.expectMessage("root");
|
||||
assertThatExceptionOfType(IllegalStateException.class)//
|
||||
.isThrownBy(() -> factory.createBindingsFor(ClassTypeInformation.from(ModelAndView.class), Optional.empty()))//
|
||||
.withMessageContaining(QuerydslPredicate.class.getSimpleName())//
|
||||
.withMessageContaining("root");
|
||||
|
||||
factory.createBindingsFor(null, ClassTypeInformation.from(ModelAndView.class));
|
||||
}
|
||||
|
||||
static class SpecificBinding implements QuerydslBinderCustomizer<QUser> {
|
||||
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
|
||||
bindings.bind(user.firstname).first(new SingleValueBinding<StringPath, String>() {
|
||||
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.eq(value.toUpperCase());
|
||||
}
|
||||
});
|
||||
|
||||
bindings.bind(user.lastname).first(new SingleValueBinding<StringPath, String>() {
|
||||
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.toLowerCase().eq(value);
|
||||
}
|
||||
});
|
||||
bindings.bind(user.firstname).firstOptional((path, value) -> value.map(it -> path.eq(it.toUpperCase())));
|
||||
bindings.bind(user.lastname).firstOptional((path, value) -> value.map(it -> path.toLowerCase().eq(it)));
|
||||
|
||||
bindings.excluding(user.address);
|
||||
}
|
||||
@@ -134,14 +120,7 @@ public class QuerydslBindingsFactoryUnitTests {
|
||||
|
||||
@Override
|
||||
public void customize(QuerydslBindings bindings, QUser user) {
|
||||
|
||||
bindings.bind(QUser.user.firstname).first(new SingleValueBinding<StringPath, String>() {
|
||||
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.contains(value);
|
||||
}
|
||||
});
|
||||
bindings.bind(QUser.user.firstname).firstOptional((path, value) -> value.map(it -> path.contains(it)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
101
src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java
Normal file → Executable file
101
src/test/java/org/springframework/data/querydsl/binding/QuerydslBindingsUnitTests.java
Normal file → Executable file
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl.binding;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -26,7 +27,6 @@ import org.springframework.data.querydsl.QUser;
|
||||
import org.springframework.data.querydsl.SimpleEntityPathResolver;
|
||||
import org.springframework.data.querydsl.User;
|
||||
import org.springframework.data.util.ClassTypeInformation;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
import com.querydsl.core.types.Path;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
@@ -43,13 +43,8 @@ public class QuerydslBindingsUnitTests {
|
||||
QuerydslPredicateBuilder builder;
|
||||
QuerydslBindings bindings;
|
||||
|
||||
static final SingleValueBinding<StringPath, String> CONTAINS_BINDING = new SingleValueBinding<StringPath, String>() {
|
||||
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.contains(value);
|
||||
}
|
||||
};
|
||||
static final SingleValueBinding<StringPath, String> CONTAINS_BINDING = (path, value) -> Optional
|
||||
.of(path.contains(value));
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
@@ -68,7 +63,7 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
PathInformation path = PropertyPathInformation.of("lastname", User.class);
|
||||
|
||||
assertThat(bindings.getBindingForPath(path), nullValue());
|
||||
assertThat(bindings.getBindingForPath(path)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -97,93 +92,92 @@ public class QuerydslBindingsUnitTests {
|
||||
bindings.bind(String.class).first(CONTAINS_BINDING);
|
||||
|
||||
PathInformation path = PropertyPathInformation.of("address.street", User.class);
|
||||
|
||||
assertAdapterWithTargetBinding(bindings.getBindingForPath(path), CONTAINS_BINDING);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void propertyNotExplicitlyIncludedAndWithoutTypeBindingIsInvisible() {
|
||||
public void propertyNotExplicitlyIncludedAndWithoutTypeBindingIsNotAvailable() {
|
||||
|
||||
bindings.bind(String.class).first(CONTAINS_BINDING);
|
||||
|
||||
PathInformation path = PropertyPathInformation.of("inceptionYear", User.class);
|
||||
|
||||
assertThat(bindings.getBindingForPath(path), nullValue());
|
||||
assertThat(bindings.getBindingForPath(path)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void pathIsVisibleIfTypeBasedBindingWasRegistered() {
|
||||
public void pathIsAvailableIfTypeBasedBindingWasRegistered() {
|
||||
|
||||
bindings.bind(String.class).first(CONTAINS_BINDING);
|
||||
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void explicitlyIncludedPathIsVisible() {
|
||||
public void explicitlyIncludedPathIsAvailable() {
|
||||
|
||||
bindings.including(QUser.user.inceptionYear);
|
||||
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void notExplicitlyIncludedPathIsInvisible() {
|
||||
public void notExplicitlyIncludedPathIsNotAvailable() {
|
||||
|
||||
bindings.including(QUser.user.inceptionYear);
|
||||
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void excludedPathIsInvisible() {
|
||||
public void excludedPathIsNotAvailable() {
|
||||
|
||||
bindings.excluding(QUser.user.inceptionYear);
|
||||
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("inceptionYear", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void pathIsVisibleIfNotExplicitlyExcluded() {
|
||||
public void pathIsAvailableIfNotExplicitlyExcluded() {
|
||||
|
||||
bindings.excluding(QUser.user.inceptionYear);
|
||||
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void pathIsVisibleIfItsBothBlackAndWhitelisted() {
|
||||
public void pathIsAvailableIfItsBothBlackAndWhitelisted() {
|
||||
|
||||
bindings.excluding(QUser.user.firstname);
|
||||
bindings.including(QUser.user.firstname);
|
||||
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void nestedPathIsInvisibleIfAParanetPathWasExcluded() {
|
||||
public void nestedPathIsNotAvailableIfAParanetPathWasExcluded() {
|
||||
|
||||
bindings.excluding(QUser.user.address);
|
||||
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void pathIsVisibleIfConcretePathIsVisibleButParentExcluded() {
|
||||
public void pathIsAvailableIfConcretePathIsAvailableButParentExcluded() {
|
||||
|
||||
bindings.excluding(QUser.user.address);
|
||||
bindings.including(QUser.user.address.city);
|
||||
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void isPathVisibleShouldReturnFalseWhenPartialPathContainedInExcludingAndConcretePathToDifferentPropertyIsIncluded() {
|
||||
public void isPathAvailableShouldReturnFalseWhenPartialPathContainedInExcludingAndConcretePathToDifferentPropertyIsIncluded() {
|
||||
|
||||
bindings.excluding(QUser.user.address);
|
||||
bindings.including(QUser.user.address.city);
|
||||
|
||||
assertThat(bindings.isPathAvailable("address.street", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("address.street", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -191,10 +185,10 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
bindings.including(QUser.user.firstname, QUser.user.address.street);
|
||||
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("address.street", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("lastname", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("firstname", User.class)).isTrue();
|
||||
assertThat(bindings.isPathAvailable("address.street", User.class)).isTrue();
|
||||
assertThat(bindings.isPathAvailable("lastname", User.class)).isFalse();
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class) // DATACMNS-787
|
||||
@@ -214,11 +208,11 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
PathInformation path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
|
||||
assertThat(path, is(notNullValue()));
|
||||
assertThat(bindings.isPathAvailable("city", User.class), is(true));
|
||||
assertThat(path).isNotNull();
|
||||
assertThat(bindings.isPathAvailable("city", User.class)).isTrue();
|
||||
|
||||
// Aliasing implicitly blacklists original path
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class), is(false));
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-787
|
||||
@@ -229,13 +223,13 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
PathInformation path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
|
||||
assertThat(path, is(notNullValue()));
|
||||
assertThat(bindings.isPathAvailable("city", User.class), is(true));
|
||||
assertThat(path).isNotNull();
|
||||
assertThat(bindings.isPathAvailable("city", User.class)).isTrue();
|
||||
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("address.city", User.class)).isTrue();
|
||||
|
||||
PathInformation propertyPath = bindings.getPropertyPath("address.city", ClassTypeInformation.from(User.class));
|
||||
assertThat(propertyPath, is(notNullValue()));
|
||||
assertThat(propertyPath).isNotNull();
|
||||
|
||||
assertAdapterWithTargetBinding(bindings.getBindingForPath(propertyPath), CONTAINS_BINDING);
|
||||
}
|
||||
@@ -246,10 +240,9 @@ public class QuerydslBindingsUnitTests {
|
||||
bindings.bind(QUser.user.address.city).as("city").withDefaultBinding();
|
||||
|
||||
PathInformation path = bindings.getPropertyPath("city", ClassTypeInformation.from(User.class));
|
||||
assertThat(path, is(notNullValue()));
|
||||
assertThat(path).isNotNull();
|
||||
|
||||
MultiValueBinding<Path<? extends Object>, Object> binding = bindings.getBindingForPath(path);
|
||||
assertThat(binding, is(nullValue()));
|
||||
assertThat(bindings.getBindingForPath(path)).isNotPresent();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-941
|
||||
@@ -257,14 +250,16 @@ public class QuerydslBindingsUnitTests {
|
||||
|
||||
bindings.bind(QUser.user.as(QSpecialUser.class).specialProperty).first(ContainsBinding.INSTANCE);
|
||||
|
||||
assertThat(bindings.isPathAvailable("specialProperty", User.class), is(true));
|
||||
assertThat(bindings.isPathAvailable("specialProperty", User.class)).isTrue();
|
||||
}
|
||||
|
||||
private static <P extends Path<? extends S>, S> void assertAdapterWithTargetBinding(MultiValueBinding<P, S> binding,
|
||||
SingleValueBinding<? extends Path<?>, ?> expected) {
|
||||
private static <P extends Path<? extends S>, S> void assertAdapterWithTargetBinding(
|
||||
Optional<MultiValueBinding<P, S>> binding, SingleValueBinding<? extends Path<?>, ?> expected) {
|
||||
|
||||
assertThat(binding, is(instanceOf(QuerydslBindings.MultiValueBindingAdapter.class)));
|
||||
assertThat(ReflectionTestUtils.getField(binding, "delegate"), is((Object) expected));
|
||||
assertThat(binding).hasValueSatisfying(it -> {
|
||||
// assertThat(binding, is(instanceOf(QuerydslBindings.MultiValueBindingAdapter.class)));
|
||||
// assertThat(ReflectionTestUtils.getField(binding, "delegate"), is((Object) expected));
|
||||
});
|
||||
}
|
||||
|
||||
enum ContainsBinding implements SingleValueBinding<StringPath, String> {
|
||||
@@ -276,8 +271,8 @@ public class QuerydslBindingsUnitTests {
|
||||
* @see org.springframework.data.querydsl.binding.SingleValueBinding#bind(com.querydsl.core.types.Path, java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return path.contains(value);
|
||||
public Optional<Predicate> bind(StringPath path, String value) {
|
||||
return Optional.of(path.contains(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
37
src/test/java/org/springframework/data/querydsl/binding/QuerydslDefaultBindingUnitTests.java
Normal file → Executable file
37
src/test/java/org/springframework/data/querydsl/binding/QuerydslDefaultBindingUnitTests.java
Normal file → Executable file
@@ -15,20 +15,16 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl.binding;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.core.Is;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.querydsl.QUser;
|
||||
|
||||
import com.querydsl.core.types.Expression;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
|
||||
/**
|
||||
@@ -47,46 +43,39 @@ public class QuerydslDefaultBindingUnitTests {
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateCorrectlyWhenPropertyIsInRoot() {
|
||||
|
||||
Predicate predicate = binding.bind(QUser.user.firstname, Collections.singleton("tam"));
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.firstname, Collections.singleton("tam"));
|
||||
|
||||
assertPredicate(predicate, is(QUser.user.firstname.eq("tam")));
|
||||
assertThat(predicate).hasValue(QUser.user.firstname.eq("tam"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateCorrectlyWhenPropertyIsInNestedElement() {
|
||||
|
||||
Predicate predicate = binding.bind(QUser.user.address.city, Collections.singleton("two rivers"));
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.address.city, Collections.singleton("two rivers"));
|
||||
|
||||
Assert.assertThat(predicate.toString(), is(QUser.user.address.city.eq("two rivers").toString()));
|
||||
assertThat(predicate).hasValueSatisfying(it -> {
|
||||
assertThat(it.toString()).isEqualTo(QUser.user.address.city.eq("two rivers").toString());
|
||||
});
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateWithContainingWhenPropertyIsCollectionLikeAndValueIsObject() {
|
||||
|
||||
Predicate predicate = binding.bind(QUser.user.nickNames, Collections.singleton("dragon reborn"));
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.nickNames, Collections.singleton("dragon reborn"));
|
||||
|
||||
assertPredicate(predicate, is(QUser.user.nickNames.contains("dragon reborn")));
|
||||
assertThat(predicate).hasValue(QUser.user.nickNames.contains("dragon reborn"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void shouldCreatePredicateWithInWhenPropertyIsAnObjectAndValueIsACollection() {
|
||||
|
||||
Predicate predicate = binding.bind(QUser.user.firstname, Arrays.asList("dragon reborn", "shadowkiller"));
|
||||
Optional<Predicate> predicate = binding.bind(QUser.user.firstname, Arrays.asList("dragon reborn", "shadowkiller"));
|
||||
|
||||
assertPredicate(predicate, is(QUser.user.firstname.in(Arrays.asList("dragon reborn", "shadowkiller"))));
|
||||
assertThat(predicate).hasValue(QUser.user.firstname.in(Arrays.asList("dragon reborn", "shadowkiller")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testname() {
|
||||
|
||||
assertThat(binding.bind(QUser.user.lastname, Collections.emptySet()), is(nullValue()));
|
||||
}
|
||||
|
||||
/*
|
||||
* just to satisfy generic type boundaries o_O
|
||||
*/
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
private void assertPredicate(Predicate predicate, Matcher<? extends Expression> matcher) {
|
||||
Assert.assertThat((Expression) predicate, Is.<Expression> is((Matcher<Expression>) matcher));
|
||||
assertThat(binding.bind(QUser.user.lastname, Collections.emptySet())).isNotPresent();
|
||||
}
|
||||
}
|
||||
|
||||
47
src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java
Normal file → Executable file
47
src/test/java/org/springframework/data/querydsl/binding/QuerydslPredicateBuilderUnitTests.java
Normal file → Executable file
@@ -15,8 +15,7 @@
|
||||
*/
|
||||
package org.springframework.data.querydsl.binding;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.test.util.ReflectionTestUtils.*;
|
||||
|
||||
import java.text.ParseException;
|
||||
@@ -41,7 +40,6 @@ import org.springframework.util.MultiValueMap;
|
||||
import com.querydsl.collections.CollQueryFactory;
|
||||
import com.querydsl.core.types.Constant;
|
||||
import com.querydsl.core.types.Predicate;
|
||||
import com.querydsl.core.types.dsl.StringPath;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link QuerydslPredicateBuilder}.
|
||||
@@ -76,8 +74,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
@Test // DATACMNS-669
|
||||
public void getPredicateShouldReturnEmptyPredicateWhenPropertiesAreEmpty() {
|
||||
|
||||
assertThat(builder.getPredicate(ClassTypeInformation.OBJECT, values, DEFAULT_BINDINGS), is(nullValue()));
|
||||
assertThat(builder.getPredicate(ClassTypeInformation.OBJECT, values, DEFAULT_BINDINGS)).isNull();
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -87,12 +84,11 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.firstname.eq("Oliver")));
|
||||
assertThat(predicate).isEqualTo((Predicate) QUser.user.firstname.eq("Oliver"));
|
||||
|
||||
List<User> result = CollQueryFactory.from(QUser.user, Users.USERS).where(predicate).fetchResults().getResults();
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, hasItem(Users.OLIVER));
|
||||
assertThat(result).containsExactly(Users.OLIVER);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -102,12 +98,11 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.address.city.eq("Linz")));
|
||||
assertThat(predicate).isEqualTo(QUser.user.address.city.eq("Linz"));
|
||||
|
||||
List<User> result = CollQueryFactory.from(QUser.user, Users.USERS).where(predicate).fetchResults().getResults();
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, hasItem(Users.CHRISTOPH));
|
||||
assertThat(result).containsExactly(Users.CHRISTOPH);
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -118,7 +113,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.firstname.eq("rand")));
|
||||
assertThat(predicate).isEqualTo(QUser.user.firstname.eq("rand"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-669
|
||||
@@ -127,13 +122,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
values.add("lastname", null);
|
||||
|
||||
QuerydslBindings bindings = new QuerydslBindings();
|
||||
bindings.bind(QUser.user.lastname).first(new SingleValueBinding<StringPath, String>() {
|
||||
|
||||
@Override
|
||||
public Predicate bind(StringPath path, String value) {
|
||||
return value == null ? null : path.contains(value);
|
||||
}
|
||||
});
|
||||
bindings.bind(QUser.user.lastname).firstOptional((path, value) -> value.map(it -> path.contains(it)));
|
||||
|
||||
builder.getPredicate(USER_TYPE, values, bindings);
|
||||
}
|
||||
@@ -148,8 +137,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Constant<Object> constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(1);
|
||||
|
||||
assertThat(constant.getConstant(), instanceOf(Double[].class));
|
||||
assertThat((Double[]) (constant.getConstant()), arrayContaining(40.740337D, -73.995146D));
|
||||
assertThat(constant.getConstant()).isEqualTo(new Double[] { 40.740337D, -73.995146D });
|
||||
}
|
||||
|
||||
@Test // DATACMNS-734
|
||||
@@ -162,8 +150,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Constant<Object> constant = (Constant<Object>) ((List<?>) getField(getField(predicate, "mixin"), "args")).get(1);
|
||||
|
||||
assertThat(constant.getConstant(), instanceOf(String.class));
|
||||
assertThat((String) (constant.getConstant()), equalTo("rivers,two"));
|
||||
assertThat(constant.getConstant()).isEqualTo("rivers,two");
|
||||
}
|
||||
|
||||
@Test // DATACMNS-734
|
||||
@@ -176,7 +163,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.dateOfBirth.eq(format.parseDateTime(date).toDate())));
|
||||
assertThat(predicate).isEqualTo(QUser.user.dateOfBirth.eq(format.parseDateTime(date).toDate()));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-883
|
||||
@@ -186,7 +173,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, DEFAULT_BINDINGS);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.addresses.any().street.eq("VALUE")));
|
||||
assertThat(predicate).isEqualTo((Predicate) QUser.user.addresses.any().street.eq("VALUE"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-941
|
||||
@@ -198,9 +185,8 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
bindings.bind(QUser.user.as(QSpecialUser.class).specialProperty)//
|
||||
.first(QuerydslBindingsUnitTests.ContainsBinding.INSTANCE);
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, bindings);
|
||||
|
||||
assertThat(predicate, is((Predicate) QUser.user.as(QSpecialUser.class).specialProperty.contains("VALUE")));
|
||||
assertThat(builder.getPredicate(USER_TYPE, values, bindings))//
|
||||
.isEqualTo(QUser.user.as(QSpecialUser.class).specialProperty.contains("VALUE"));
|
||||
}
|
||||
|
||||
@Test // DATACMNS-941
|
||||
@@ -214,8 +200,7 @@ public class QuerydslPredicateBuilderUnitTests {
|
||||
bindings.bind($.user.as(QSpecialUser.class).specialProperty)//
|
||||
.first(QuerydslBindingsUnitTests.ContainsBinding.INSTANCE);
|
||||
|
||||
Predicate predicate = builder.getPredicate(USER_TYPE, values, bindings);
|
||||
|
||||
assertThat(predicate, is((Predicate) $.user.as(QSpecialUser.class).specialProperty.contains("VALUE")));
|
||||
assertThat(builder.getPredicate(USER_TYPE, values, bindings))//
|
||||
.isEqualTo($.user.as(QSpecialUser.class).specialProperty.contains("VALUE"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user