Search in sources :

Example 6 with RepositoryInformation

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

the class DefaultRepositoryInformationUnitTests method doesNotConsiderRedeclaredSaveMethodAQueryMethod.

// DATACMNS-151
@Test
public void doesNotConsiderRedeclaredSaveMethodAQueryMethod() throws Exception {
    RepositoryMetadata metadata = new DefaultRepositoryMetadata(ConcreteRepository.class);
    RepositoryInformation information = new DefaultRepositoryInformation(metadata, CrudRepository.class, RepositoryComposition.empty());
    Method saveMethod = BaseRepository.class.getMethod("save", Object.class);
    Method deleteMethod = BaseRepository.class.getMethod("delete", Object.class);
    Iterable<Method> queryMethods = information.getQueryMethods();
    assertThat(queryMethods).doesNotContain(saveMethod, deleteMethod);
}
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 7 with RepositoryInformation

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

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

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

the class EventPublishingRepositoryProxyPostProcessorUnitTests method doesNotAddAdviceIfDomainTypeDoesNotExposeEvents.

// DATACMNS-928
@Test
public void doesNotAddAdviceIfDomainTypeDoesNotExposeEvents() {
    RepositoryInformation information = new DummyRepositoryInformation(CrudRepository.class);
    RepositoryProxyPostProcessor processor = new EventPublishingRepositoryProxyPostProcessor(publisher);
    ProxyFactory factory = mock(ProxyFactory.class);
    processor.postProcess(factory, information);
    verify(factory, never()).addAdvice(any(Advice.class));
}
Also used : ProxyFactory(org.springframework.aop.framework.ProxyFactory) Advice(org.aopalliance.aop.Advice) RepositoryInformation(org.springframework.data.repository.core.RepositoryInformation) Test(org.junit.Test)

Example 10 with RepositoryInformation

use of org.springframework.data.repository.core.RepositoryInformation in project spring-cloud-gcp by spring-cloud.

the class DatastoreRepositoryFactoryTests method getTargetRepositoryTest.

@Test
public void getTargetRepositoryTest() {
    RepositoryInformation repoInfo = mock(RepositoryInformation.class);
    Mockito.<Class<?>>when(repoInfo.getRepositoryBaseClass()).thenReturn(SimpleDatastoreRepository.class);
    Mockito.<Class<?>>when(repoInfo.getDomainType()).thenReturn(TestEntity.class);
    Object repo = this.datastoreRepositoryFactory.getTargetRepository(repoInfo);
    assertThat(repo.getClass()).isEqualTo(SimpleDatastoreRepository.class);
}
Also used : 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