Search in sources :

Example 21 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class StringBasedAggregationUnitTests method aggregateRaisesErrorOnInvalidReturnType.

// DATAMONGO-2506
@Test
void aggregateRaisesErrorOnInvalidReturnType() {
    Method method = ClassUtils.getMethod(UnsupportedRepository.class, "pageIsUnsupported", Pageable.class);
    ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
    // 
    assertThatExceptionOfType(InvalidMongoDbApiUsageException.class).isThrownBy(() -> new StringBasedAggregation(queryMethod, operations, PARSER, // 
    QueryMethodEvaluationContextProvider.DEFAULT)).withMessageContaining(// 
    "pageIsUnsupported").withMessageContaining("Page");
}
Also used : InvalidMongoDbApiUsageException(org.springframework.data.mongodb.InvalidMongoDbApiUsageException) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.jupiter.api.Test)

Example 22 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class AbstractMongoQueryUnitTests method createQueryForMethod.

private MongoQueryFake createQueryForMethod(Class<?> repository, String methodName, Class<?>... paramTypes) {
    try {
        Method method = repository.getMethod(methodName, paramTypes);
        ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
        MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(repository), factory, mappingContextMock);
        return new MongoQueryFake(queryMethod, mongoOperationsMock);
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method)

Example 23 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class AbstractReactiveMongoQueryUnitTests method createQueryForMethod.

private ReactiveMongoQueryFake createQueryForMethod(Class<?> repository, String methodName, Class<?>... paramTypes) {
    try {
        Method method = repository.getMethod(methodName, paramTypes);
        ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
        ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method, new DefaultRepositoryMetadata(repository), factory, mappingContextMock);
        return new ReactiveMongoQueryFake(queryMethod, mongoOperationsMock);
    } catch (Exception e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method)

Example 24 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class ReactiveMongoQueryMethodUnitTests method rejectsNullMappingContext.

// DATAMONGO-1444
@Test(expected = IllegalArgumentException.class)
public void rejectsNullMappingContext() throws Exception {
    Method method = PersonRepository.class.getMethod("findByFirstname", String.class, Point.class);
    new MongoQueryMethod(method, new DefaultRepositoryMetadata(PersonRepository.class), new SpelAwareProxyProjectionFactory(), null);
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 25 with SpelAwareProxyProjectionFactory

use of org.springframework.data.projection.SpelAwareProxyProjectionFactory in project spring-data-mongodb by spring-projects.

the class ReactiveMongoQueryMethodUnitTests method queryMethod.

private ReactiveMongoQueryMethod queryMethod(Class<?> repository, String name, Class<?>... parameters) throws Exception {
    Method method = repository.getMethod(name, parameters);
    ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    return new ReactiveMongoQueryMethod(method, new DefaultRepositoryMetadata(repository), factory, context);
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) Method(java.lang.reflect.Method)

Aggregations

SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)28 Method (java.lang.reflect.Method)17 DefaultRepositoryMetadata (org.springframework.data.repository.core.support.DefaultRepositoryMetadata)15 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)11 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)4 PartTree (org.springframework.data.repository.query.parser.PartTree)4 QueryMethod (org.springframework.data.repository.query.QueryMethod)3 JacksonMappingProvider (com.jayway.jsonpath.spi.mapper.JacksonMappingProvider)2 ArrayList (java.util.ArrayList)2 Document (org.bson.Document)2 MappingMongoConverter (org.springframework.data.mongodb.core.convert.MappingMongoConverter)2 Query (org.springframework.data.mongodb.core.query.Query)2 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)2 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 MappingProvider (com.jayway.jsonpath.spi.mapper.MappingProvider)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 JsonParseException (org.bson.json.JsonParseException)1 Before (org.junit.Before)1