Added test case to check whether declaring a CRUD method in a repository interface extending Repository is delegated to the backing bean.
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2008-2010 the original author or authors.
|
* Copyright 2008-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
import org.mockito.runners.MockitoJUnitRunner;
|
import org.mockito.runners.MockitoJUnitRunner;
|
||||||
|
import org.springframework.data.repository.CrudRepository;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy;
|
import org.springframework.data.repository.query.QueryLookupStrategy;
|
||||||
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
import org.springframework.data.repository.query.QueryLookupStrategy.Key;
|
||||||
@@ -41,6 +42,9 @@ public class RepositoryFactorySupportUnitTests {
|
|||||||
|
|
||||||
RepositoryFactorySupport factory = new DummyRepositoryFactory();
|
RepositoryFactorySupport factory = new DummyRepositoryFactory();
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
CrudRepository<Object, Serializable> backingRepo;
|
||||||
|
|
||||||
@Mock
|
@Mock
|
||||||
MyQueryCreationListener listener;
|
MyQueryCreationListener listener;
|
||||||
@Mock
|
@Mock
|
||||||
@@ -58,7 +62,15 @@ public class RepositoryFactorySupportUnitTests {
|
|||||||
|
|
||||||
verify(listener, times(1)).onCreation(any(MyRepositoryQuery.class));
|
verify(listener, times(1)).onCreation(any(MyRepositoryQuery.class));
|
||||||
verify(otherListener, times(2)).onCreation(any(RepositoryQuery.class));
|
verify(otherListener, times(2)).onCreation(any(RepositoryQuery.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void routesCallToRedeclaredMethodIntoTarget() {
|
||||||
|
|
||||||
|
ObjectRepository repository = factory.getRepository(ObjectRepository.class);
|
||||||
|
repository.save(repository);
|
||||||
|
|
||||||
|
verify(backingRepo, times(1)).save(any(Object.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
class DummyRepositoryFactory extends RepositoryFactorySupport {
|
class DummyRepositoryFactory extends RepositoryFactorySupport {
|
||||||
@@ -77,14 +89,14 @@ public class RepositoryFactorySupportUnitTests {
|
|||||||
@Override
|
@Override
|
||||||
protected Object getTargetRepository(RepositoryMetadata metadata) {
|
protected Object getTargetRepository(RepositoryMetadata metadata) {
|
||||||
|
|
||||||
return new Object();
|
return backingRepo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
protected Class<?> getRepositoryBaseClass(RepositoryMetadata metadata) {
|
||||||
|
|
||||||
return Object.class;
|
return CrudRepository.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -108,6 +120,8 @@ public class RepositoryFactorySupportUnitTests {
|
|||||||
|
|
||||||
|
|
||||||
Object findByFoo();
|
Object findByFoo();
|
||||||
|
|
||||||
|
Object save(Object entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlainQueryCreationListener extends
|
interface PlainQueryCreationListener extends
|
||||||
|
|||||||
Reference in New Issue
Block a user