|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2021 the original author or authors.
|
|
|
|
|
* Copyright 2012-2022 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.
|
|
|
|
@ -23,6 +23,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
|
|
|
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
|
|
|
|
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
|
|
|
|
import org.springframework.context.ConfigurableApplicationContext;
|
|
|
|
|
import org.springframework.context.support.AbstractApplicationContext;
|
|
|
|
|
import org.springframework.test.context.MergedContextConfiguration;
|
|
|
|
|
|
|
|
|
@ -38,13 +39,24 @@ import static org.mockito.Mockito.mock;
|
|
|
|
|
class TestRestTemplateContextCustomizerTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
|
void whenContextIsNotABeanDefinitionRegistryTestRestTemplateIsRegistered() {
|
|
|
|
|
new ApplicationContextRunner(TestApplicationContext::new).withInitializer((context) -> {
|
|
|
|
|
new ApplicationContextRunner(TestApplicationContext::new)
|
|
|
|
|
.withInitializer(this::applyTestRestTemplateContextCustomizer)
|
|
|
|
|
.run((context) -> assertThat(context).hasSingleBean(TestRestTemplate.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
void whenUsingAotGeneratedArtifactsTestRestTemplateIsNotRegistered() {
|
|
|
|
|
new ApplicationContextRunner().withSystemProperties("spring.aot.enabled:true")
|
|
|
|
|
.withInitializer(this::applyTestRestTemplateContextCustomizer)
|
|
|
|
|
.run((context) -> assertThat(context).doesNotHaveBean(TestRestTemplate.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings({ "unchecked", "rawtypes" })
|
|
|
|
|
void applyTestRestTemplateContextCustomizer(ConfigurableApplicationContext context) {
|
|
|
|
|
MergedContextConfiguration configuration = mock(MergedContextConfiguration.class);
|
|
|
|
|
given(configuration.getTestClass()).willReturn((Class) TestClass.class);
|
|
|
|
|
new TestRestTemplateContextCustomizer().customizeContext(context, configuration);
|
|
|
|
|
}).run((context) -> assertThat(context).hasSingleBean(TestRestTemplate.class));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
|
|
|
|