Register runtime hints for ApplicationContextInitializers in the TCF
This commit introduces automatic registration of runtime hints for ApplicationContextInitializers configured via the `initializers` attribute in @ContextConfiguration. See gh-29021
This commit is contained in:
@@ -123,6 +123,7 @@ class TestContextAotGeneratorTests extends AbstractAotTests {
|
||||
).forEach(type -> assertReflectionRegistered(runtimeHints, type, INVOKE_PUBLIC_CONSTRUCTORS));
|
||||
|
||||
Set.of(
|
||||
org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer.class,
|
||||
org.springframework.test.context.support.AnnotationConfigContextLoader.class,
|
||||
org.springframework.test.context.support.DefaultTestContextBootstrapper.class,
|
||||
org.springframework.test.context.support.DelegatingSmartContextLoader.class,
|
||||
|
||||
@@ -19,8 +19,11 @@ package org.springframework.test.context.aot.samples.basic;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.aot.samples.basic.BasicSpringTestNGTests.CustomInitializer;
|
||||
import org.springframework.test.context.aot.samples.common.MessageService;
|
||||
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
|
||||
|
||||
@@ -30,8 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Sam Brannen
|
||||
* @since 6.0
|
||||
*/
|
||||
@ContextConfiguration(classes = BasicTestConfiguration.class)
|
||||
@TestPropertySource(properties = "test.engine = testng")
|
||||
@ContextConfiguration(classes = BasicTestConfiguration.class, initializers = CustomInitializer.class)
|
||||
public class BasicSpringTestNGTests extends AbstractTestNGSpringContextTests {
|
||||
|
||||
@Autowired
|
||||
@@ -51,4 +53,14 @@ public class BasicSpringTestNGTests extends AbstractTestNGSpringContextTests {
|
||||
.as("@TestPropertySource").isEqualTo("testng");
|
||||
}
|
||||
|
||||
public static class CustomInitializer implements ApplicationContextInitializer<ConfigurableApplicationContext> {
|
||||
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
applicationContext.getEnvironment().getPropertySources()
|
||||
.addFirst(new MockPropertySource().withProperty("test.engine", "testng"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user