Search in sources :

Example 1 with RepositoryMetadata

use of org.springframework.data.repository.core.RepositoryMetadata in project spring-data-jdbc by spring-projects.

the class JdbcQueryMethodUnitTests method returnsSqlStatement.

// DATAJDBC-165
@Test
public void returnsSqlStatement() throws NoSuchMethodException {
    RepositoryMetadata metadata = mock(RepositoryMetadata.class);
    when(metadata.getReturnedDomainClass(any(Method.class))).thenReturn((Class) String.class);
    JdbcQueryMethod queryMethod = new JdbcQueryMethod(JdbcQueryMethodUnitTests.class.getDeclaredMethod("queryMethod"), metadata, mock(ProjectionFactory.class));
    assertThat(queryMethod.getAnnotatedQuery()).isEqualTo(DUMMY_SELECT);
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 2 with RepositoryMetadata

use of org.springframework.data.repository.core.RepositoryMetadata 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));
}
Also used : StandardEvaluationContext(org.springframework.expression.spel.support.StandardEvaluationContext) QueryMethod(org.springframework.data.repository.query.QueryMethod) SpelAwareProxyProjectionFactory(org.springframework.data.projection.SpelAwareProxyProjectionFactory) ArrayList(java.util.ArrayList) QueryMethod(org.springframework.data.repository.query.QueryMethod) Method(java.lang.reflect.Method) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) ParametersParameterAccessor(org.springframework.data.repository.query.ParametersParameterAccessor) PartTree(org.springframework.data.repository.query.parser.PartTree) SpelQueryCreator(org.springframework.data.keyvalue.repository.query.SpelQueryCreator)

Example 3 with RepositoryMetadata

use of org.springframework.data.repository.core.RepositoryMetadata in project spring-data-commons by spring-projects.

the class AbstractRepositoryMetadataUnitTests method handlesGenericTypeInReturnedCollectionCorrectly.

// DATACMNS-98
@Test
public void handlesGenericTypeInReturnedCollectionCorrectly() throws SecurityException, NoSuchMethodException {
    RepositoryMetadata metadata = new DummyRepositoryMetadata(ExtendingRepository.class);
    Method method = ExtendingRepository.class.getMethod("anotherMethod");
    assertThat(metadata.getReturnedDomainClass(method)).isEqualTo(Map.class);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 4 with RepositoryMetadata

use of org.springframework.data.repository.core.RepositoryMetadata in project spring-data-commons by spring-projects.

the class ReflectionRepositoryInvokerUnitTests method getInvokerFor.

private static RepositoryInvoker getInvokerFor(Object repository) {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(repository.getClass().getInterfaces()[0]);
    GenericConversionService conversionService = new DefaultFormattingConversionService();
    return new ReflectionRepositoryInvoker(repository, metadata, conversionService);
}
Also used : DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) DefaultRepositoryMetadata(org.springframework.data.repository.core.support.DefaultRepositoryMetadata) GenericConversionService(org.springframework.core.convert.support.GenericConversionService) DefaultFormattingConversionService(org.springframework.format.support.DefaultFormattingConversionService)

Example 5 with RepositoryMetadata

use of org.springframework.data.repository.core.RepositoryMetadata in project spring-data-commons by spring-projects.

the class DefaultRepositoryMetadataUnitTests method findsDomainClassOnExtensionOfDaoInterface.

@Test
public void findsDomainClassOnExtensionOfDaoInterface() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ExtensionOfUserCustomExtendedDao.class);
    assertThat(metadata.getDomainType()).isEqualTo(User.class);
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Test(org.junit.Test)

Aggregations

RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)60 Test (org.junit.Test)52 Method (java.lang.reflect.Method)37 RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)17 DefaultRepositoryMetadata (org.springframework.data.repository.core.support.DefaultRepositoryMetadata)16 AbstractRepositoryMetadata (org.springframework.data.repository.core.support.AbstractRepositoryMetadata)4 GenericConversionService (org.springframework.core.convert.support.GenericConversionService)3 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)3 DefaultFormattingConversionService (org.springframework.format.support.DefaultFormattingConversionService)3 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 ProxyFactory (org.springframework.aop.framework.ProxyFactory)1 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)1 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)1 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)1 SpelQueryCreator (org.springframework.data.keyvalue.repository.query.SpelQueryCreator)1 DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor)1 ParametersParameterAccessor (org.springframework.data.repository.query.ParametersParameterAccessor)1 QueryMethod (org.springframework.data.repository.query.QueryMethod)1