Merge branch '2.2.x' into 2.3.x

pull/21793/head
Stephane Nicoll 5 years ago
commit 7fe85750fb

@ -16,21 +16,21 @@
package org.springframework.boot.autoconfigure.data.jpa; package org.springframework.boot.autoconfigure.data.jpa;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage; import org.springframework.boot.autoconfigure.TestAutoConfigurationPackage;
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.autoconfigure.data.jpa.city.City; import org.springframework.boot.autoconfigure.data.jpa.city.City;
import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository; import org.springframework.boot.autoconfigure.data.jpa.city.CityRepository;
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration; import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext; import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.data.geo.Distance;
import org.springframework.data.web.PageableHandlerMethodArgumentResolver; import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
import org.springframework.data.web.SortHandlerMethodArgumentResolver;
import org.springframework.format.support.FormattingConversionService; import org.springframework.format.support.FormattingConversionService;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -40,27 +40,25 @@ import static org.assertj.core.api.Assertions.assertThat;
* {@link JpaRepositoriesAutoConfiguration}. * {@link JpaRepositoriesAutoConfiguration}.
* *
* @author Dave Syer * @author Dave Syer
* @author Stephane Nicoll
*/ */
class JpaWebAutoConfigurationTests { class JpaWebAutoConfigurationTests {
private AnnotationConfigServletWebApplicationContext context; private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
.withConfiguration(
@AfterEach AutoConfigurations.of(DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class,
void close() { JpaRepositoriesAutoConfiguration.class, SpringDataWebAutoConfiguration.class))
this.context.close(); .withPropertyValues("spring.datasource.generate-unique-name=true");
}
@Test @Test
void testDefaultRepositoryConfiguration() { void springDataWebIsConfiguredWithJpaRepositories() {
this.context = new AnnotationConfigServletWebApplicationContext(); this.contextRunner.withUserConfiguration(TestConfiguration.class).run((context) -> {
this.context.setServletContext(new MockServletContext()); assertThat(context).hasSingleBean(CityRepository.class);
this.context.register(TestConfiguration.class, EmbeddedDataSourceConfiguration.class, assertThat(context).hasSingleBean(PageableHandlerMethodArgumentResolver.class);
HibernateJpaAutoConfiguration.class, JpaRepositoriesAutoConfiguration.class, assertThat(context).hasSingleBean(SortHandlerMethodArgumentResolver.class);
SpringDataWebAutoConfiguration.class, PropertyPlaceholderAutoConfiguration.class); assertThat(context.getBean(FormattingConversionService.class).canConvert(String.class, Distance.class))
this.context.refresh(); .isTrue();
assertThat(this.context.getBean(CityRepository.class)).isNotNull(); });
assertThat(this.context.getBean(PageableHandlerMethodArgumentResolver.class)).isNotNull();
assertThat(this.context.getBean(FormattingConversionService.class).canConvert(Long.class, City.class)).isTrue();
} }
@Configuration(proxyBeanMethods = false) @Configuration(proxyBeanMethods = false)

Loading…
Cancel
Save