Search in sources :

Example 41 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method ignoresCrudMethodsAnnotatedWithQuery.

// DATACMNS-364
@Test
public void ignoresCrudMethodsAnnotatedWithQuery() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    Method method = BaseRepository.class.getMethod("findById", Object.class);
    assertThat(information.getQueryMethods()).contains(method);
}
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 42 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method findsTargetSaveForIterableIfEntityImplementsIterable.

// DATACMNS-385
@Test
public void findsTargetSaveForIterableIfEntityImplementsIterable() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(BossRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    Method method = BossRepository.class.getMethod("saveAll", Iterable.class);
    Method reference = CrudRepository.class.getMethod("saveAll", Iterable.class);
    assertThat(information.getTargetClassMethod(method)).isEqualTo(reference);
}
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 43 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method discoversCustomlyImplementedCrudMethodWithGenerics.

// DATACMNS-854
@Test
public void discoversCustomlyImplementedCrudMethodWithGenerics() throws SecurityException, NoSuchMethodException {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.just(customImplementation));
    Method source = FooRepositoryCustom.class.getMethod("exists", Object.class);
    Method expected = customImplementation.getClass().getMethod("exists", Object.class);
    assertThat(information.getTargetClassMethod(source)).isEqualTo(expected);
}
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 44 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method discoversCustomlyImplementedCrudMethod.

@Test
public void discoversCustomlyImplementedCrudMethod() throws SecurityException, NoSuchMethodException {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(FooRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.just(customImplementation));
    Method source = FooRepositoryCustom.class.getMethod("save", User.class);
    Method expected = customImplementation.getClass().getMethod("save", User.class);
    assertThat(information.getTargetClassMethod(source)).isEqualTo(expected);
}
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 45 with RepositoryMetadata

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

the class DefaultRepositoryInformationUnitTests method doesNotConsiderManuallyDefinedSaveMethodAQueryMethod.

// DATACMNS-151
@Test
public void doesNotConsiderManuallyDefinedSaveMethodAQueryMethod() {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(CustomRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, PagingAndSortingRepository.class, RepositoryComposition.empty());
    assertThat(information.getQueryMethods()).isEmpty();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) 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