Search in sources :

Example 26 with SpelAwareProxyProjectionFactory

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

the class ReactiveStringBasedMongoQueryUnitTests method createQueryForMethod.

private ReactiveStringBasedMongoQuery createQueryForMethod(ReactiveQueryMethodEvaluationContextProvider contextProvider, String name, Class<?>... parameters) throws Exception {
    Method method = SampleRepository.class.getMethod(name, parameters);
    ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    ReactiveMongoQueryMethod queryMethod = new ReactiveMongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
    return new ReactiveStringBasedMongoQuery(queryMethod, operations, PARSER, contextProvider);
}
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 27 with SpelAwareProxyProjectionFactory

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

the class StringBasedMongoQueryUnitTests method createQueryForMethod.

private StringBasedMongoQuery createQueryForMethod(String name, Class<?>... parameters) {
    try {
        Method method = SampleRepository.class.getMethod(name, parameters);
        ProjectionFactory factory = new SpelAwareProxyProjectionFactory();
        MongoQueryMethod queryMethod = new MongoQueryMethod(method, new DefaultRepositoryMetadata(SampleRepository.class), factory, converter.getMappingContext());
        return new StringBasedMongoQuery(queryMethod, operations, PARSER, QueryMethodEvaluationContextProvider.DEFAULT);
    } 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 28 with SpelAwareProxyProjectionFactory

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

the class MongoRepositoryFactoryUnitTests method setUp.

@BeforeEach
@SuppressWarnings("unchecked")
public void setUp() {
    when(template.getConverter()).thenReturn(converter);
    when(converter.getMappingContext()).thenReturn(mappingContext);
    when(converter.getProjectionFactory()).thenReturn(new SpelAwareProxyProjectionFactory());
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) BeforeEach(org.junit.jupiter.api.BeforeEach)

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