Search in sources :

Example 1 with RepositoryInformation

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

the class RepositoryCompositionUnitTests method shouldCallMethodsInOrder.

// DATACMNS-102
@Test
public void shouldCallMethodsInOrder() throws Throwable {
    RepositoryInformation repositoryInformation = new DefaultRepositoryInformation(new DefaultRepositoryMetadata(OrderedRepository.class), OrderedRepository.class, RepositoryComposition.empty());
    RepositoryFragment<?> foo = RepositoryFragment.implemented(FooMixinImpl.INSTANCE);
    RepositoryFragment<?> bar = RepositoryFragment.implemented(BarMixinImpl.INSTANCE);
    RepositoryComposition fooBar = RepositoryComposition.of(RepositoryFragments.of(foo, bar)).withMethodLookup(MethodLookups.forRepositoryTypes(repositoryInformation));
    RepositoryComposition barFoo = RepositoryComposition.of(RepositoryFragments.of(bar, foo)).withMethodLookup(MethodLookups.forRepositoryTypes(repositoryInformation));
    Method getString = ReflectionUtils.findMethod(OrderedRepository.class, "getString");
    assertThat(fooBar.invoke(fooBar.findMethod(getString).get())).isEqualTo("foo");
    assertThat(barFoo.invoke(barFoo.findMethod(getString).get())).isEqualTo("bar");
}
Also used : Method(java.lang.reflect.Method) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 2 with RepositoryInformation

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

the class RepositoryCompositionUnitTests method before.

@Before
@SuppressWarnings("rawtypes")
public void before() {
    RepositoryInformation repositoryInformation = new DefaultRepositoryInformation(new DefaultRepositoryMetadata(PersonRepository.class), backingRepo.getClass(), RepositoryComposition.empty());
    RepositoryFragment<QueryByExampleExecutor> mixin = RepositoryFragment.implemented(QueryByExampleExecutor.class, queryByExampleExecutor);
    RepositoryFragment<PersonRepository> base = RepositoryFragment.implemented(backingRepo);
    repositoryComposition = RepositoryComposition.of(RepositoryFragments.of(mixin, base)).withMethodLookup(MethodLookups.forRepositoryTypes(repositoryInformation));
}
Also used : QueryByExampleExecutor(org.springframework.data.repository.query.QueryByExampleExecutor) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Before(org.junit.Before)

Example 3 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method considersIntermediateMethodsAsFinderMethods.

@Test
public void considersIntermediateMethodsAsFinderMethods() {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    assertThat(information.hasCustomMethod()).isFalse();
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 4 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method onlyReturnsMostConcreteQueryMethod.

@Test
public void onlyReturnsMostConcreteQueryMethod() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    Method intermediateMethod = BaseRepository.class.getMethod("genericMethodToOverride", String.class);
    Method concreteMethod = ConcreteRepository.class.getMethod("genericMethodToOverride", String.class);
    Iterable<Method> queryMethods = information.getQueryMethods();
    assertThat(queryMethods).contains(concreteMethod);
    assertThat(queryMethods).doesNotContain(intermediateMethod);
}
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 5 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method getQueryShouldNotReturnAnyBridgeMethods.

// DATACMNS-441
@Test
public void getQueryShouldNotReturnAnyBridgeMethods() {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(CustomDefaultRepositoryMethodsRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    assertThat(information.getQueryMethods()).allMatch(method -> !method.isBridge());
}
Also used : RepositoryMetadata(org.springframework.data.repository.core.RepositoryMetadata) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Aggregations

RepositoryInformation (org.springframework.data.repository.core.RepositoryInformation)25 Test (org.junit.Test)21 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