From aebaa580db050a94e945c35b99a5bfdc0de4f5d4 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Thu, 9 Jan 2014 11:14:18 +0000 Subject: [PATCH] Add test for user overriding @EnableJpaRepositories --- ...JpaRepositoriesAutoConfigurationTests.java | 24 +++++++++++++++++++ .../data/alt/CityRepository.java | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityRepository.java diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java index 0bdc4b2249e..fe25443d802 100644 --- a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/JpaRepositoriesAutoConfigurationTests.java @@ -28,6 +28,7 @@ import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfigurat import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.data.jpa.repository.config.EnableJpaRepositories; import org.springframework.transaction.PlatformTransactionManager; import static org.junit.Assert.assertNotNull; @@ -56,10 +57,33 @@ public class JpaRepositoriesAutoConfigurationTests { assertNotNull(this.context.getBean(EntityManagerFactory.class)); } + @Test + public void testOverrideRepositoryConfiguration() throws Exception { + this.context = new AnnotationConfigApplicationContext(); + this.context.register(CustomConfiguration.class, + ComponentScanDetectorConfiguration.class, + EmbeddedDataSourceConfiguration.class, + HibernateJpaAutoConfiguration.class, + JpaRepositoriesAutoConfiguration.class, + PropertyPlaceholderAutoConfiguration.class); + this.context.refresh(); + assertNotNull(this.context + .getBean(org.springframework.boot.autoconfigure.data.alt.CityRepository.class)); + assertNotNull(this.context.getBean(PlatformTransactionManager.class)); + assertNotNull(this.context.getBean(EntityManagerFactory.class)); + } + @Configuration @ComponentScan(basePackageClasses = City.class) protected static class TestConfiguration { } + @Configuration + @EnableJpaRepositories(basePackageClasses = org.springframework.boot.autoconfigure.data.alt.CityRepository.class) + @ComponentScan(basePackageClasses = City.class) + protected static class CustomConfiguration { + + } + } diff --git a/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityRepository.java b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityRepository.java new file mode 100644 index 00000000000..e52ff7dbe83 --- /dev/null +++ b/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/alt/CityRepository.java @@ -0,0 +1,24 @@ +/* + * Copyright 2012-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.boot.autoconfigure.data.alt; + +import org.springframework.boot.autoconfigure.data.jpa.City; +import org.springframework.data.repository.Repository; + +public interface CityRepository extends Repository { + +}