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 gh-16096
This commit is contained in:
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,6 +35,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
@@ -45,7 +46,6 @@ import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
@@ -60,7 +60,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*/
|
||||
public class ControllerEndpointWebMvcIntegrationTests {
|
||||
|
||||
private AnnotationConfigWebApplicationContext context;
|
||||
private AnnotationConfigServletWebApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
@@ -70,7 +70,7 @@ public class ControllerEndpointWebMvcIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void endpointsAreSecureByDefault() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class, ExampleController.class);
|
||||
MockMvc mockMvc = createSecureMockMvc();
|
||||
mockMvc.perform(get("/actuator/example").accept(MediaType.APPLICATION_JSON))
|
||||
@@ -81,7 +81,7 @@ public class ControllerEndpointWebMvcIntegrationTests {
|
||||
public void endpointsCanBeAccessed() throws Exception {
|
||||
TestSecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class, ExampleController.class);
|
||||
TestPropertyValues
|
||||
.of("management.endpoints.web.base-path:/management",
|
||||
|
||||
@@ -30,12 +30,12 @@ import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.mock.web.MockServletContext;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.options;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.header;
|
||||
@@ -49,11 +49,11 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*/
|
||||
public class WebMvcEndpointCorsIntegrationTests {
|
||||
|
||||
private AnnotationConfigWebApplicationContext context;
|
||||
private AnnotationConfigServletWebApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void createContext() {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.setServletContext(new MockServletContext());
|
||||
this.context.register(JacksonAutoConfiguration.class,
|
||||
HttpMessageConvertersAutoConfiguration.class,
|
||||
|
||||
@@ -43,6 +43,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
|
||||
import org.springframework.boot.autoconfigure.web.servlet.DispatcherServletAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration;
|
||||
import org.springframework.boot.test.util.TestPropertyValues;
|
||||
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -54,7 +55,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcConfigurer;
|
||||
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
|
||||
|
||||
import static org.hamcrest.Matchers.both;
|
||||
import static org.hamcrest.Matchers.hasKey;
|
||||
@@ -70,7 +70,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
||||
*/
|
||||
public class WebMvcEndpointIntegrationTests {
|
||||
|
||||
private AnnotationConfigWebApplicationContext context;
|
||||
private AnnotationConfigServletWebApplicationContext context;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
@@ -80,7 +80,7 @@ public class WebMvcEndpointIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void endpointsAreSecureByDefault() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class);
|
||||
MockMvc mockMvc = createSecureMockMvc();
|
||||
mockMvc.perform(get("/actuator/beans").accept(MediaType.APPLICATION_JSON))
|
||||
@@ -89,7 +89,7 @@ public class WebMvcEndpointIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void endpointsAreSecureByDefaultWithCustomBasePath() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class);
|
||||
TestPropertyValues.of("management.endpoints.web.base-path:/management")
|
||||
.applyTo(this.context);
|
||||
@@ -102,7 +102,7 @@ public class WebMvcEndpointIntegrationTests {
|
||||
public void endpointsAreSecureWithActuatorRoleWithCustomBasePath() throws Exception {
|
||||
TestSecurityContextHolder.getContext().setAuthentication(
|
||||
new TestingAuthenticationToken("user", "N/A", "ROLE_ACTUATOR"));
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(SecureConfiguration.class);
|
||||
TestPropertyValues
|
||||
.of("management.endpoints.web.base-path:/management",
|
||||
@@ -114,7 +114,7 @@ public class WebMvcEndpointIntegrationTests {
|
||||
|
||||
@Test
|
||||
public void linksAreProvidedToAllEndpointTypes() throws Exception {
|
||||
this.context = new AnnotationConfigWebApplicationContext();
|
||||
this.context = new AnnotationConfigServletWebApplicationContext();
|
||||
this.context.register(DefaultConfiguration.class, EndpointsConfiguration.class);
|
||||
TestPropertyValues.of("management.endpoints.web.exposure.include=*")
|
||||
.applyTo(this.context);
|
||||
|
||||
Reference in New Issue
Block a user