use of org.springframework.data.repository.query.QueryMethod in project spring-data-keyvalue by spring-projects.
the class KeyValuePartTreeQueryUnitTests method shouldApplyPageableParameterToCollectionQuery.
// DATAKV-142
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldApplyPageableParameterToCollectionQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findBy", Pageable.class), metadataMock, projectionFactoryMock);
KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE, kvOpsMock, SpelQueryCreator.class);
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { PageRequest.of(2, 3) });
assertThat(query.getOffset(), is(6L));
assertThat(query.getRows(), is(3));
}
use of org.springframework.data.repository.query.QueryMethod in project spring-data-keyvalue by spring-projects.
the class KeyValuePartTreeQueryUnitTests method shouldApplyDerivedMaxResultsToQuery.
// DATAKV-142
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void shouldApplyDerivedMaxResultsToQuery() throws SecurityException, NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findTop3By"), metadataMock, projectionFactoryMock);
KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE, kvOpsMock, SpelQueryCreator.class);
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] {});
assertThat(query.getRows(), is(3));
}
use of org.springframework.data.repository.query.QueryMethod in project spring-data-keyvalue by spring-projects.
the class SpelQueryEngineUnitTests method createQueryForMethodWithArgs.
private static SpelCriteria createQueryForMethodWithArgs(String methodName, Object... args) throws Exception {
List<Class<?>> types = new ArrayList<>(args.length);
for (Object arg : args) {
types.add(arg.getClass());
}
Method method = PersonRepository.class.getMethod(methodName, types.toArray(new Class<?>[types.size()]));
RepositoryMetadata metadata = mock(RepositoryMetadata.class);
doReturn(method.getReturnType()).when(metadata).getReturnedDomainClass(method);
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
SpelQueryCreator creator = new SpelQueryCreator(partTree, new ParametersParameterAccessor(new QueryMethod(method, metadata, new SpelAwareProxyProjectionFactory()).getParameters(), args));
return new SpelCriteria(creator.createQuery().getCriteria(), new StandardEvaluationContext(args));
}
use of org.springframework.data.repository.query.QueryMethod in project spring-data-jdbc by spring-projects.
the class CriteriaFactoryUnitTests method shouldConsiderArrayValuesInInOperator.
// DATAJDBC-539
@Test
void shouldConsiderArrayValuesInInOperator() {
QueryMethod queryMethod = getQueryMethod("findAllByNameIn", String[].class);
RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, new Object[] { new String[] { "foo", "bar" } });
ParameterMetadataProvider parameterMetadata = new ParameterMetadataProvider(accessor);
CriteriaFactory criteriaFactory = new CriteriaFactory(parameterMetadata);
Part part = new Part("NameIn", User.class);
Criteria criteria = criteriaFactory.createCriteria(part);
assertThat(criteria.getValue()).isEqualTo(Arrays.asList("foo", "bar"));
}
use of org.springframework.data.repository.query.QueryMethod in project spring-data-keyvalue by spring-projects.
the class KeyValuePartTreeQueryUnitTests method spelExpressionAndContextShouldNotBeReused.
// DATAKV-115
@Test
@SuppressWarnings({ "unchecked", "rawtypes" })
public void spelExpressionAndContextShouldNotBeReused() throws NoSuchMethodException, SecurityException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Person.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("findByFirstname", String.class), metadataMock, projectionFactoryMock);
KeyValuePartTreeQuery query = new KeyValuePartTreeQuery(qm, DefaultEvaluationContextProvider.INSTANCE, kvOpsMock, SpelQueryCreator.class);
Object[] args = new Object[] { "foo" };
Object first = query.prepareQuery(args).getCriteria();
Object second = query.prepareQuery(args).getCriteria();
assertThat(first, not(sameInstance(second)));
}
Aggregations