Skip to content

Commit c432288

Browse files
committed
Migrate ApplicationContext to common hierarchy
This commit migrates `AnnotationConfigReactiveWebApplicationContext` parent to the `GenericApplicationContext` abstraction. Any use of `AnnotationConfigWebApplicationContext` is also removed as it also inherits from the `AbstractRefreshableApplicationContext` outdated hierarchy. A new `AnnotationConfigServletWebApplicationContext` context is introduced instead, extending from `GenericApplicationContext` and providing the counter part of the reactive context for the Servlet-based web app tests. See spring-projectsgh-16096
1 parent 4bcc632 commit c432288

File tree

24 files changed

+303
-353
lines changed

24 files changed

+303
-353
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/ControllerEndpointWebMvcIntegrationTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -35,6 +35,7 @@
3535
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
3636
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
3737
import org.springframework.boot.test.util.TestPropertyValues;
38+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3839
import org.springframework.context.annotation.Import;
3940
import org.springframework.http.MediaType;
4041
import org.springframework.mock.web.MockServletContext;
@@ -45,7 +46,6 @@
4546
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
4647
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
4748
import org.springframework.web.bind.annotation.GetMapping;
48-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4949

5050
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
5151
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
@@ -60,7 +60,7 @@
6060
*/
6161
public class ControllerEndpointWebMvcIntegrationTests {
6262

63-
private AnnotationConfigWebApplicationContext context;
63+
private AnnotationConfigServletWebApplicationContext context;
6464

6565
@After
6666
public void close() {
@@ -70,7 +70,7 @@ public void close() {
7070

7171
@Test
7272
public void endpointsAreSecureByDefault() throws Exception {
73-
this.context = new AnnotationConfigWebApplicationContext();
73+
this.context = new AnnotationConfigServletWebApplicationContext();
7474
this.context.register(SecureConfiguration.class, ExampleController.class);
7575
MockMvc mockMvc = createSecureMockMvc();
7676
mockMvc.perform(get("/actuator/example").accept(MediaType.APPLICATION_JSON))
@@ -81,7 +81,7 @@ public void endpointsAreSecureByDefault() throws Exception {
8181
public void endpointsCanBeAccessed() throws Exception {
8282
TestSecurityContextHolder.getContext().setAuthentication(
8383
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
84-
this.context = new AnnotationConfigWebApplicationContext();
84+
this.context = new AnnotationConfigServletWebApplicationContext();
8585
this.context.register(SecureConfiguration.class, ExampleController.class);
8686
TestPropertyValues
8787
.of("management.endpoints.web.base-path:/management",

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointCorsIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
3131
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
3232
import org.springframework.boot.test.util.TestPropertyValues;
33+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3334
import org.springframework.http.HttpHeaders;
3435
import org.springframework.mock.web.MockServletContext;
3536
import org.springframework.test.web.servlet.MockMvc;
3637
import org.springframework.test.web.servlet.ResultActions;
3738
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
38-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3939

4040
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
4141
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
@@ -49,11 +49,11 @@
4949
*/
5050
public class WebMvcEndpointCorsIntegrationTests {
5151

52-
private AnnotationConfigWebApplicationContext context;
52+
private AnnotationConfigServletWebApplicationContext context;
5353

5454
@Before
5555
public void createContext() {
56-
this.context = new AnnotationConfigWebApplicationContext();
56+
this.context = new AnnotationConfigServletWebApplicationContext();
5757
this.context.setServletContext(new MockServletContext());
5858
this.context.register(JacksonAutoConfiguration.class,
5959
HttpMessageConvertersAutoConfiguration.class,

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/integrationtest/WebMvcEndpointIntegrationTests.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
4444
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
4545
import org.springframework.boot.test.util.TestPropertyValues;
46+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
4647
import org.springframework.context.annotation.Bean;
4748
import org.springframework.context.annotation.Configuration;
4849
import org.springframework.context.annotation.Import;
@@ -54,7 +55,6 @@
5455
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
5556
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
5657
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
57-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
5858

5959
import static org.hamcrest.Matchers.both;
6060
import static org.hamcrest.Matchers.hasKey;
@@ -70,7 +70,7 @@
7070
*/
7171
public class WebMvcEndpointIntegrationTests {
7272

73-
private AnnotationConfigWebApplicationContext context;
73+
private AnnotationConfigServletWebApplicationContext context;
7474

7575
@After
7676
public void close() {
@@ -80,7 +80,7 @@ public void close() {
8080

8181
@Test
8282
public void endpointsAreSecureByDefault() throws Exception {
83-
this.context = new AnnotationConfigWebApplicationContext();
83+
this.context = new AnnotationConfigServletWebApplicationContext();
8484
this.context.register(SecureConfiguration.class);
8585
MockMvc mockMvc = createSecureMockMvc();
8686
mockMvc.perform(get("/actuator/beans").accept(MediaType.APPLICATION_JSON))
@@ -89,7 +89,7 @@ public void endpointsAreSecureByDefault() throws Exception {
8989

9090
@Test
9191
public void endpointsAreSecureByDefaultWithCustomBasePath() throws Exception {
92-
this.context = new AnnotationConfigWebApplicationContext();
92+
this.context = new AnnotationConfigServletWebApplicationContext();
9393
this.context.register(SecureConfiguration.class);
9494
TestPropertyValues.of("management.endpoints.web.base-path:/management")
9595
.applyTo(this.context);
@@ -102,7 +102,7 @@ public void endpointsAreSecureByDefaultWithCustomBasePath() throws Exception {
102102
public void endpointsAreSecureWithActuatorRoleWithCustomBasePath() throws Exception {
103103
TestSecurityContextHolder.getContext().setAuthentication(
104104
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
105-
this.context = new AnnotationConfigWebApplicationContext();
105+
this.context = new AnnotationConfigServletWebApplicationContext();
106106
this.context.register(SecureConfiguration.class);
107107
TestPropertyValues
108108
.of("management.endpoints.web.base-path:/management",
@@ -114,7 +114,7 @@ public void endpointsAreSecureWithActuatorRoleWithCustomBasePath() throws Except
114114

115115
@Test
116116
public void linksAreProvidedToAllEndpointTypes() throws Exception {
117-
this.context = new AnnotationConfigWebApplicationContext();
117+
this.context = new AnnotationConfigServletWebApplicationContext();
118118
this.context.register(DefaultConfiguration.class, EndpointsConfiguration.class);
119119
TestPropertyValues.of("management.endpoints.web.exposure.include=*")
120120
.applyTo(this.context);

spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/web/mappings/MappingsEndpointTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.springframework.boot.test.context.runner.ReactiveWebApplicationContextRunner;
4343
import org.springframework.boot.test.context.runner.WebApplicationContextRunner;
4444
import org.springframework.boot.web.servlet.ServletRegistrationBean;
45+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
4546
import org.springframework.context.ApplicationContext;
4647
import org.springframework.context.annotation.Bean;
4748
import org.springframework.context.annotation.Configuration;
@@ -50,7 +51,6 @@
5051
import org.springframework.web.bind.annotation.RequestMapping;
5152
import org.springframework.web.context.ConfigurableWebApplicationContext;
5253
import org.springframework.web.context.WebApplicationContext;
53-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
5454
import org.springframework.web.reactive.config.EnableWebFlux;
5555
import org.springframework.web.reactive.function.server.RouterFunction;
5656
import org.springframework.web.reactive.function.server.ServerResponse;
@@ -133,7 +133,7 @@ private Supplier<ConfigurableWebApplicationContext> prepareContextSupplier() {
133133
given((Map<String, ServletRegistration>) servletContext.getServletRegistrations())
134134
.willReturn(Collections.singletonMap("testServlet", servletRegistration));
135135
return () -> {
136-
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
136+
AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
137137
context.setServletContext(servletContext);
138138
return context;
139139
};

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/condition/ConditionalOnWebApplicationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@
2424
import org.springframework.boot.autoconfigure.web.reactive.MockReactiveWebServerFactory;
2525
import org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebApplicationContext;
2626
import org.springframework.boot.web.reactive.server.ReactiveWebServerFactory;
27+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
2728
import org.springframework.context.ConfigurableApplicationContext;
2829
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
2930
import org.springframework.context.annotation.Bean;
3031
import org.springframework.context.annotation.Configuration;
3132
import org.springframework.http.server.reactive.HttpHandler;
3233
import org.springframework.mock.web.MockServletContext;
33-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3434

3535
import static org.assertj.core.api.Assertions.assertThat;
3636
import static org.assertj.core.api.Assertions.entry;
@@ -54,7 +54,7 @@ public void closeContext() {
5454

5555
@Test
5656
public void testWebApplicationWithServletContext() {
57-
AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
57+
AnnotationConfigServletWebApplicationContext ctx = new AnnotationConfigServletWebApplicationContext();
5858
ctx.register(AnyWebApplicationConfiguration.class,
5959
ServletWebApplicationConfiguration.class,
6060
ReactiveWebApplicationConfiguration.class);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/jpa/JpaWebAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@
2626
import org.springframework.boot.autoconfigure.data.web.SpringDataWebAutoConfiguration;
2727
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
2828
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
29+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
2930
import org.springframework.context.annotation.Configuration;
3031
import org.springframework.data.web.PageableHandlerMethodArgumentResolver;
3132
import org.springframework.format.support.FormattingConversionService;
3233
import org.springframework.mock.web.MockServletContext;
33-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
3434
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
3535

3636
import static org.assertj.core.api.Assertions.assertThat;
@@ -43,7 +43,7 @@
4343
*/
4444
public class JpaWebAutoConfigurationTests {
4545

46-
private AnnotationConfigWebApplicationContext context;
46+
private AnnotationConfigServletWebApplicationContext context;
4747

4848
@After
4949
public void close() {
@@ -52,7 +52,7 @@ public void close() {
5252

5353
@Test
5454
public void testDefaultRepositoryConfiguration() {
55-
this.context = new AnnotationConfigWebApplicationContext();
55+
this.context = new AnnotationConfigServletWebApplicationContext();
5656
this.context.setServletContext(new MockServletContext());
5757
this.context.register(TestConfiguration.class,
5858
EmbeddedDataSourceConfiguration.class,

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/data/rest/RepositoryRestMvcAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.springframework.boot.autoconfigure.jdbc.EmbeddedDataSourceConfiguration;
3131
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
3232
import org.springframework.boot.test.util.TestPropertyValues;
33+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3334
import org.springframework.context.annotation.Bean;
3435
import org.springframework.context.annotation.Configuration;
3536
import org.springframework.context.annotation.Import;
@@ -41,7 +42,6 @@
4142
import org.springframework.http.MediaType;
4243
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;
4344
import org.springframework.mock.web.MockServletContext;
44-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4545
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
4646

4747
import static org.assertj.core.api.Assertions.assertThat;
@@ -55,7 +55,7 @@
5555
*/
5656
public class RepositoryRestMvcAutoConfigurationTests {
5757

58-
private AnnotationConfigWebApplicationContext context;
58+
private AnnotationConfigServletWebApplicationContext context;
5959

6060
@After
6161
public void tearDown() {
@@ -143,7 +143,7 @@ public void backOffWithCustomConfiguration() {
143143
}
144144

145145
private void load(Class<?> config, String... environment) {
146-
AnnotationConfigWebApplicationContext applicationContext = new AnnotationConfigWebApplicationContext();
146+
AnnotationConfigServletWebApplicationContext applicationContext = new AnnotationConfigServletWebApplicationContext();
147147
applicationContext.setServletContext(new MockServletContext());
148148
applicationContext.register(config, BaseConfiguration.class);
149149
TestPropertyValues.of(environment).applyTo(applicationContext);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/freemarker/FreeMarkerAutoConfigurationServletIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131
import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration;
3232
import org.springframework.boot.test.util.TestPropertyValues;
3333
import org.springframework.boot.web.servlet.FilterRegistrationBean;
34+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3435
import org.springframework.boot.web.servlet.filter.OrderedCharacterEncodingFilter;
3536
import org.springframework.context.annotation.Bean;
3637
import org.springframework.context.annotation.Configuration;
3738
import org.springframework.context.annotation.Import;
3839
import org.springframework.mock.web.MockHttpServletRequest;
3940
import org.springframework.mock.web.MockHttpServletResponse;
4041
import org.springframework.mock.web.MockServletContext;
41-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4242
import org.springframework.web.servlet.View;
4343
import org.springframework.web.servlet.resource.ResourceUrlEncodingFilter;
4444
import org.springframework.web.servlet.support.RequestContext;
@@ -57,7 +57,7 @@
5757
*/
5858
public class FreeMarkerAutoConfigurationServletIntegrationTests {
5959

60-
private AnnotationConfigWebApplicationContext context;
60+
private AnnotationConfigServletWebApplicationContext context;
6161

6262
@After
6363
public void close() {
@@ -206,7 +206,7 @@ private void load(String... env) {
206206
}
207207

208208
private void load(Class<?> config, String... env) {
209-
this.context = new AnnotationConfigWebApplicationContext();
209+
this.context = new AnnotationConfigServletWebApplicationContext();
210210
this.context.setServletContext(new MockServletContext());
211211
TestPropertyValues.of(env).applyTo(this.context);
212212
this.context.register(config);

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/groovy/template/GroovyTemplateAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -32,12 +32,12 @@
3232

3333
import org.springframework.boot.test.util.TestPropertyValues;
3434
import org.springframework.boot.testsupport.BuildOutput;
35+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
3536
import org.springframework.context.i18n.LocaleContextHolder;
3637
import org.springframework.core.io.ClassPathResource;
3738
import org.springframework.mock.web.MockHttpServletRequest;
3839
import org.springframework.mock.web.MockHttpServletResponse;
3940
import org.springframework.mock.web.MockServletContext;
40-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
4141
import org.springframework.web.servlet.View;
4242
import org.springframework.web.servlet.ViewResolver;
4343
import org.springframework.web.servlet.support.RequestContext;
@@ -56,7 +56,7 @@ public class GroovyTemplateAutoConfigurationTests {
5656

5757
private final BuildOutput buildOutput = new BuildOutput(getClass());
5858

59-
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
59+
private AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
6060

6161
@Before
6262
public void setupContext() {

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/h2/H2ConsoleAutoConfigurationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -23,8 +23,8 @@
2323
import org.springframework.beans.factory.BeanCreationException;
2424
import org.springframework.boot.test.util.TestPropertyValues;
2525
import org.springframework.boot.web.servlet.ServletRegistrationBean;
26+
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
2627
import org.springframework.mock.web.MockServletContext;
27-
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
2828

2929
import static org.assertj.core.api.Assertions.assertThat;
3030
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
@@ -38,7 +38,7 @@
3838
*/
3939
public class H2ConsoleAutoConfigurationTests {
4040

41-
private AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
41+
private AnnotationConfigServletWebApplicationContext context = new AnnotationConfigServletWebApplicationContext();
4242

4343
@Before
4444
public void setupContext() {

0 commit comments

Comments
 (0)