Search in sources :

Example 21 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method discoversCustomlyImplementedCrudMethodWithoutGenericParameters.

// DATACMNS-1008, DATACMNS-912, DATACMNS-854
@Test
public void discoversCustomlyImplementedCrudMethodWithoutGenericParameters() throws Exception {
    SimpleSaveRepositoryImpl customImplementation = new SimpleSaveRepositoryImpl();
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(SimpleSaveRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class, RepositoryComposition.just(customImplementation).withMethodLookup(MethodLookups.forRepositoryTypes(metadata)));
    Method customBaseRepositoryMethod = SimpleSaveRepository.class.getMethod("save", Object.class);
    assertThat(information.isCustomMethod(customBaseRepositoryMethod)).isTrue();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 22 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method discoversRepositoryBaseClassMethod.

@Test
public void discoversRepositoryBaseClassMethod() throws Exception {
    Method method = FooRepository.class.getMethod("findById", Integer.class);
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
    DefaultRepositoryInformation information = new DefaultRepositoryInformation(metadata, REPOSITORY, RepositoryComposition.empty().withMethodLookup(MethodLookups.forRepositoryTypes(metadata)));
    Method reference = information.getTargetClassMethod(method);
    assertThat(reference.getDeclaringClass()).isEqualTo(REPOSITORY);
    assertThat(reference.getName()).isEqualTo("findById");
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 23 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method detectsQueryMethodCorrectly.

// DATACMNS-193
@Test
public void detectsQueryMethodCorrectly() {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    Method queryMethod = getMethodFrom(ConcreteRepository.class, "findBySomethingDifferent");
    assertThat(information.getQueryMethods()).contains(queryMethod);
    assertThat(information.isQueryMethod(queryMethod)).isTrue();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 24 with RepositoryMetadata

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

the class CrudRepositoryInvokerUnitTests method getInvokerFor.

@SuppressWarnings({ "rawtypes", "unchecked" })
private static RepositoryInvoker getInvokerFor(Object repository, VerifyingMethodInterceptor interceptor) {
    Object proxy = getVerifyingRepositoryProxy(repository, interceptor);
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(repository.getClass().getInterfaces()[0]);
    GenericConversionService conversionService = new DefaultFormattingConversionService();
    return new CrudRepositoryInvoker((CrudRepository) proxy, 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 25 with RepositoryMetadata

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

the class JdbcQueryMethodUnitTests method returnsSpecifiedRowMapperClass.

// DATAJDBC-165
@Test
public void returnsSpecifiedRowMapperClass() 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.getRowMapperClass()).isEqualTo(CustomRowMapper.class);
}
Also used : ProjectionFactory(org.springframework.data.projection.ProjectionFactory) RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) Method(java.lang.reflect.Method) 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