|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2018 the original author or authors.
|
|
|
|
* Copyright 2012-2019 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.
|
|
|
@ -37,6 +37,7 @@ import org.springframework.boot.test.context.assertj.AssertableApplicationContex
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
|
|
import org.springframework.boot.test.context.runner.ContextConsumer;
|
|
|
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
|
|
|
|
|
|
|
|
import org.springframework.boot.web.servlet.FilterRegistrationBean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
|
import org.springframework.context.annotation.Primary;
|
|
|
@ -158,6 +159,32 @@ public abstract class AbstractJpaAutoConfigurationTests {
|
|
|
|
.doesNotHaveBean(OpenEntityManagerInViewInterceptor.class));
|
|
|
|
.doesNotHaveBean(OpenEntityManagerInViewInterceptor.class));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void openEntityManagerInViewInterceptorIsNotRegisteredWhenFilterRegistrationPresent() {
|
|
|
|
|
|
|
|
new WebApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
|
|
|
|
|
|
|
.withUserConfiguration(TestFilterRegistrationConfiguration.class)
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(
|
|
|
|
|
|
|
|
DataSourceAutoConfiguration.class,
|
|
|
|
|
|
|
|
TransactionAutoConfiguration.class, this.autoConfiguredClass))
|
|
|
|
|
|
|
|
.run((context) -> assertThat(context)
|
|
|
|
|
|
|
|
.doesNotHaveBean(OpenEntityManagerInViewInterceptor.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void openEntityManagerInViewInterceptorAutoConfigurationBacksOffWhenManuallyRegistered() {
|
|
|
|
|
|
|
|
new WebApplicationContextRunner()
|
|
|
|
|
|
|
|
.withPropertyValues("spring.datasource.generate-unique-name=true")
|
|
|
|
|
|
|
|
.withUserConfiguration(TestInterceptorManualConfiguration.class)
|
|
|
|
|
|
|
|
.withConfiguration(AutoConfigurations.of(
|
|
|
|
|
|
|
|
DataSourceAutoConfiguration.class,
|
|
|
|
|
|
|
|
TransactionAutoConfiguration.class, this.autoConfiguredClass))
|
|
|
|
|
|
|
|
.run((context) -> assertThat(context)
|
|
|
|
|
|
|
|
.getBean(OpenEntityManagerInViewInterceptor.class)
|
|
|
|
|
|
|
|
.isExactlyInstanceOf(
|
|
|
|
|
|
|
|
TestInterceptorManualConfiguration.ManualOpenEntityManagerInViewInterceptor.class));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void openEntityManagerInViewInterceptorISNotRegisteredWhenExplicitlyOff() {
|
|
|
|
public void openEntityManagerInViewInterceptorISNotRegisteredWhenExplicitlyOff() {
|
|
|
|
new WebApplicationContextRunner()
|
|
|
|
new WebApplicationContextRunner()
|
|
|
@ -295,6 +322,33 @@ public abstract class AbstractJpaAutoConfigurationTests {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@TestAutoConfigurationPackage(City.class)
|
|
|
|
|
|
|
|
protected static class TestFilterRegistrationConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
public FilterRegistrationBean<OpenEntityManagerInViewFilter> OpenEntityManagerInViewFilterFilterRegistrationBean() {
|
|
|
|
|
|
|
|
return new FilterRegistrationBean<>();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
|
|
|
|
@TestAutoConfigurationPackage(City.class)
|
|
|
|
|
|
|
|
protected static class TestInterceptorManualConfiguration {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
|
|
|
public OpenEntityManagerInViewInterceptor openEntityManagerInViewInterceptor() {
|
|
|
|
|
|
|
|
return new ManualOpenEntityManagerInViewInterceptor();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected static class ManualOpenEntityManagerInViewInterceptor
|
|
|
|
|
|
|
|
extends OpenEntityManagerInViewInterceptor {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Configuration
|
|
|
|
@Configuration
|
|
|
|
protected static class TestConfigurationWithLocalContainerEntityManagerFactoryBean
|
|
|
|
protected static class TestConfigurationWithLocalContainerEntityManagerFactoryBean
|
|
|
|
extends TestConfiguration {
|
|
|
|
extends TestConfiguration {
|
|
|
|