Removed all references to 'DAO'.
This commit is contained in:
@@ -23,7 +23,7 @@ import java.lang.annotation.Target;
|
||||
|
||||
|
||||
/**
|
||||
* Annotation to declare finder queries directly on DAO methods.
|
||||
* Annotation to declare finder queries directly on repository methods.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.w3c.dom.Element;
|
||||
|
||||
|
||||
/**
|
||||
* Parser to create bean definitions for dao-config namespace. Registers bean
|
||||
* Parser to create bean definitions for repositories namespace. Registers bean
|
||||
* definitions for repositories as well as
|
||||
* {@code PersistenceAnnotationBeanPostProcessor} and
|
||||
* {@code PersistenceExceptionTranslationPostProcessor} to transparently inject
|
||||
@@ -53,8 +53,9 @@ class JpaRepositoryConfigDefinitionParser
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see org.springframework.data.jpa.repository.config.
|
||||
* AbstractRepositoryConfigDefinitionParser#getDaoConfigContext()
|
||||
* @see org.springframework.data.repository.config.
|
||||
* AbstractRepositoryConfigDefinitionParser
|
||||
* #getGlobalRepositoryConfigInformation(org.w3c.dom.Element)
|
||||
*/
|
||||
@Override
|
||||
protected SimpleJpaRepositoryConfiguration getGlobalRepositoryConfigInformation(
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
|
||||
|
||||
|
||||
/**
|
||||
* Simple namespace handler for {@literal dao-config} namespace.
|
||||
* Simple namespace handler for {@literal repositories} namespace.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -98,7 +98,7 @@ public class SimpleJpaRepositoryConfiguration
|
||||
|
||||
/**
|
||||
* Returns the {@link javax.persistence.EntityManagerFactory} reference
|
||||
* to be used for all the DAO instances configured.
|
||||
* to be used for all the repository instances configured.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
|
||||
@@ -43,7 +43,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public class AuditingEntityListenerTests {
|
||||
|
||||
@Autowired
|
||||
AuditableUserRepository dao;
|
||||
AuditableUserRepository repository;
|
||||
|
||||
@Autowired
|
||||
AuditorAwareStub auditorAware;
|
||||
@@ -57,7 +57,7 @@ public class AuditingEntityListenerTests {
|
||||
user = new AuditableUser();
|
||||
auditorAware.setAuditor(user);
|
||||
|
||||
dao.save(user);
|
||||
repository.save(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ public class AuditingEntityListenerTests {
|
||||
role.setName("ADMIN");
|
||||
|
||||
user.addRole(role);
|
||||
dao.save(user);
|
||||
repository.save(user);
|
||||
role = user.getRoles().iterator().next();
|
||||
|
||||
assertDatesSet(user);
|
||||
|
||||
@@ -25,6 +25,6 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@ContextConfiguration(value = "classpath:openjpa.xml", inheritLocations = true)
|
||||
public class OpenJpaNamespaceUserDaoTests extends NamespaceUserRepositoryTests {
|
||||
public class OpenJpaNamespaceUserRepositoryTests extends NamespaceUserRepositoryTests {
|
||||
|
||||
}
|
||||
@@ -85,8 +85,8 @@ public class UserRepositoryFinderTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests that the DAO returns {@code null} for not found objects for finder
|
||||
* methods that return a single domain object.
|
||||
* Tests that the repository returns {@code null} for not found objects for
|
||||
* finder methods that return a single domain object.
|
||||
*/
|
||||
@Test
|
||||
public void returnsNullIfNothingFound() {
|
||||
|
||||
@@ -326,7 +326,7 @@ public class UserRepositoryTests {
|
||||
|
||||
/**
|
||||
* Tests that all users get deleted by triggering
|
||||
* {@link UserDao#deleteAll()}.
|
||||
* {@link UserRepository#deleteAll()}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -398,7 +398,7 @@ public class UserRepositoryTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests, that the generic dao implements count correctly.
|
||||
* Tests, that the generic repository implements count correctly.
|
||||
*/
|
||||
@Test
|
||||
public void testCountsCorrectly() {
|
||||
@@ -414,7 +414,8 @@ public class UserRepositoryTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests invoking a method of a custom implementation of the DAO interface.
|
||||
* Tests invoking a method of a custom implementation of the repository
|
||||
* interface.
|
||||
*/
|
||||
@Test
|
||||
public void testInvocationOfCustomImplementation() {
|
||||
@@ -424,7 +425,7 @@ public class UserRepositoryTests {
|
||||
|
||||
|
||||
/**
|
||||
* Tests that overriding a finder method is recognized by the DAO
|
||||
* Tests that overriding a finder method is recognized by the repository
|
||||
* implementation. If an overriding method is found it will will be invoked
|
||||
* instead of the automatically generated finder.
|
||||
*/
|
||||
|
||||
@@ -45,7 +45,7 @@ public abstract class AbstractRepositoryConfigTests {
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that context creation detects 3 DAO beans.
|
||||
* Asserts that context creation detects 3 repository beans.
|
||||
*/
|
||||
@Test
|
||||
public void testContextCreation() {
|
||||
|
||||
@@ -25,14 +25,14 @@ import org.springframework.util.Assert;
|
||||
|
||||
|
||||
/**
|
||||
* Annotation to exclude DAO interfaces from being picked up and thus in
|
||||
* Annotation to exclude repository interfaces from being picked up and thus in
|
||||
* consequence getting an instance being created.
|
||||
* <p>
|
||||
* This will typically be used when providing an extended base interface for all
|
||||
* DAOs in combination with a custom DAO base class to implement methods
|
||||
* declared in that intermediate interface. In this case you typically derive
|
||||
* your concrete DAO interfaces from the intermediate one but don't want to
|
||||
* create a Spring bean for the intermediate interface.
|
||||
* repositories in combination with a custom repository base class to implement
|
||||
* methods declared in that intermediate interface. In this case you typically
|
||||
* derive your concrete repository interfaces from the intermediate one but
|
||||
* don't want to create a Spring bean for the intermediate interface.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test to test DAO auto configuration.
|
||||
* Integration test to test repository auto configuration.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test for DAO namespace configuration.
|
||||
* Integration test for repository namespace configuration.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -24,8 +24,8 @@ import org.springframework.data.jpa.repository.support.SimpleJpaRepository;
|
||||
|
||||
|
||||
/**
|
||||
* Sample custom DAO base class implementing common custom functionality for all
|
||||
* derived DAO instances.
|
||||
* Sample custom repository base class implementing common custom functionality
|
||||
* for all derived repository instances.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.springframework.data.repository.support.RepositoryFactorySupport;
|
||||
|
||||
|
||||
/**
|
||||
* {@link GenericDaoFactoryBean} to return a custom DAO base class.
|
||||
* {@link JpaRepositoryFactoryBean} to return a custom repository base class.
|
||||
*
|
||||
* @author Gil Markham
|
||||
* @author Oliver Gierke
|
||||
|
||||
@@ -20,8 +20,8 @@ import org.springframework.data.jpa.domain.sample.User;
|
||||
|
||||
|
||||
/**
|
||||
* Custom Extended DAO interface for a {@code User}. This relies on the custom
|
||||
* intermediate DAO interface {@link CustomGenericRepository}.
|
||||
* Custom Extended repository interface for a {@code User}. This relies on the
|
||||
* custom intermediate repository interface {@link CustomGenericRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -56,7 +56,7 @@ public class JpaQueryMethodUnitTests {
|
||||
@Mock
|
||||
EntityManager em;
|
||||
|
||||
Method daoMethod, invalidReturnType, pageableAndSort, pageableTwice,
|
||||
Method repositoryMethod, invalidReturnType, pageableAndSort, pageableTwice,
|
||||
sortableTwice, modifyingMethod;
|
||||
|
||||
|
||||
@@ -66,21 +66,21 @@ public class JpaQueryMethodUnitTests {
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
daoMethod =
|
||||
repositoryMethod =
|
||||
UserRepository.class.getMethod("findByLastname", String.class);
|
||||
|
||||
invalidReturnType =
|
||||
InvalidDao.class.getMethod(METHOD_NAME, String.class,
|
||||
InvalidRepository.class.getMethod(METHOD_NAME, String.class,
|
||||
Pageable.class);
|
||||
pageableAndSort =
|
||||
InvalidDao.class.getMethod(METHOD_NAME, String.class,
|
||||
InvalidRepository.class.getMethod(METHOD_NAME, String.class,
|
||||
Pageable.class, Sort.class);
|
||||
pageableTwice =
|
||||
InvalidDao.class.getMethod(METHOD_NAME, String.class,
|
||||
InvalidRepository.class.getMethod(METHOD_NAME, String.class,
|
||||
Pageable.class, Pageable.class);
|
||||
|
||||
sortableTwice =
|
||||
InvalidDao.class.getMethod(METHOD_NAME, String.class,
|
||||
InvalidRepository.class.getMethod(METHOD_NAME, String.class,
|
||||
Sort.class, Sort.class);
|
||||
modifyingMethod =
|
||||
UserRepository.class
|
||||
@@ -91,7 +91,8 @@ public class JpaQueryMethodUnitTests {
|
||||
@Test
|
||||
public void testname() {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
|
||||
assertEquals("User.findByLastname", method.getNamedQueryName());
|
||||
assertThat(method.getExecution(), is(CollectionExecution.class));
|
||||
@@ -99,7 +100,7 @@ public class JpaQueryMethodUnitTests {
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullDaoMethod() {
|
||||
public void preventsNullRepositoryMethod() {
|
||||
|
||||
new JpaQueryMethod(null, extractor, em);
|
||||
}
|
||||
@@ -108,37 +109,39 @@ public class JpaQueryMethodUnitTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullEntityManager() {
|
||||
|
||||
new JpaQueryMethod(daoMethod, extractor, null);
|
||||
new JpaQueryMethod(repositoryMethod, extractor, null);
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullQueryExtractor() {
|
||||
|
||||
new JpaQueryMethod(daoMethod, null, em);
|
||||
new JpaQueryMethod(repositoryMethod, null, em);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void returnsCorrectName() {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
assertEquals(daoMethod.getName(), method.getName());
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
assertEquals(repositoryMethod.getName(), method.getName());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void returnsQueryIfAvailable() throws Exception {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
|
||||
assertNull(method.getAnnotatedQuery());
|
||||
|
||||
Method daoMethod =
|
||||
Method repositoryMethod =
|
||||
UserRepository.class.getMethod("findByAnnotatedQuery",
|
||||
String.class);
|
||||
|
||||
assertNotNull(new JpaQueryMethod(daoMethod, extractor, em)
|
||||
assertNotNull(new JpaQueryMethod(repositoryMethod, extractor, em)
|
||||
.getAnnotatedQuery());
|
||||
}
|
||||
|
||||
@@ -146,7 +149,8 @@ public class JpaQueryMethodUnitTests {
|
||||
@Test
|
||||
public void returnsCorrectDomainClassName() {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
assertEquals(DOMAIN_CLASS, method.getDomainClass());
|
||||
}
|
||||
|
||||
@@ -154,8 +158,9 @@ public class JpaQueryMethodUnitTests {
|
||||
@Test
|
||||
public void returnsCorrectNumberOfParameters() {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
assertTrue(method.isCorrectNumberOfParameters(daoMethod
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
assertTrue(method.isCorrectNumberOfParameters(repositoryMethod
|
||||
.getParameterTypes().length));
|
||||
}
|
||||
|
||||
@@ -215,7 +220,7 @@ public class JpaQueryMethodUnitTests {
|
||||
public void rejectsModifyingMethodWithPageable() throws Exception {
|
||||
|
||||
Method method =
|
||||
InvalidDao.class.getMethod("updateMethod", String.class,
|
||||
InvalidRepository.class.getMethod("updateMethod", String.class,
|
||||
Pageable.class);
|
||||
|
||||
new JpaQueryMethod(method, extractor, em);
|
||||
@@ -226,7 +231,7 @@ public class JpaQueryMethodUnitTests {
|
||||
public void rejectsModifyingMethodWithSort() throws Exception {
|
||||
|
||||
Method method =
|
||||
InvalidDao.class.getMethod("updateMethod", String.class,
|
||||
InvalidRepository.class.getMethod("updateMethod", String.class,
|
||||
Sort.class);
|
||||
|
||||
new JpaQueryMethod(method, extractor, em);
|
||||
@@ -236,7 +241,8 @@ public class JpaQueryMethodUnitTests {
|
||||
@Test
|
||||
public void discoversHintsCorrectly() {
|
||||
|
||||
JpaQueryMethod method = new JpaQueryMethod(daoMethod, extractor, em);
|
||||
JpaQueryMethod method =
|
||||
new JpaQueryMethod(repositoryMethod, extractor, em);
|
||||
List<QueryHint> hints = method.getHints();
|
||||
|
||||
assertNotNull(hints);
|
||||
@@ -245,11 +251,11 @@ public class JpaQueryMethodUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Interface to define invalid DAO methods for testing.
|
||||
* Interface to define invalid repository methods for testing.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
static interface InvalidDao {
|
||||
static interface InvalidRepository {
|
||||
|
||||
// Invalid return type
|
||||
User findByFirstname(String firstname, Pageable pageable);
|
||||
|
||||
@@ -55,12 +55,13 @@ public class ParameterBinderUnitTests {
|
||||
@Before
|
||||
public void setUp() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
valid = SampleDao.class.getMethod("valid", String.class);
|
||||
valid = SampleRepository.class.getMethod("valid", String.class);
|
||||
|
||||
useIndexedParameters =
|
||||
SampleDao.class.getMethod("useIndexedParameters", String.class);
|
||||
SampleRepository.class.getMethod("useIndexedParameters",
|
||||
String.class);
|
||||
indexedParametersWithSort =
|
||||
SampleDao.class.getMethod("indexedParameterWithSort",
|
||||
SampleRepository.class.getMethod("indexedParameterWithSort",
|
||||
String.class, Sort.class);
|
||||
}
|
||||
|
||||
@@ -68,7 +69,7 @@ public class ParameterBinderUnitTests {
|
||||
|
||||
}
|
||||
|
||||
static interface SampleDao {
|
||||
static interface SampleRepository {
|
||||
|
||||
User useIndexedParameters(String lastname);
|
||||
|
||||
@@ -116,8 +117,8 @@ public class ParameterBinderUnitTests {
|
||||
NoSuchMethodException {
|
||||
|
||||
Method method =
|
||||
SampleDao.class.getMethod("validWithPageable", String.class,
|
||||
Pageable.class);
|
||||
SampleRepository.class.getMethod("validWithPageable",
|
||||
String.class, Pageable.class);
|
||||
|
||||
Parameters parameters = new Parameters(method);
|
||||
ParameterBinder binder =
|
||||
@@ -131,7 +132,7 @@ public class ParameterBinderUnitTests {
|
||||
public void bindWorksWithNullForSort() throws Exception {
|
||||
|
||||
Method validWithSort =
|
||||
SampleDao.class.getMethod("validWithSort", String.class,
|
||||
SampleRepository.class.getMethod("validWithSort", String.class,
|
||||
Sort.class);
|
||||
|
||||
new ParameterBinder(new Parameters(validWithSort), new Object[] {
|
||||
@@ -144,8 +145,8 @@ public class ParameterBinderUnitTests {
|
||||
public void bindWorksWithNullForPageable() throws Exception {
|
||||
|
||||
Method validWithPageable =
|
||||
SampleDao.class.getMethod("validWithPageable", String.class,
|
||||
Pageable.class);
|
||||
SampleRepository.class.getMethod("validWithPageable",
|
||||
String.class, Pageable.class);
|
||||
|
||||
new ParameterBinder(new Parameters(validWithPageable), new Object[] {
|
||||
"foo", null }).bind(query);
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
/**
|
||||
* DAO interface for {@code AuditableUser}.
|
||||
* Repository interface for {@code AuditableUser}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -33,8 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* DAO interface for {@code User}s. The declared methods will trigger named
|
||||
* queries as they start with {@code findBy}.
|
||||
* Repository interface for {@code User}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.data.jpa.domain.sample.User;
|
||||
|
||||
|
||||
/**
|
||||
* Simple interface for custom methods on the DAO for {@code User}s.
|
||||
* Simple interface for custom methods on the repository for {@code User}s.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* Assures the injected DAO instances are wired to the customly configured
|
||||
* {@link EntityManagerFactory}.
|
||||
* Assures the injected repository instances are wired to the customly
|
||||
* configured {@link EntityManagerFactory}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@@ -43,7 +43,7 @@ public class EntityManagerFactoryRefTests {
|
||||
UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
AuditableUserRepository auditableUserDao;
|
||||
AuditableUserRepository auditableUserRepository;
|
||||
|
||||
|
||||
@Test
|
||||
@@ -57,8 +57,8 @@ public class EntityManagerFactoryRefTests {
|
||||
|
||||
@Test
|
||||
@Transactional("transactionManager-2")
|
||||
public void useAuditableUserDao() throws Exception {
|
||||
public void useAuditableUserRepository() throws Exception {
|
||||
|
||||
auditableUserDao.saveAndFlush(new AuditableUser());
|
||||
auditableUserRepository.saveAndFlush(new AuditableUser());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,8 +36,8 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
|
||||
/**
|
||||
* Assures the injected DAO instances are wired to the customly configured
|
||||
* {@link EntityManagerFactory}.
|
||||
* Assures the injected repository instances are wired to the customly
|
||||
* configured {@link EntityManagerFactory}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@@ -55,7 +55,8 @@ public class EntityManagerFactoryRefUnitTests extends
|
||||
|
||||
|
||||
@Test
|
||||
public void daosGetTheSecondEntityManagerFactoryInjected() throws Exception {
|
||||
public void repositoriesGetTheSecondEntityManagerFactoryInjected()
|
||||
throws Exception {
|
||||
|
||||
verify(first, never()).createEntityManager();
|
||||
verify(second, atLeastOnce()).createEntityManager();
|
||||
|
||||
@@ -38,7 +38,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@code GenericDaoFactoryBean}.
|
||||
* Unit test for {@code JpaRepositoryFactoryBean}.
|
||||
* <p>
|
||||
* TODO: Check if test methods double the ones in
|
||||
* {@link JpaRepositoryFactoryUnitTests}.
|
||||
@@ -80,7 +80,7 @@ public class JpaRepositoryFactoryBeanUnitTests {
|
||||
|
||||
/**
|
||||
* Assert that the instance created for the standard configuration is a
|
||||
* valid {@code UserDao}.
|
||||
* valid {@code UserRepository}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -103,22 +103,23 @@ public class JpaRepositoryFactoryBeanUnitTests {
|
||||
|
||||
/**
|
||||
* Assert that the factory rejects calls to
|
||||
* {@code GenericDaoFactoryBean#setDaoInterface(Class)} with {@code null} or
|
||||
* any other parameter instance not implementing {@code GenericDao}.
|
||||
* {@code JpaRepositoryFactoryBean#setRepositoryInterface(Class)} with
|
||||
* {@literal null} or any other parameter instance not implementing
|
||||
* {@code Repository}.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsNullDaoInterface() {
|
||||
public void preventsNullRepositoryInterface() {
|
||||
|
||||
factory.setRepositoryInterface(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Assert that the factory detects unset DAO class and interface in
|
||||
* {@code GenericDaoFactoryBean#afterPropertiesSet()}.
|
||||
* Assert that the factory detects unset repository class and interface in
|
||||
* {@code JpaRepositoryFactoryBean#afterPropertiesSet()}.
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void preventsUnsetDaoInterface() throws Exception {
|
||||
public void preventsUnsetRepositoryInterface() throws Exception {
|
||||
|
||||
factory = new JpaRepositoryFactoryBean<SimpleSampleRepository>();
|
||||
factory.afterPropertiesSet();
|
||||
@@ -126,10 +127,11 @@ public class JpaRepositoryFactoryBeanUnitTests {
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that the factory recognized configured DAO classes that contain
|
||||
* custom method but no custom implementation could be found. Furthremore
|
||||
* the exception has to contain the name of the DAO interface as for a large
|
||||
* DAO configuration it's hard to find out where this error occured.
|
||||
* Asserts that the factory recognized configured repository classes that
|
||||
* contain custom method but no custom implementation could be found.
|
||||
* Furthremore the exception has to contain the name of the repository
|
||||
* interface as for a large repository configuration it's hard to find out
|
||||
* where this error occured.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -160,13 +162,13 @@ public class JpaRepositoryFactoryBeanUnitTests {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private interface SampleCustomDao {
|
||||
private interface SampleCustomRepository {
|
||||
|
||||
void someSampleMethod();
|
||||
}
|
||||
|
||||
private interface SampleRepository extends JpaRepository<User, Integer>,
|
||||
SampleCustomDao {
|
||||
SampleCustomRepository {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* Unit test for {@code GenericDaoFactoryBean}.
|
||||
* Unit test for {@code JpaRepositoryFactory}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
@@ -58,33 +58,35 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
|
||||
/**
|
||||
* Assert that the instance created for the standard configuration is a
|
||||
* valid {@code UserDao}.
|
||||
* valid {@code UserRepository}.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void setsUpBasicInstanceCorrectly() throws Exception {
|
||||
|
||||
assertNotNull(factory.getRepository(SimpleSampleDao.class));
|
||||
assertNotNull(factory.getRepository(SimpleSampleRepository.class));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void allowsCallingOfObjectMethods() {
|
||||
|
||||
SimpleSampleDao userDao = factory.getRepository(SimpleSampleDao.class);
|
||||
SimpleSampleRepository repository =
|
||||
factory.getRepository(SimpleSampleRepository.class);
|
||||
|
||||
userDao.hashCode();
|
||||
userDao.toString();
|
||||
userDao.equals(userDao);
|
||||
repository.hashCode();
|
||||
repository.toString();
|
||||
repository.equals(repository);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Asserts that the factory recognized configured DAO classes that contain
|
||||
* custom method but no custom implementation could be found. Furthremore
|
||||
* the exception has to contain the name of the DAO interface as for a large
|
||||
* DAO configuration it's hard to find out where this error occured.
|
||||
* Asserts that the factory recognized configured repository classes that
|
||||
* contain custom method but no custom implementation could be found.
|
||||
* Furthremore the exception has to contain the name of the repository
|
||||
* interface as for a large repository configuration it's hard to find out
|
||||
* where this error occured.
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@@ -93,9 +95,10 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
throws Exception {
|
||||
|
||||
try {
|
||||
factory.getRepository(SampleDao.class);
|
||||
factory.getRepository(SampleRepository.class);
|
||||
} catch (IllegalArgumentException e) {
|
||||
assertTrue(e.getMessage().contains(SampleDao.class.getName()));
|
||||
assertTrue(e.getMessage()
|
||||
.contains(SampleRepository.class.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,20 +106,20 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void handlesRuntimeExceptionsCorrectly() {
|
||||
|
||||
SampleDao dao =
|
||||
factory.getRepository(SampleDao.class,
|
||||
new SampleCustomDaoImpl());
|
||||
dao.throwingRuntimeException();
|
||||
SampleRepository repository =
|
||||
factory.getRepository(SampleRepository.class,
|
||||
new SampleCustomRepositoryImpl());
|
||||
repository.throwingRuntimeException();
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = IOException.class)
|
||||
public void handlesCheckedExceptionsCorrectly() throws Exception {
|
||||
|
||||
SampleDao dao =
|
||||
factory.getRepository(SampleDao.class,
|
||||
new SampleCustomDaoImpl());
|
||||
dao.throwingCheckedException();
|
||||
SampleRepository repository =
|
||||
factory.getRepository(SampleRepository.class,
|
||||
new SampleCustomRepositoryImpl());
|
||||
repository.throwingCheckedException();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,13 +128,14 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
|
||||
JpaRepositoryFactory factory =
|
||||
new CustomGenericJpaRepositoryFactory(entityManager);
|
||||
UserCustomExtendedRepository dao =
|
||||
UserCustomExtendedRepository repository =
|
||||
factory.getRepository(UserCustomExtendedRepository.class);
|
||||
|
||||
dao.customMethod(1);
|
||||
repository.customMethod(1);
|
||||
}
|
||||
|
||||
private interface SimpleSampleDao extends JpaRepository<User, Integer> {
|
||||
private interface SimpleSampleRepository extends
|
||||
JpaRepository<User, Integer> {
|
||||
|
||||
@Transactional
|
||||
User readByPrimaryKey(Integer primaryKey);
|
||||
@@ -142,7 +146,7 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public interface SampleCustomDao {
|
||||
public interface SampleCustomRepository {
|
||||
|
||||
void throwingRuntimeException();
|
||||
|
||||
@@ -151,11 +155,11 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementation of the custom DAO interface.
|
||||
* Implementation of the custom repository interface.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
private class SampleCustomDaoImpl implements SampleCustomDao {
|
||||
private class SampleCustomRepositoryImpl implements SampleCustomRepository {
|
||||
|
||||
public void throwingRuntimeException() {
|
||||
|
||||
@@ -169,8 +173,8 @@ public class JpaRepositoryFactoryUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
private interface SampleDao extends JpaRepository<User, Integer>,
|
||||
SampleCustomDao {
|
||||
private interface SampleRepository extends JpaRepository<User, Integer>,
|
||||
SampleCustomRepository {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test for {@link GenericJpaDao}.
|
||||
* Integration test for {@link JpaRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.springframework.transaction.TransactionStatus;
|
||||
|
||||
|
||||
/**
|
||||
* Integration test for transactional behaviour of DAO operations.
|
||||
* Integration test for transactional behaviour of repository operations.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user