Search in sources :

Example 11 with SpelAwareProxyProjectionFactory

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

the class ResultProcessorUnitTests method leavesNonProjectingResultUntouched.

// DATACMNS-89
@Test
public void leavesNonProjectingResultUntouched() throws Exception {
    ResultProcessor information = new ResultProcessor(getQueryMethod("findAll"), new SpelAwareProxyProjectionFactory());
    Sample sample = new Sample("Dave", "Matthews");
    List<Sample> result = new ArrayList<>(Collections.singletonList(sample));
    List<Sample> converted = information.processResult(result);
    assertThat(converted).contains(sample);
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 12 with SpelAwareProxyProjectionFactory

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

the class ReturnedTypeUnitTests method cachesInstancesBySourceTypes.

// DATACMNS-1112
@Test
public void cachesInstancesBySourceTypes() {
    SpelAwareProxyProjectionFactory factory = new SpelAwareProxyProjectionFactory();
    ReturnedType left = ReturnedType.of(Child.class, Object.class, factory);
    ReturnedType right = ReturnedType.of(Child.class, Object.class, factory);
    assertThat(left).isSameAs(right);
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) Test(org.junit.Test)

Example 13 with SpelAwareProxyProjectionFactory

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

the class ReturnedTypeUnitTests method detectsDistinctInputProperties.

// DATACMNS-963
@Test
public void detectsDistinctInputProperties() {
    ReturnedType type = ReturnedType.of(Child.class, Object.class, new SpelAwareProxyProjectionFactory());
    List<String> properties = type.getInputProperties();
    assertThat(properties).hasSize(1);
    assertThat(properties).containsExactly("firstname");
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) Test(org.junit.Test)

Example 14 with SpelAwareProxyProjectionFactory

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

the class QueryExecutorMethodInterceptorUnitTests method skipsQueryLookupsIfQueryLookupStrategyIsNotPresent.

@Test
public void skipsQueryLookupsIfQueryLookupStrategyIsNotPresent() {
    when(information.getQueryMethods()).thenReturn(Streamable.empty());
    when(factory.getQueryLookupStrategy(any(), any())).thenReturn(Optional.of(strategy));
    factory.new QueryExecutorMethodInterceptor(information, new SpelAwareProxyProjectionFactory());
    verify(strategy, times(0)).resolveQuery(any(), any(), any(), any());
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) Test(org.junit.Test)

Example 15 with SpelAwareProxyProjectionFactory

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

the class QueryExecutorMethodInterceptorUnitTests method rejectsRepositoryInterfaceWithQueryMethodsIfNoQueryLookupStrategyIsDefined.

@Test(expected = IllegalStateException.class)
public void rejectsRepositoryInterfaceWithQueryMethodsIfNoQueryLookupStrategyIsDefined() throws Exception {
    when(information.hasQueryMethods()).thenReturn(true);
    when(factory.getQueryLookupStrategy(any(), any())).thenReturn(Optional.empty());
    factory.new QueryExecutorMethodInterceptor(information, new SpelAwareProxyProjectionFactory());
}
Also used : SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) Test(org.junit.Test)

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