Search in sources :

Example 16 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method discoversCustomlyImplementedCrudMethodWithGenericParameters.

// DATACMNS-912
@Test
public void discoversCustomlyImplementedCrudMethodWithGenericParameters() throws Exception {
    GenericsSaveRepositoryImpl customImplementation = new GenericsSaveRepositoryImpl();
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(GenericsSaveRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, RepositoryFactorySupport.class, RepositoryComposition.just(customImplementation).withMethodLookup(MethodLookups.forRepositoryTypes(metadata)));
    Method customBaseRepositoryMethod = GenericsSaveRepository.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 17 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation 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 18 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation 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 19 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation 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 20 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation 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)

Aggregations

RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)26 Test (org.junit.Test)22 RepositoryMetadata (org.springframework.data.repository.core.RepositoryMetadata)17 Method (java.lang.reflect.Method)13 ProxyFactory (org.springframework.aop.framework.ProxyFactory)3 HashSet (java.util.HashSet)1 Advice (org.aopalliance.aop.Advice)1 Before (org.junit.Before)1 DefaultMethodInvokingMethodInterceptor (org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor)1 ProjectionFactory (org.springframework.data.projection.ProjectionFactory)1 SpelAwareProxyProjectionFactory (org.springframework.data.projection.SpelAwareProxyProjectionFactory)1 EntityInformation (org.springframework.data.repository.core.EntityInformation)1 EventPublishingMethodInterceptor (org.springframework.data.repository.core.support.EventPublishingRepositoryProxyPostProcessor.EventPublishingMethodInterceptor)1 RepositoryFactoryInformation (org.springframework.data.repository.core.support.RepositoryFactoryInformation)1 QueryByExampleExecutor (org.springframework.data.repository.query.QueryByExampleExecutor)1