Register runtime hint for @WebAppConfiguration's resource path
This commit introduces automatic registration of a runtime hint for classpath resources configured via the `value` attribute in @WebAppConfiguration. Closes gh-29026
This commit is contained in:
@@ -172,9 +172,13 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
|
||||
assertThat(resource().forResource("/org/springframework/test/context/aot/samples/xml/test-config.xml"))
|
||||
.accepts(runtimeHints);
|
||||
|
||||
// @TestPropertySource(locations = ... )
|
||||
// @TestPropertySource(locations = ...)
|
||||
assertThat(resource().forResource("/org/springframework/test/context/aot/samples/basic/BasicSpringVintageTests.properties"))
|
||||
.accepts(runtimeHints);
|
||||
|
||||
// @WebAppConfiguration(value = ...)
|
||||
assertThat(resource().forResource("/META-INF/web-resources/resources/Spring.js")).accepts(runtimeHints);
|
||||
assertThat(resource().forResource("/META-INF/web-resources/WEB-INF/views/home.jsp")).accepts(runtimeHints);
|
||||
}
|
||||
|
||||
private static void assertReflectionRegistered(RuntimeHints runtimeHints, String type, MemberCategory memberCategory) {
|
||||
@@ -328,9 +332,9 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
|
||||
"org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext005_ApplicationContextInitializer.java",
|
||||
"org/springframework/test/context/aot/samples/web/WebSpringJupiterTests__TestContext005_BeanFactoryRegistrations.java",
|
||||
"org/springframework/test/context/aot/samples/web/WebTestConfiguration__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/web/reactive/config/DelegatingWebFluxConfiguration__TestContext005_Autowiring.java",
|
||||
"org/springframework/web/reactive/config/DelegatingWebFluxConfiguration__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/web/reactive/config/WebFluxConfigurationSupport__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext005_Autowiring.java",
|
||||
"org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration__TestContext005_BeanDefinitions.java",
|
||||
"org/springframework/web/servlet/config/annotation/WebMvcConfigurationSupport__TestContext005_BeanDefinitions.java",
|
||||
// XmlSpringJupiterTests
|
||||
"org/springframework/context/event/DefaultEventListenerFactory__TestContext006_BeanDefinitions.java",
|
||||
"org/springframework/context/event/EventListenerMethodProcessor__TestContext006_BeanDefinitions.java",
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.web.context.WebApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
@@ -33,7 +34,7 @@ import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppC
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
@SpringJUnitWebConfig(WebTestConfiguration.class)
|
||||
@SpringJUnitWebConfig(classes = WebTestConfiguration.class, resourcePath = "classpath:META-INF/web-resources")
|
||||
@TestPropertySource(properties = "test.engine = jupiter")
|
||||
public class WebSpringJupiterTests {
|
||||
|
||||
@@ -49,7 +50,7 @@ public class WebSpringJupiterTests {
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
void test(@Value("${test.engine}") String testEngine) throws Exception {
|
||||
void controller(@Value("${test.engine}") String testEngine) throws Exception {
|
||||
assertThat(testEngine)
|
||||
.as("@Value").isEqualTo("jupiter");
|
||||
assertThat(wac.getEnvironment().getProperty("test.engine"))
|
||||
@@ -59,4 +60,13 @@ public class WebSpringJupiterTests {
|
||||
.andExpectAll(status().isOk(), content().string("Hello, AOT!"));
|
||||
}
|
||||
|
||||
@org.junit.jupiter.api.Test
|
||||
void resources() throws Exception {
|
||||
this.mockMvc.perform(get("/resources/Spring.js"))
|
||||
.andExpectAll(
|
||||
content().contentType("application/javascript"),
|
||||
content().string(containsString("Spring={};"))
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,19 +18,26 @@ package org.springframework.test.context.aot.samples.web;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.reactive.config.EnableWebFlux;
|
||||
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
|
||||
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@EnableWebFlux
|
||||
class WebTestConfiguration {
|
||||
@EnableWebMvc
|
||||
class WebTestConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Bean
|
||||
MessageController messageController() {
|
||||
return new MessageController();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addResourceHandlers(ResourceHandlerRegistry registry) {
|
||||
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user