Bumping versions
This commit is contained in:
@@ -151,7 +151,8 @@ public class RefreshAutoConfiguration {
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringCreator(this)
|
||||
.append("additionalPropertySourcesToRetain", additionalPropertySourcesToRetain).toString();
|
||||
.append("additionalPropertySourcesToRetain", additionalPropertySourcesToRetain)
|
||||
.toString();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,7 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
MutablePropertySources bootstrapProperties = bootstrapEnvironment.getPropertySources();
|
||||
String configLocation = environment.resolvePlaceholders("${spring.cloud.bootstrap.location:}");
|
||||
String configAdditionalLocation = environment
|
||||
.resolvePlaceholders("${spring.cloud.bootstrap.additional-location:}");
|
||||
.resolvePlaceholders("${spring.cloud.bootstrap.additional-location:}");
|
||||
Map<String, Object> bootstrapMap = new HashMap<>();
|
||||
bootstrapMap.put("spring.config.name", configName);
|
||||
// if an app (or test) uses spring.main.web-application-type=reactive, bootstrap
|
||||
@@ -170,9 +170,12 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
}
|
||||
// TODO: is it possible or sensible to share a ResourceLoader?
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder().profiles(environment.getActiveProfiles())
|
||||
.bannerMode(Mode.OFF).environment(bootstrapEnvironment)
|
||||
// Don't use the default properties in this builder
|
||||
.registerShutdownHook(false).logStartupInfo(false).web(WebApplicationType.NONE);
|
||||
.bannerMode(Mode.OFF)
|
||||
.environment(bootstrapEnvironment)
|
||||
// Don't use the default properties in this builder
|
||||
.registerShutdownHook(false)
|
||||
.logStartupInfo(false)
|
||||
.web(WebApplicationType.NONE);
|
||||
final SpringApplication builderApplication = builder.application();
|
||||
if (builderApplication.getMainApplicationClass() == null) {
|
||||
// gh_425:
|
||||
@@ -383,7 +386,7 @@ public class BootstrapApplicationListener implements ApplicationListener<Applica
|
||||
PropertySource<?> removed = environment.getPropertySources().remove(DEFAULT_PROPERTIES);
|
||||
if (removed instanceof ExtendedDefaultPropertySource defaultProperties) {
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource(DEFAULT_PROPERTIES, defaultProperties.getSource()));
|
||||
.addLast(new MapPropertySource(DEFAULT_PROPERTIES, defaultProperties.getSource()));
|
||||
for (PropertySource<?> source : defaultProperties.getPropertySources().getPropertySources()) {
|
||||
if (!environment.getPropertySources().contains(source.getName())) {
|
||||
environment.getPropertySources().addBefore(DEFAULT_PROPERTIES, source);
|
||||
|
||||
@@ -376,14 +376,15 @@ public class BootstrapConfigFileApplicationListener
|
||||
|
||||
private String[] getDefaultProfiles(Binder binder) {
|
||||
return binder.bind(AbstractEnvironment.DEFAULT_PROFILES_PROPERTY_NAME, STRING_ARRAY)
|
||||
.orElseGet(this.environment::getDefaultProfiles);
|
||||
.orElseGet(this.environment::getDefaultProfiles);
|
||||
}
|
||||
|
||||
private List<Profile> getOtherActiveProfiles(Set<Profile> activatedViaProperty,
|
||||
Set<Profile> includedViaProperty) {
|
||||
return Arrays.stream(this.environment.getActiveProfiles()).map(Profile::new).filter(
|
||||
(profile) -> !activatedViaProperty.contains(profile) && !includedViaProperty.contains(profile))
|
||||
.collect(Collectors.toList());
|
||||
return Arrays.stream(this.environment.getActiveProfiles())
|
||||
.map(Profile::new)
|
||||
.filter((profile) -> !activatedViaProperty.contains(profile) && !includedViaProperty.contains(profile))
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
void addActiveProfiles(Set<Profile> profiles) {
|
||||
@@ -474,7 +475,7 @@ public class BootstrapConfigFileApplicationListener
|
||||
|
||||
private boolean canLoadFileExtension(PropertySourceLoader loader, String name) {
|
||||
return Arrays.stream(loader.getFileExtensions())
|
||||
.anyMatch((fileExtension) -> StringUtils.endsWithIgnoreCase(name, fileExtension));
|
||||
.anyMatch((fileExtension) -> StringUtils.endsWithIgnoreCase(name, fileExtension));
|
||||
}
|
||||
|
||||
private void loadForFileExtension(PropertySourceLoader loader, String prefix, String fileExtension,
|
||||
@@ -606,9 +607,12 @@ public class BootstrapConfigFileApplicationListener
|
||||
if (files != null) {
|
||||
String fileName = locationReference.substring(locationReference.lastIndexOf("/") + 1);
|
||||
Arrays.sort(files, FILE_COMPARATOR);
|
||||
return Arrays.stream(files).map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
|
||||
.filter(Objects::nonNull).flatMap((Function<File[], Stream<File>>) Arrays::stream)
|
||||
.map(FileSystemResource::new).toArray(Resource[]::new);
|
||||
return Arrays.stream(files)
|
||||
.map((file) -> file.listFiles((dir, name) -> name.equals(fileName)))
|
||||
.filter(Objects::nonNull)
|
||||
.flatMap((Function<File[], Stream<File>>) Arrays::stream)
|
||||
.map(FileSystemResource::new)
|
||||
.toArray(Resource[]::new);
|
||||
}
|
||||
return EMPTY_RESOURCES;
|
||||
}
|
||||
@@ -793,8 +797,10 @@ public class BootstrapConfigFileApplicationListener
|
||||
activeProfiles.addAll(bindStringList(binder, "spring.profiles.active"));
|
||||
}
|
||||
}
|
||||
this.processedProfiles.stream().filter(this::isDefaultProfile).map(Profile::getName)
|
||||
.forEach(activeProfiles::add);
|
||||
this.processedProfiles.stream()
|
||||
.filter(this::isDefaultProfile)
|
||||
.map(Profile::getName)
|
||||
.forEach(activeProfiles::add);
|
||||
this.environment.setActiveProfiles(activeProfiles.toArray(new String[0]));
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BootstrapImportSelector implements EnvironmentAware, DeferredImport
|
||||
List<String> names = new ArrayList<>(
|
||||
SpringFactoriesLoader.loadFactoryNames(BootstrapConfiguration.class, classLoader));
|
||||
names.addAll(Arrays.asList(StringUtils
|
||||
.commaDelimitedListToStringArray(this.environment.getProperty("spring.cloud.bootstrap.sources", ""))));
|
||||
.commaDelimitedListToStringArray(this.environment.getProperty("spring.cloud.bootstrap.sources", ""))));
|
||||
|
||||
List<OrderedAnnotatedElement> elements = new ArrayList<>();
|
||||
for (String name : names) {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class TextEncryptorConfigBootstrapper implements BootstrapRegistryInitial
|
||||
* RsaSecretEncryptor present.
|
||||
*/
|
||||
public static final boolean RSA_IS_PRESENT = ClassUtils
|
||||
.isPresent("org.springframework.security.rsa.crypto.RsaSecretEncryptor", null);
|
||||
.isPresent("org.springframework.security.rsa.crypto.RsaSecretEncryptor", null);
|
||||
|
||||
@Override
|
||||
public void initialize(BootstrapRegistry registry) {
|
||||
@@ -46,11 +46,15 @@ public class TextEncryptorConfigBootstrapper implements BootstrapRegistryInitial
|
||||
return;
|
||||
}
|
||||
|
||||
registry.registerIfAbsent(KeyProperties.class, context -> context.get(Binder.class)
|
||||
.bind(KeyProperties.PREFIX, KeyProperties.class).orElseGet(KeyProperties::new));
|
||||
registry.registerIfAbsent(KeyProperties.class,
|
||||
context -> context.get(Binder.class)
|
||||
.bind(KeyProperties.PREFIX, KeyProperties.class)
|
||||
.orElseGet(KeyProperties::new));
|
||||
if (RSA_IS_PRESENT) {
|
||||
registry.registerIfAbsent(RsaProperties.class, context -> context.get(Binder.class)
|
||||
.bind(RsaProperties.PREFIX, RsaProperties.class).orElseGet(RsaProperties::new));
|
||||
registry.registerIfAbsent(RsaProperties.class,
|
||||
context -> context.get(Binder.class)
|
||||
.bind(RsaProperties.PREFIX, RsaProperties.class)
|
||||
.orElseGet(RsaProperties::new));
|
||||
}
|
||||
TextEncryptorUtils.register(registry);
|
||||
|
||||
|
||||
@@ -106,7 +106,8 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
@Override
|
||||
public void initialize(ConfigurableApplicationContext applicationContext) {
|
||||
if (!bootstrapProperties.isInitializeOnContextRefresh() || !applicationContext.getEnvironment()
|
||||
.getPropertySources().contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
.getPropertySources()
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
doInitialize(applicationContext);
|
||||
}
|
||||
}
|
||||
@@ -151,8 +152,9 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
}
|
||||
|
||||
private void reinitializeLoggingSystem(ConfigurableEnvironment environment) {
|
||||
Map<String, Object> props = Binder.get(environment).bind("logging", Bindable.mapOf(String.class, Object.class))
|
||||
.orElseGet(Collections::emptyMap);
|
||||
Map<String, Object> props = Binder.get(environment)
|
||||
.bind("logging", Bindable.mapOf(String.class, Object.class))
|
||||
.orElseGet(Collections::emptyMap);
|
||||
if (!props.isEmpty()) {
|
||||
String logConfig = environment.resolvePlaceholders("${logging.config:}");
|
||||
LogFile logFile = LogFile.get(environment);
|
||||
@@ -240,7 +242,7 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
|
||||
private void handleProfiles(ConfigurableEnvironment environment) {
|
||||
if (bootstrapProperties.isInitializeOnContextRefresh() && !environment.getPropertySources()
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
// In the case that spring.cloud.config.initialize-on-context-refresh is true
|
||||
// this method will
|
||||
// be called during the bootstrap phase and the main application startup. We
|
||||
@@ -268,7 +270,7 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
activeProfiles.add(0, profile);
|
||||
}
|
||||
List<String> activeProfilesFromEnvironment = Arrays.stream(environment.getActiveProfiles())
|
||||
.collect(Collectors.toList());
|
||||
.collect(Collectors.toList());
|
||||
if (!activeProfiles.containsAll(activeProfilesFromEnvironment)) {
|
||||
activeProfiles.addAll(activeProfilesFromEnvironment);
|
||||
|
||||
@@ -296,7 +298,7 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
String property, ConfigurableEnvironment environment) {
|
||||
if (propertySource instanceof CompositePropertySource) {
|
||||
for (PropertySource<?> nestedPropertySource : ((CompositePropertySource) propertySource)
|
||||
.getPropertySources()) {
|
||||
.getPropertySources()) {
|
||||
addProfilesTo(profiles, nestedPropertySource, property, environment);
|
||||
}
|
||||
}
|
||||
@@ -331,8 +333,9 @@ public class PropertySourceBootstrapConfiguration implements ApplicationListener
|
||||
public void onApplicationEvent(ContextRefreshedEvent event) {
|
||||
if (bootstrapProperties.isInitializeOnContextRefresh()
|
||||
&& event.getApplicationContext() instanceof ConfigurableApplicationContext) {
|
||||
if (((ConfigurableApplicationContext) event.getApplicationContext()).getEnvironment().getPropertySources()
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
if (((ConfigurableApplicationContext) event.getApplicationContext()).getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
doInitialize((ConfigurableApplicationContext) event.getApplicationContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,9 +29,9 @@ class EncryptionRuntimeHints implements RuntimeHintsRegistrar {
|
||||
|
||||
@Override
|
||||
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
|
||||
hints.reflection().registerTypeIfPresent(classLoader,
|
||||
"org.springframework.security.rsa.crypto.RsaSecretEncryptor",
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
hints.reflection()
|
||||
.registerTypeIfPresent(classLoader, "org.springframework.security.rsa.crypto.RsaSecretEncryptor",
|
||||
MemberCategory.INVOKE_DECLARED_CONSTRUCTORS);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class EnvironmentDecryptApplicationInitializer extends AbstractEnvironmen
|
||||
if (!propertySources.contains(DECRYPTED_BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
// No reason to decrypt bootstrap twice
|
||||
PropertySource<?> bootstrap = propertySources
|
||||
.get(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
.get(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
if (bootstrap != null) {
|
||||
Map<String, Object> map = decrypt(bootstrap);
|
||||
if (!map.isEmpty()) {
|
||||
@@ -139,7 +139,7 @@ public class EnvironmentDecryptApplicationInitializer extends AbstractEnvironmen
|
||||
while (parent != null) {
|
||||
if (parent.getEnvironment() instanceof ConfigurableEnvironment) {
|
||||
((ConfigurableEnvironment) parent.getEnvironment()).getPropertySources()
|
||||
.remove(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
.remove(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
}
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
@@ -55,12 +55,12 @@ public abstract class TextEncryptorUtils {
|
||||
static TextEncryptor getTextEncryptor(AbstractEnvironmentDecrypt decryptor, ConfigurableEnvironment environment) {
|
||||
Binder binder = Binder.get(environment);
|
||||
KeyProperties keyProperties = binder.bind(KeyProperties.PREFIX, KeyProperties.class)
|
||||
.orElseGet(KeyProperties::new);
|
||||
.orElseGet(KeyProperties::new);
|
||||
if (TextEncryptorUtils.keysConfigured(keyProperties)) {
|
||||
decryptor.setFailOnError(keyProperties.isFailOnError());
|
||||
if (ClassUtils.isPresent("org.springframework.security.rsa.crypto.RsaSecretEncryptor", null)) {
|
||||
RsaProperties rsaProperties = binder.bind(RsaProperties.PREFIX, RsaProperties.class)
|
||||
.orElseGet(RsaProperties::new);
|
||||
.orElseGet(RsaProperties::new);
|
||||
return TextEncryptorUtils.createTextEncryptor(keyProperties, rsaProperties);
|
||||
}
|
||||
return new EncryptorFactory(keyProperties.getSalt()).create(keyProperties.getKey());
|
||||
@@ -121,7 +121,8 @@ public abstract class TextEncryptorUtils {
|
||||
if (keyStore.getLocation().exists()) {
|
||||
return new RsaSecretEncryptor(
|
||||
new KeyStoreKeyFactory(keyStore.getLocation(), keyStore.getPassword().toCharArray(),
|
||||
keyStore.getType()).getKeyPair(keyStore.getAlias(), keyStore.getSecret().toCharArray()),
|
||||
keyStore.getType())
|
||||
.getKeyPair(keyStore.getAlias(), keyStore.getSecret().toCharArray()),
|
||||
rsaProperties.getAlgorithm(), rsaProperties.getSalt(), rsaProperties.isStrong());
|
||||
}
|
||||
|
||||
|
||||
@@ -180,8 +180,10 @@ public abstract class NamedContextFactory<C extends NamedContextFactory.Specific
|
||||
: new AnnotationConfigApplicationContext();
|
||||
}
|
||||
context.setClassLoader(classLoader);
|
||||
context.getEnvironment().getPropertySources().addFirst(
|
||||
new MapPropertySource(this.propertySourceName, Collections.singletonMap(this.propertyName, name)));
|
||||
context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addFirst(
|
||||
new MapPropertySource(this.propertySourceName, Collections.singletonMap(this.propertyName, name)));
|
||||
if (this.parent != null) {
|
||||
// Uses Environment from parent as well as beans
|
||||
context.setParent(this.parent);
|
||||
|
||||
@@ -57,7 +57,7 @@ public class ConfigurationPropertiesBeans implements BeanPostProcessor, Applicat
|
||||
this.beanFactory = (ConfigurableListableBeanFactory) applicationContext.getAutowireCapableBeanFactory();
|
||||
}
|
||||
if (applicationContext.getParent() != null && applicationContext.getParent()
|
||||
.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory listable) {
|
||||
.getAutowireCapableBeanFactory() instanceof ConfigurableListableBeanFactory listable) {
|
||||
String[] names = listable.getBeanNamesForType(ConfigurationPropertiesBeans.class);
|
||||
if (names.length == 1) {
|
||||
this.parent = (ConfigurationPropertiesBeans) listable.getBean(names[0]);
|
||||
|
||||
@@ -153,7 +153,7 @@ public class ConfigurationPropertiesRebinder
|
||||
@ManagedAttribute
|
||||
public Set<String> getNeverRefreshable() {
|
||||
String neverRefresh = this.applicationContext.getEnvironment()
|
||||
.getProperty("spring.cloud.refresh.never-refreshable", "com.zaxxer.hikari.HikariDataSource");
|
||||
.getProperty("spring.cloud.refresh.never-refreshable", "com.zaxxer.hikari.HikariDataSource");
|
||||
return StringUtils.commaDelimitedListToSet(neverRefresh);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@ public class ConfigDataContextRefresher extends ContextRefresher
|
||||
}
|
||||
StandardEnvironment environment = copyEnvironment(getContext().getEnvironment());
|
||||
ConfigurableBootstrapContext bootstrapContext = getContext().getBeanProvider(ConfigurableBootstrapContext.class)
|
||||
.getIfAvailable(DefaultBootstrapContext::new);
|
||||
.getIfAvailable(DefaultBootstrapContext::new);
|
||||
|
||||
// run thru all EnvironmentPostProcessor instances. This lets things like vcap and
|
||||
// decrypt happen after refresh. The hard coded call to
|
||||
|
||||
@@ -70,11 +70,13 @@ public class LegacyContextRefresher extends ContextRefresher {
|
||||
environment.getPropertySources().addFirst(new MapPropertySource(REFRESH_ARGS_PROPERTY_SOURCE, map));
|
||||
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder(Empty.class).bannerMode(Banner.Mode.OFF)
|
||||
.web(WebApplicationType.NONE).environment(environment);
|
||||
.web(WebApplicationType.NONE)
|
||||
.environment(environment);
|
||||
// Just the listeners that affect the environment (e.g. excluding logging
|
||||
// listener because it has side effects)
|
||||
builder.application().setListeners(
|
||||
Arrays.asList(new BootstrapApplicationListener(), new BootstrapConfigFileApplicationListener()));
|
||||
builder.application()
|
||||
.setListeners(Arrays.asList(new BootstrapApplicationListener(),
|
||||
new BootstrapConfigFileApplicationListener()));
|
||||
capture = builder.run();
|
||||
if (environment.getPropertySources().contains(REFRESH_ARGS_PROPERTY_SOURCE)) {
|
||||
environment.getPropertySources().remove(REFRESH_ARGS_PROPERTY_SOURCE);
|
||||
|
||||
@@ -92,8 +92,9 @@ public class RestartEndpoint implements ApplicationListener<ContextRefreshedWith
|
||||
this.args = this.event.getArgs();
|
||||
this.application = this.event.getSpringApplication();
|
||||
this.application.addInitializers(new PostProcessorInitializer());
|
||||
this.pauseHandlers = this.context.getBeanProvider(PauseHandler.class).orderedStream()
|
||||
.collect(Collectors.toList());
|
||||
this.pauseHandlers = this.context.getBeanProvider(PauseHandler.class)
|
||||
.orderedStream()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -33,8 +33,9 @@ public final class EnvironmentUtils {
|
||||
}
|
||||
|
||||
public static Map<String, String> getSubProperties(Environment environment, String keyPrefix) {
|
||||
return Binder.get(environment).bind(keyPrefix, Bindable.mapOf(String.class, String.class))
|
||||
.orElseGet(Collections::emptyMap);
|
||||
return Binder.get(environment)
|
||||
.bind(keyPrefix, Bindable.mapOf(String.class, String.class))
|
||||
.orElseGet(Collections::emptyMap);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -64,8 +64,9 @@ public class LoggingRebinder implements ApplicationListener<EnvironmentChangeEve
|
||||
}
|
||||
|
||||
protected void setLogLevels(LoggingSystem system, Environment environment) {
|
||||
Map<String, String> levels = Binder.get(environment).bind("logging.level", STRING_STRING_MAP)
|
||||
.orElseGet(Collections::emptyMap);
|
||||
Map<String, String> levels = Binder.get(environment)
|
||||
.bind("logging.level", STRING_STRING_MAP)
|
||||
.orElseGet(Collections::emptyMap);
|
||||
for (Entry<String, String> entry : levels.entrySet()) {
|
||||
setLogLevel(system, environment, entry.getKey(), entry.getValue());
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ public class RefreshAutoConfigurationClassPathTests {
|
||||
public void refreshEventListenerCreated() {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class)) {
|
||||
then(context.getBeansOfType(RefreshEventListener.class)).as("RefreshEventListeners not created")
|
||||
.isNotEmpty();
|
||||
.isNotEmpty();
|
||||
then(context.containsBean("refreshEndpoint")).as("refreshEndpoint created").isFalse();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,9 +46,9 @@ public class RefreshAutoConfigurationMoreClassPathTests {
|
||||
try (ConfigurableApplicationContext context = getApplicationContext(Config.class, "debug=true")) {
|
||||
String output = outputCapture.toString();
|
||||
then(output)
|
||||
.doesNotContain("Failed to introspect annotations on "
|
||||
+ "[class org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration")
|
||||
.doesNotContain("TypeNotPresentExceptionProxy");
|
||||
.doesNotContain("Failed to introspect annotations on "
|
||||
+ "[class org.springframework.cloud.autoconfigure.RefreshEndpointAutoConfiguration")
|
||||
.doesNotContain("TypeNotPresentExceptionProxy");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,8 +47,10 @@ class RefreshAutoConfigurationTests {
|
||||
|
||||
private static ConfigurableApplicationContext getApplicationContext(WebApplicationType type, Class<?> configuration,
|
||||
String... properties) {
|
||||
return new SpringApplicationBuilder(configuration).web(type).properties(properties).properties("server.port=0")
|
||||
.run();
|
||||
return new SpringApplicationBuilder(configuration).web(type)
|
||||
.properties(properties)
|
||||
.properties("server.port=0")
|
||||
.run();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,14 +102,14 @@ class RefreshAutoConfigurationTests {
|
||||
@Test
|
||||
void refreshScopeLifecylePresentByDefault() {
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.run(context -> assertThat(context).hasBean("refreshScopeLifecycle"));
|
||||
.run(context -> assertThat(context).hasBean("refreshScopeLifecycle"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void refreshScopeLifecyleDisabledWithProp() {
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.refresh.on-restart.enabled=false")
|
||||
.run(context -> assertThat(context).doesNotHaveBean("refreshScopeLifecycle"));
|
||||
.withPropertyValues("spring.cloud.refresh.on-restart.enabled=false")
|
||||
.run(context -> assertThat(context).doesNotHaveBean("refreshScopeLifecycle"));
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
@@ -39,7 +39,7 @@ public class BootstrapOrderingAutoConfigurationIntegrationTests {
|
||||
@Test
|
||||
public void bootstrapPropertiesExist() {
|
||||
then(this.environment.getPropertySources().contains("applicationConfig: [classpath:/bootstrap.properties]"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -48,7 +48,7 @@ public class BootstrapOrderingCustomPropertySourceIntegrationTests {
|
||||
@Test
|
||||
public void bootstrapPropertiesExist() {
|
||||
then(this.environment.getPropertySources().contains("applicationConfig: [classpath:/custom.properties]"))
|
||||
.isTrue();
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -33,7 +33,7 @@ public class BootstrapSourcesOrderingTests {
|
||||
public void sourcesAreOrderedCorrectly() {
|
||||
Class<?> firstConstructedClass = firstToBeCreated.get();
|
||||
then(firstConstructedClass).as("bootstrap sources not ordered correctly")
|
||||
.isEqualTo(TestHigherPriorityBootstrapConfiguration.class);
|
||||
.isEqualTo(TestHigherPriorityBootstrapConfiguration.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -62,8 +62,9 @@ public class TestBootstrapConfiguration {
|
||||
public ApplicationContextInitializer<ConfigurableApplicationContext> customInitializer() {
|
||||
return applicationContext -> {
|
||||
ConfigurableEnvironment environment = applicationContext.getEnvironment();
|
||||
environment.getPropertySources().addLast(new MapPropertySource("customProperties", Collections
|
||||
.singletonMap("custom.foo", environment.resolvePlaceholders("${spring.application.name:bar}"))));
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("customProperties", Collections.singletonMap("custom.foo",
|
||||
environment.resolvePlaceholders("${spring.application.name:bar}"))));
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -90,13 +90,15 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void pickupOnlyExternalBootstrapProperties(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(BareConfiguration.class)
|
||||
.properties(properties).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName");
|
||||
then(this.context.getEnvironment().getProperty("info.desc")).isNull();
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,13 +118,15 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void pickupAdditionalExternalBootstrapProperties(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(BareConfiguration.class)
|
||||
.properties(properties).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName");
|
||||
then(this.context.getEnvironment().getProperty("info.desc")).isEqualTo("defaultPropertiesInfoDesc");
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,14 +141,17 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void bootstrapPropertiesAvailableInInitializer(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).initializers(applicationContext -> {
|
||||
// This property is defined in bootstrap.properties
|
||||
then(applicationContext.getEnvironment().getProperty("info.name")).isEqualTo("child");
|
||||
}).run();
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.initializers(applicationContext -> {
|
||||
// This property is defined in bootstrap.properties
|
||||
then(applicationContext.getEnvironment().getProperty("info.name")).isEqualTo("child");
|
||||
})
|
||||
.run();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -170,12 +177,14 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void picksUpAdditionalPropertySource(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,8 +201,10 @@ public class BootstrapConfigurationTests {
|
||||
private void failsOnPropertySource(String... properties) {
|
||||
System.setProperty("expected.fail", "true");
|
||||
Throwable throwable = Assertions.assertThrows(RuntimeException.class, () -> {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
});
|
||||
then(throwable.getMessage().equals("Planned"));
|
||||
}
|
||||
@@ -214,8 +225,10 @@ public class BootstrapConfigurationTests {
|
||||
private void overrideSystemPropertySourceByDefault(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -234,8 +247,10 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.overrideSystemProperties", "false");
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("system");
|
||||
}
|
||||
|
||||
@@ -258,8 +273,10 @@ public class BootstrapConfigurationTests {
|
||||
// their own remote property source.
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "false");
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@@ -279,8 +296,10 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.overrideSystemProperties", "false");
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true");
|
||||
System.setProperty("bootstrap.foo", "system");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("system");
|
||||
}
|
||||
|
||||
@@ -300,10 +319,13 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.overrideNone", "true");
|
||||
PropertySourceConfiguration.MAP.put("spring.cloud.config.allowOverride", "true");
|
||||
ConfigurableEnvironment environment = new StandardEnvironment();
|
||||
environment.getPropertySources().addLast(
|
||||
new MapPropertySource("last", Collections.<String, Object>singletonMap("bootstrap.foo", "splat")));
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.environment(environment).sources(BareConfiguration.class).run();
|
||||
environment.getPropertySources()
|
||||
.addLast(new MapPropertySource("last", Collections.<String, Object>singletonMap("bootstrap.foo", "splat")));
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.environment(environment)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("splat");
|
||||
}
|
||||
|
||||
@@ -322,15 +344,17 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void applicationNameInBootstrapAndMain(String... properties) {
|
||||
System.setProperty("expected.name", "main");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name")).isEqualTo("app");
|
||||
// The parent is called "main" because spring.application.name is specified in
|
||||
// other.properties (the bootstrap properties)
|
||||
then(this.context.getParent().getEnvironment().getProperty("spring.application.name")).isEqualTo("main");
|
||||
// The bootstrap context has the same "bootstrap" property source
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment()).getPropertySources()
|
||||
.get("bootstrap")).isEqualTo(this.context.getEnvironment().getPropertySources().get("bootstrap"));
|
||||
.get("bootstrap")).isEqualTo(this.context.getEnvironment().getPropertySources().get("bootstrap"));
|
||||
then(this.context.getId()).isEqualTo("main-1");
|
||||
}
|
||||
|
||||
@@ -349,8 +373,10 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void applicationNameNotInBootstrap(String... properties) {
|
||||
System.setProperty("expected.name", "main");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name")).isEqualTo("main");
|
||||
// The parent has no name because spring.application.name is not
|
||||
// defined in the bootstrap properties
|
||||
@@ -370,8 +396,10 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void applicationNameOnlyInBootstrap(String... properties) {
|
||||
System.setProperty("expected.name", "main");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
// The main context is called "main" because spring.application.name is specified
|
||||
// in other.properties (and not in the main config file)
|
||||
then(this.context.getEnvironment().getProperty("spring.application.name")).isEqualTo("main");
|
||||
@@ -394,14 +422,17 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void environmentEnrichedOnceWhenSharedWithChildContext(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class).properties(properties)
|
||||
.environment(new StandardEnvironment()).child(BareConfiguration.class).web(WebApplicationType.NONE)
|
||||
.run();
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.environment(new StandardEnvironment())
|
||||
.child(BareConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getParent().getEnvironment()).isEqualTo(this.context.getEnvironment());
|
||||
MutablePropertySources sources = this.context.getEnvironment().getPropertySources();
|
||||
PropertySource<?> bootstrap = sources
|
||||
.get(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap");
|
||||
.get(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap");
|
||||
then(bootstrap).isNotNull();
|
||||
then(sources.precedenceOf(bootstrap)).isEqualTo(0);
|
||||
}
|
||||
@@ -420,8 +451,11 @@ public class BootstrapConfigurationTests {
|
||||
private void onlyOneBootstrapContext(String... properties) {
|
||||
TestHigherPriorityBootstrapConfiguration.count.set(0);
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class).properties(properties)
|
||||
.child(BareConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.child(BareConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(TestHigherPriorityBootstrapConfiguration.count.get()).isEqualTo(1);
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent().getId()).isEqualTo("bootstrap");
|
||||
@@ -441,8 +475,11 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void listOverride(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class).properties(properties)
|
||||
.child(BareConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.child(BareConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
ListProperties listProperties = new ListProperties();
|
||||
Binder.get(this.context.getEnvironment()).bind("list", Bindable.ofInstance(listProperties));
|
||||
then(listProperties.getFoo().size()).isEqualTo(1);
|
||||
@@ -464,11 +501,15 @@ public class BootstrapConfigurationTests {
|
||||
TestHigherPriorityBootstrapConfiguration.count.set(0);
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
SpringApplicationBuilder builder = new SpringApplicationBuilder().properties(properties)
|
||||
.sources(BareConfiguration.class);
|
||||
this.sibling = builder.child(BareConfiguration.class).properties("spring.application.name=sibling")
|
||||
.web(WebApplicationType.NONE).run();
|
||||
this.context = builder.child(BareConfiguration.class).properties("spring.application.name=context")
|
||||
.web(WebApplicationType.NONE).run();
|
||||
.sources(BareConfiguration.class);
|
||||
this.sibling = builder.child(BareConfiguration.class)
|
||||
.properties("spring.application.name=sibling")
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
this.context = builder.child(BareConfiguration.class)
|
||||
.properties("spring.application.name=context")
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(TestHigherPriorityBootstrapConfiguration.count.get()).isEqualTo(1);
|
||||
then(this.context.getParent()).isNotNull();
|
||||
then(this.context.getParent().getParent().getId()).isEqualTo("bootstrap");
|
||||
@@ -495,16 +536,18 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void environmentEnrichedInParentContext(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class).properties(properties)
|
||||
.child(BareConfiguration.class).web(WebApplicationType.NONE).run();
|
||||
this.context = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.child(BareConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
then(this.context.getParent().getEnvironment()).isNotSameAs(this.context.getEnvironment());
|
||||
then(this.context.getEnvironment().getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment()).getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -513,10 +556,15 @@ public class BootstrapConfigurationTests {
|
||||
PropertySourceConfiguration.MAP.put("bootstrap.foo", "bar");
|
||||
// Profiles are always merged with the child
|
||||
ConfigurableApplicationContext parent = new SpringApplicationBuilder().sources(BareConfiguration.class)
|
||||
.profiles("parent").web(WebApplicationType.NONE).run();
|
||||
.profiles("parent")
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
this.context = new SpringApplicationBuilder(BareConfiguration.class)
|
||||
.properties("spring.config.use-legacy-processing=true").profiles("child").parent(parent)
|
||||
.web(WebApplicationType.NONE).run();
|
||||
.properties("spring.config.use-legacy-processing=true")
|
||||
.profiles("child")
|
||||
.parent(parent)
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(this.context.getParent().getEnvironment()).isNotSameAs(this.context.getEnvironment());
|
||||
// The ApplicationContext merges profiles (profiles and property sources), see
|
||||
// AbstractEnvironment.merge()
|
||||
@@ -525,8 +573,7 @@ public class BootstrapConfigurationTests {
|
||||
then(this.context.getParent().getEnvironment().acceptsProfiles("child")).isFalse();
|
||||
then(this.context.getParent().getEnvironment().acceptsProfiles("parent")).isTrue();
|
||||
then(((ConfigurableEnvironment) this.context.getParent().getEnvironment()).getPropertySources()
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap"))
|
||||
.isTrue();
|
||||
.contains(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-testBootstrap")).isTrue();
|
||||
then(this.context.getEnvironment().getProperty("bootstrap.foo")).isEqualTo("bar");
|
||||
// The "bootstrap" property source is not shared now, but it has the same
|
||||
// properties in it because they are pulled from the PropertySourceConfiguration
|
||||
@@ -550,8 +597,11 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void includeProfileFromBootstrapPropertySource(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.include", "bar,baz");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.profiles("foo").sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.profiles("foo")
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().acceptsProfiles("baz")).isTrue();
|
||||
then(this.context.getEnvironment().acceptsProfiles("bar")).isTrue();
|
||||
}
|
||||
@@ -572,8 +622,11 @@ public class BootstrapConfigurationTests {
|
||||
|
||||
private void activeProfileFromBootstrapPropertySource(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.active", "bar,baz");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.profiles("foo").sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.profiles("foo")
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().acceptsProfiles("baz", "bar", "foo")).isTrue();
|
||||
|
||||
}
|
||||
@@ -592,8 +645,11 @@ public class BootstrapConfigurationTests {
|
||||
private void activeAndIncludeProfileFromBootstrapPropertySource(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.active", "bar,baz");
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.include", "bar,baz,hello");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.profiles("foo").sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.profiles("foo")
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().acceptsProfiles("baz", "bar", "hello", "foo")).isTrue();
|
||||
then(this.context.getEnvironment().getActiveProfiles()).contains("baz", "bar", "foo", "hello");
|
||||
}
|
||||
@@ -613,8 +669,11 @@ public class BootstrapConfigurationTests {
|
||||
private void activeAndIncludeProfileFromBootstrapPropertySourceWithReplacement(String... properties) {
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.active", "${barreplacement},baz");
|
||||
PropertySourceConfiguration.MAP.put("spring.profiles.include", "${barreplacement},baz,hello");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.profiles("foo").sources(BareConfiguration.class).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.profiles("foo")
|
||||
.sources(BareConfiguration.class)
|
||||
.run();
|
||||
then(this.context.getEnvironment().acceptsProfiles("baz", "bar", "hello", "foo")).isTrue();
|
||||
then(this.context.getEnvironment().getActiveProfiles()).contains("baz", "bar", "foo", "hello");
|
||||
}
|
||||
@@ -632,8 +691,10 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void includeProfileFromBootstrapProperties(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(BareConfiguration.class)
|
||||
.properties(properties).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.run();
|
||||
then(this.context.getEnvironment().acceptsProfiles("local")).isTrue();
|
||||
then(this.context.getEnvironment().getProperty("added")).isEqualTo("Hello added!");
|
||||
}
|
||||
@@ -651,16 +712,20 @@ public class BootstrapConfigurationTests {
|
||||
}
|
||||
|
||||
private void nonEnumerablePropertySourceWorks(String... properties) {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(BareConfiguration.class)
|
||||
.properties(properties).run();
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(BareConfiguration.class)
|
||||
.properties(properties)
|
||||
.run();
|
||||
then(this.context.getEnvironment().getProperty("foo")).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveActiveProfileProperties_ShouldOnlyAcceptTheTopPriority() {
|
||||
String[] properties = new String[] { "spring.config.use-legacy-processing=true" };
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE).properties(properties)
|
||||
.sources(BareConfiguration.class).run("--spring.profiles.active=prod,secure");
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.properties(properties)
|
||||
.sources(BareConfiguration.class)
|
||||
.run("--spring.profiles.active=prod,secure");
|
||||
then(this.context.getEnvironment().acceptsProfiles("prod", "secure")).isTrue();
|
||||
// active profile from property sources with lower priority should not be included
|
||||
then(this.context.getEnvironment().acceptsProfiles("local")).isFalse();
|
||||
@@ -668,9 +733,11 @@ public class BootstrapConfigurationTests {
|
||||
then(this.context.getEnvironment().getActiveProfiles()).doesNotContain("local");
|
||||
// check if active profile value could possibly exist in other property sources
|
||||
// with lower priority
|
||||
then(this.context.getEnvironment().getPropertySources().stream()
|
||||
.map(p -> p.getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)).anyMatch("local"::equals))
|
||||
.isTrue();
|
||||
then(this.context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.stream()
|
||||
.map(p -> p.getProperty(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME))
|
||||
.anyMatch("local"::equals)).isTrue();
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@@ -711,7 +778,7 @@ public class BootstrapConfigurationTests {
|
||||
public PropertySource<?> locate(Environment environment) {
|
||||
if (environment instanceof ConfigurableEnvironment) {
|
||||
if (!((ConfigurableEnvironment) environment).getPropertySources()
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
.contains(BootstrapApplicationListener.BOOTSTRAP_PROPERTY_SOURCE_NAME)) {
|
||||
if (MAP.containsKey(AbstractEnvironment.ACTIVE_PROFILES_PROPERTY_NAME)) {
|
||||
// This additional profile, after, should not be added when
|
||||
// initialize-on-context-refresh=true
|
||||
|
||||
@@ -37,7 +37,10 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
@Test
|
||||
public void shouldAddInABootstrapContext() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(BasicConfiguration.class).web(NONE).run();
|
||||
.properties("spring.cloud.bootstrap.enabled=true")
|
||||
.sources(BasicConfiguration.class)
|
||||
.web(NONE)
|
||||
.run();
|
||||
|
||||
then(context.getParent()).isNotNull();
|
||||
}
|
||||
@@ -45,8 +48,12 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
@Test
|
||||
public void shouldAddInOneBootstrapForABasicParentChildHierarchy() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(RootConfiguration.class).web(NONE)
|
||||
.child(BasicConfiguration.class).web(NONE).run();
|
||||
.properties("spring.cloud.bootstrap.enabled=true")
|
||||
.sources(RootConfiguration.class)
|
||||
.web(NONE)
|
||||
.child(BasicConfiguration.class)
|
||||
.web(NONE)
|
||||
.run();
|
||||
|
||||
// Should be RootConfiguration based context
|
||||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context.getParent();
|
||||
@@ -64,8 +71,14 @@ public class BootstrapListenerHierarchyIntegrationTests {
|
||||
@Test
|
||||
public void shouldAddInOneBootstrapForSiblingsBasedHierarchy() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder()
|
||||
.properties("spring.cloud.bootstrap.enabled=true").sources(RootConfiguration.class).web(NONE)
|
||||
.child(BasicConfiguration.class).web(NONE).sibling(BasicConfiguration.class).web(NONE).run();
|
||||
.properties("spring.cloud.bootstrap.enabled=true")
|
||||
.sources(RootConfiguration.class)
|
||||
.web(NONE)
|
||||
.child(BasicConfiguration.class)
|
||||
.web(NONE)
|
||||
.sibling(BasicConfiguration.class)
|
||||
.web(NONE)
|
||||
.run();
|
||||
|
||||
// Should be RootConfiguration based context
|
||||
ConfigurableApplicationContext parent = (ConfigurableApplicationContext) context.getParent();
|
||||
|
||||
@@ -31,7 +31,9 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void symmetric() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("encrypt.key:pie").run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key:pie")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
@@ -40,10 +42,10 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void rsaKeyStore() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.keyStore.location:classpath:/server.jks", "encrypt.keyStore.password:letmein",
|
||||
"encrypt.keyStore.alias:mytestkey", "encrypt.keyStore.secret:changeme")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.keyStore.location:classpath:/server.jks", "encrypt.keyStore.password:letmein",
|
||||
"encrypt.keyStore.alias:mytestkey", "encrypt.keyStore.secret:changeme")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
@@ -52,10 +54,10 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void rsaPkcs12KeyStore() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.keyStore.location:classpath:/server.p12", "encrypt.keyStore.password:letmein",
|
||||
"encrypt.keyStore.alias:mytestkey", "encrypt.keyStore.type:PKCS12")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.keyStore.location:classpath:/server.p12", "encrypt.keyStore.password:letmein",
|
||||
"encrypt.keyStore.alias:mytestkey", "encrypt.keyStore.type:PKCS12")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
@@ -64,10 +66,10 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void rsaKeyStoreWithRelaxedProperties() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks", "encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey", "encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks", "encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey", "encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
then(encryptor.decrypt(encryptor.encrypt("foo"))).isEqualTo("foo");
|
||||
context.close();
|
||||
@@ -76,11 +78,11 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
@Test
|
||||
public void rsaProperties() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks", "encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey", "encrypt.key-store.secret:changeme",
|
||||
"encrypt.rsa.strong:true", "encrypt.rsa.salt:foobar")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks", "encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey", "encrypt.key-store.secret:changeme", "encrypt.rsa.strong:true",
|
||||
"encrypt.rsa.salt:foobar")
|
||||
.run();
|
||||
RsaProperties properties = context.getBean(RsaProperties.class);
|
||||
then(properties.getSalt()).isEqualTo("foobar");
|
||||
then(properties.isStrong()).isTrue();
|
||||
@@ -92,10 +94,9 @@ public class EncryptionBootstrapConfigurationTests {
|
||||
public void nonExistentKeystoreLocationShouldNotBeAllowed() {
|
||||
try {
|
||||
new SpringApplicationBuilder(EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks1",
|
||||
"encrypt.key-store.password:letmein", "encrypt.key-store.alias:mytestkey",
|
||||
"encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
.properties("encrypt.key-store.location:classpath:/server.jks1", "encrypt.key-store.password:letmein",
|
||||
"encrypt.key-store.alias:mytestkey", "encrypt.key-store.secret:changeme")
|
||||
.run();
|
||||
then(false).as("Should not create an application context with invalid keystore location").isTrue();
|
||||
}
|
||||
catch (Exception e) {
|
||||
|
||||
@@ -39,36 +39,40 @@ public class EncryptionIntegrationTests {
|
||||
@Test
|
||||
public void legacySymmetricPropertyValues() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getEnvironment().getProperty("foo.password")).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacySymmetricConfigurationProperties() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getBean(PasswordProperties.class).getPassword()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propSymmetricPropertyValues() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getEnvironment().getProperty("foo.password")).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propSymmetricConfigurationProperties() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getBean(PasswordProperties.class).getPassword()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@@ -76,50 +80,51 @@ public class EncryptionIntegrationTests {
|
||||
public void symmetricPropertyValuesFailOnError() {
|
||||
assertThatThrownBy(() -> {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}ZZZbf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}ZZZbf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
}).isInstanceOf(IllegalStateException.class).hasMessageContaining("Cannot decrypt");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void symmetricPropertyValuesFailOnErrorFalse() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.fail-on-error=false", "spring.config.use-legacy-processing=false",
|
||||
"encrypt.key:pie",
|
||||
"foo.password:{cipher}ZZZbf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.fail-on-error=false", "spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}ZZZbf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getEnvironment().getProperty("foo.password")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void symmetricPropertyValues() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getEnvironment().getProperty("foo.password")).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void decryptEnvironmentPostProcessorDisabled() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"spring.cloud.decrypt-environment-post-processor.enabled=false",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"spring.cloud.decrypt-environment-post-processor.enabled=false",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getEnvironment().getProperty("foo.password")).startsWith("{cipher}bf2945");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void symmetricConfigurationProperties() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.use-legacy-processing=false", "encrypt.key:pie",
|
||||
"foo.password:{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95")
|
||||
.run();
|
||||
then(context.getBean(PasswordProperties.class).getPassword()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@@ -128,9 +133,10 @@ public class EncryptionIntegrationTests {
|
||||
TestConfigDataLocationResolver.config.put("foo.password",
|
||||
"{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95");
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE).properties("encrypt.key:pie", TestEnvPostProcessor.EPP_ENABLED + "=true",
|
||||
"spring.cloud.refresh.enabled:true")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key:pie", TestEnvPostProcessor.EPP_ENABLED + "=true",
|
||||
"spring.cloud.refresh.enabled:true")
|
||||
.run();
|
||||
TextEncryptor encryptor = context.getBean(TextEncryptor.class);
|
||||
ContextRefresher refresher = context.getBean(ContextRefresher.class);
|
||||
ConfigurableEnvironment env = context.getBean(ConfigurableEnvironment.class);
|
||||
@@ -145,7 +151,10 @@ public class EncryptionIntegrationTests {
|
||||
@Test
|
||||
public void failsafeTextEncryptor() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(
|
||||
EncryptionIntegrationTests.TestConfiguration.class).web(WebApplicationType.NONE).properties().run();
|
||||
EncryptionIntegrationTests.TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties()
|
||||
.run();
|
||||
then(context.getBean(TextEncryptor.class)).isInstanceOf(TextEncryptorUtils.FailsafeTextEncryptor.class);
|
||||
}
|
||||
|
||||
@@ -154,10 +163,10 @@ public class EncryptionIntegrationTests {
|
||||
TestConfigDataLocationResolver.config.put("foo.password",
|
||||
"{cipher}bf29452295df354e6153c5b31b03ef23c70e55fba24299aa85c63438f1c43c95");
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestAutoConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.import=testdatasource:,classpath:application-failsafe.properties",
|
||||
"createfailsafedelegate=true")
|
||||
.run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("spring.config.import=testdatasource:,classpath:application-failsafe.properties",
|
||||
"createfailsafedelegate=true")
|
||||
.run();
|
||||
ConfigurableEnvironment env = context.getBean(ConfigurableEnvironment.class);
|
||||
then(env.getProperty("foo.password")).isEqualTo("test");
|
||||
context.close();
|
||||
|
||||
@@ -40,14 +40,16 @@ class EncryptionRuntimeHintsTests {
|
||||
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories").load(RuntimeHintsRegistrar.class)
|
||||
.forEach(registrar -> registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
|
||||
SpringFactoriesLoader.forResourceLocation("META-INF/spring/aot.factories")
|
||||
.load(RuntimeHintsRegistrar.class)
|
||||
.forEach(registrar -> registrar.registerHints(this.hints, ClassUtils.getDefaultClassLoader()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rsaSecretEncryptorHasHints() {
|
||||
assertThat(RuntimeHintsPredicates.reflection().onType(RsaSecretEncryptor.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(this.hints);
|
||||
assertThat(RuntimeHintsPredicates.reflection()
|
||||
.onType(RsaSecretEncryptor.class)
|
||||
.withMemberCategories(MemberCategory.INVOKE_DECLARED_CONSTRUCTORS)).accepts(this.hints);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
public void relaxedBinding() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "FOO_TEXT: {cipher}bar")
|
||||
.applyTo(context.getEnvironment(), TestPropertyValues.Type.SYSTEM_ENVIRONMENT);
|
||||
.applyTo(context.getEnvironment(), TestPropertyValues.Type.SYSTEM_ENVIRONMENT);
|
||||
this.listener.initialize(context);
|
||||
then(context.getEnvironment().getProperty("foo.text")).isEqualTo("bar");
|
||||
}
|
||||
@@ -81,8 +81,9 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
public void propertySourcesOrderedCorrectly() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "foo: {cipher}bar").applyTo(context);
|
||||
context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "{cipher}spam")));
|
||||
context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "{cipher}spam")));
|
||||
this.listener.initialize(context);
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
}
|
||||
@@ -125,14 +126,14 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
// tests that collections in another property source don't get copied into
|
||||
// "decrypted" property source
|
||||
TestPropertyValues
|
||||
.of("spring.cloud.bootstrap.enabled=true", "yours[0].someValue: yourFoo", "yours[1].someValue: yourBar")
|
||||
.applyTo(context);
|
||||
.of("spring.cloud.bootstrap.enabled=true", "yours[0].someValue: yourFoo", "yours[1].someValue: yourBar")
|
||||
.applyTo(context);
|
||||
|
||||
// collection with some encrypted keys and some not encrypted
|
||||
TestPropertyValues
|
||||
.of("mine[0].someValue: Foo", "mine[0].someKey: {cipher}Foo0", "mine[1].someValue: Bar",
|
||||
"mine[1].someKey: {cipher}Bar1", "nonindexed: nonindexval")
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "combinedTest");
|
||||
.of("mine[0].someValue: Foo", "mine[0].someKey: {cipher}Foo0", "mine[1].someValue: Bar",
|
||||
"mine[1].someKey: {cipher}Bar1", "nonindexed: nonindexval")
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "combinedTest");
|
||||
this.listener.initialize(context);
|
||||
|
||||
then(context.getEnvironment().getProperty("mine[0].someValue")).isEqualTo("Foo");
|
||||
@@ -144,7 +145,7 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
|
||||
MutablePropertySources propertySources = context.getEnvironment().getPropertySources();
|
||||
PropertySource<Map<?, ?>> decrypted = (PropertySource<Map<?, ?>>) propertySources
|
||||
.get(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
.get(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
then(decrypted.getSource().size()).as("decrypted property source had wrong size").isEqualTo(4);
|
||||
}
|
||||
|
||||
@@ -193,8 +194,9 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
public void propertySourcesOrderedCorrectlyWithUnencryptedOverrides() {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "foo: {cipher}bar").applyTo(context);
|
||||
context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "spam")));
|
||||
context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "spam")));
|
||||
this.listener.initialize(context);
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
}
|
||||
@@ -212,15 +214,16 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
ConfigurableApplicationContext context = new AnnotationConfigApplicationContext();
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true").applyTo(context);
|
||||
CompositePropertySource bootstrap = new CompositePropertySource(BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
bootstrap.addPropertySource(
|
||||
new MapPropertySource("configService", Collections.singletonMap("foo", "{cipher}bar")));
|
||||
bootstrap
|
||||
.addPropertySource(new MapPropertySource("configService", Collections.singletonMap("foo", "{cipher}bar")));
|
||||
context.getEnvironment().getPropertySources().addFirst(bootstrap);
|
||||
|
||||
Map<String, Object> props = new HashMap<>();
|
||||
props.put("foo2", "{cipher}bar2");
|
||||
props.put("bar", "{cipher}baz");
|
||||
context.getEnvironment().getPropertySources().addAfter(BOOTSTRAP_PROPERTY_SOURCE_NAME,
|
||||
new MapPropertySource("remote", props));
|
||||
context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addAfter(BOOTSTRAP_PROPERTY_SOURCE_NAME, new MapPropertySource("remote", props));
|
||||
|
||||
initializer.initialize(context);
|
||||
|
||||
@@ -236,8 +239,9 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
verify(encryptor, times(2)).decrypt("baz");
|
||||
|
||||
// Check if all encrypted properties are still decrypted
|
||||
PropertySource<?> decryptedBootstrap = context.getEnvironment().getPropertySources()
|
||||
.get(DECRYPTED_BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
PropertySource<?> decryptedBootstrap = context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.get(DECRYPTED_BOOTSTRAP_PROPERTY_SOURCE_NAME);
|
||||
then(decryptedBootstrap.getProperty("foo")).isEqualTo("bar");
|
||||
|
||||
PropertySource<?> decrypted = context.getEnvironment().getPropertySources().get(DECRYPTED_PROPERTY_SOURCE_NAME);
|
||||
@@ -252,9 +256,10 @@ public class EnvironmentDecryptApplicationInitializerTests {
|
||||
when(encryptor.decrypt("bar2")).thenReturn("bar2");
|
||||
EnvironmentDecryptApplicationInitializer initializer = new EnvironmentDecryptApplicationInitializer(encryptor);
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.enabled=true", "foo: {cipher}bar", "foo2: {cipher}bar2")
|
||||
.applyTo(context);
|
||||
context.getEnvironment().getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "spam")));
|
||||
.applyTo(context);
|
||||
context.getEnvironment()
|
||||
.getPropertySources()
|
||||
.addFirst(new MapPropertySource("test_override", Collections.singletonMap("foo", "spam")));
|
||||
initializer.initialize(context);
|
||||
then(context.getEnvironment().getProperty("foo")).isEqualTo("spam");
|
||||
then(context.getEnvironment().getProperty("foo2")).isEqualTo("bar2");
|
||||
|
||||
@@ -40,8 +40,10 @@ public class RsaDisabledTests {
|
||||
@BeforeEach
|
||||
public void setUp() {
|
||||
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
|
||||
.sources(EncryptionBootstrapConfiguration.class).web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key:mykey", "encrypt.rsa.strong:true", "encrypt.rsa.salt:foobar").run();
|
||||
.sources(EncryptionBootstrapConfiguration.class)
|
||||
.web(WebApplicationType.NONE)
|
||||
.properties("encrypt.key:mykey", "encrypt.rsa.strong:true", "encrypt.rsa.salt:foobar")
|
||||
.run();
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
|
||||
@@ -72,7 +72,8 @@ public class EnvironmentManagerIntegrationTests {
|
||||
String content = property("message", "Foo");
|
||||
|
||||
this.mvc.perform(post(BASE_PATH + "/env").content(content).contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andExpect(content().string("{\"message\":\"Foo\"}"));
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().string("{\"message\":\"Foo\"}"));
|
||||
then(this.properties.getMessage()).isEqualTo("Foo");
|
||||
}
|
||||
|
||||
@@ -88,9 +89,11 @@ public class EnvironmentManagerIntegrationTests {
|
||||
@Test
|
||||
public void testRefreshFails() throws Exception {
|
||||
try {
|
||||
this.mvc.perform(
|
||||
post(BASE_PATH + "/env").content(property("delay", "foo")).contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk()).andExpect(status().is5xxServerError());
|
||||
this.mvc
|
||||
.perform(post(BASE_PATH + "/env").content(property("delay", "foo"))
|
||||
.contentType(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(status().is5xxServerError());
|
||||
fail("expected ServletException");
|
||||
}
|
||||
catch (ServletException e) {
|
||||
@@ -111,10 +114,10 @@ public class EnvironmentManagerIntegrationTests {
|
||||
then(envbeans.get("writableEnvironmentEndpoint")).isInstanceOf(WritableEnvironmentEndpoint.class);
|
||||
|
||||
Map<String, EnvironmentEndpointWebExtension> extbeans = this.context
|
||||
.getBeansOfType(EnvironmentEndpointWebExtension.class);
|
||||
.getBeansOfType(EnvironmentEndpointWebExtension.class);
|
||||
then(extbeans).hasSize(1).containsKey("writableEnvironmentEndpointWebExtension");
|
||||
then(extbeans.get("writableEnvironmentEndpointWebExtension"))
|
||||
.isInstanceOf(WritableEnvironmentEndpointWebExtension.class);
|
||||
.isInstanceOf(WritableEnvironmentEndpointWebExtension.class);
|
||||
}
|
||||
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
|
||||
@@ -158,11 +158,11 @@ public class NamedContextFactoryTests {
|
||||
GenericApplicationContext barContext = factory.getContext("bar");
|
||||
|
||||
then(fooContext.getClassLoader()).as("foo context classloader does not match parent")
|
||||
.isSameAs(parent.getClassLoader());
|
||||
.isSameAs(parent.getClassLoader());
|
||||
|
||||
then(fooContext.getBeanFactory().getBeanClassLoader())
|
||||
.as("foo context bean factory classloader does not match parent")
|
||||
.isSameAs(parent.getBeanFactory().getBeanClassLoader());
|
||||
.as("foo context bean factory classloader does not match parent")
|
||||
.isSameAs(parent.getBeanFactory().getBeanClassLoader());
|
||||
|
||||
assertThat(fooContext).hasFieldOrPropertyWithValue("customClassLoader", true);
|
||||
|
||||
@@ -287,7 +287,7 @@ public class NamedContextFactoryTests {
|
||||
|
||||
}
|
||||
|
||||
record Container<T> (T item) {
|
||||
record Container<T>(T item) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -88,13 +88,14 @@ public class ContextRefresherTests {
|
||||
System.err.println("***** " + context.getEnvironment().getPropertySources());
|
||||
then(names).doesNotContain("bootstrapProperties");
|
||||
ContextRefresher refresher = new LegacyContextRefresher(context, this.scope);
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "defaultProperties");
|
||||
TestPropertyValues
|
||||
.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context.getEnvironment(), Type.MAP, "defaultProperties");
|
||||
refresher.refresh();
|
||||
names = names(context.getEnvironment().getPropertySources());
|
||||
then(names).first()
|
||||
.isEqualTo(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-refreshTest");
|
||||
.isEqualTo(PropertySourceBootstrapConfiguration.BOOTSTRAP_PROPERTY_SOURCE_NAME + "-refreshTest");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,9 +107,10 @@ public class ContextRefresherTests {
|
||||
"--spring.main.web-application-type=none", "--spring.cloud.bootstrap.enabled=true", "--debug=false",
|
||||
"--spring.main.bannerMode=OFF", "--spring.cloud.bootstrap.name=refresh")) {
|
||||
LegacyContextRefresher refresher = new LegacyContextRefresher(context, this.scope);
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context);
|
||||
TestPropertyValues
|
||||
.of("spring.cloud.bootstrap.sources: "
|
||||
+ "org.springframework.cloud.context.refresh.ContextRefresherTests.PropertySourceConfiguration")
|
||||
.applyTo(context);
|
||||
|
||||
ConfigurableApplicationContext refresherContext = refresher.addConfigFilesToEnvironment();
|
||||
then(refresherContext.getParent()).isNotNull().isInstanceOf(ConfigurableApplicationContext.class);
|
||||
@@ -152,28 +154,30 @@ public class ContextRefresherTests {
|
||||
@Test
|
||||
public void legacyContextRefresherCreatedUsingBootstrapEnabled() {
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.bootstrap.enabled=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(LegacyContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.bootstrap.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(LegacyContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void legacyContextRefresherCreated() {
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.withPropertyValues("spring.cloud.bootstrap.enabled=true").run(context -> {
|
||||
assertThat(context).hasSingleBean(LegacyContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
.withPropertyValues("spring.cloud.bootstrap.enabled=true")
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(LegacyContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void configDataContextRefresherCreated() {
|
||||
new ApplicationContextRunner().withConfiguration(AutoConfigurations.of(RefreshAutoConfiguration.class))
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(ConfigDataContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
.run(context -> {
|
||||
assertThat(context).hasSingleBean(ConfigDataContextRefresher.class);
|
||||
assertThat(context).hasSingleBean(ContextRefresher.class);
|
||||
});
|
||||
}
|
||||
|
||||
private List<String> names(MutablePropertySources propertySources) {
|
||||
|
||||
@@ -46,7 +46,7 @@ public class ImportRefreshScopeIntegrationTests {
|
||||
public void testSimpleProperties() {
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("service")).getScope())
|
||||
.isEqualTo("refresh");
|
||||
.isEqualTo("refresh");
|
||||
then(this.service.getMessage()).isEqualTo("Hello scope!");
|
||||
}
|
||||
|
||||
|
||||
@@ -72,7 +72,7 @@ public class RefreshEndpointIntegrationTests {
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity request = new HttpEntity(headers);
|
||||
ResponseEntity<String> refreshResponse = template
|
||||
.postForEntity("http://localhost:" + this.port + BASE_PATH + "/refresh", request, String.class);
|
||||
.postForEntity("http://localhost:" + this.port + BASE_PATH + "/refresh", request, String.class);
|
||||
assertThat(refreshResponse.getStatusCode()).isEqualTo(HttpStatus.OK);
|
||||
String message = template.getForObject("http://localhost:" + this.port + "/", String.class);
|
||||
then(message).isEqualTo("Hello Dave!");
|
||||
|
||||
@@ -55,7 +55,7 @@ public class RefreshScopeConfigurationTests {
|
||||
EnvironmentManager environmentManager = this.context.getBean(EnvironmentManager.class);
|
||||
environmentManager.setProperty("message", "Hello Dave!");
|
||||
org.springframework.cloud.context.scope.refresh.RefreshScope scope = this.context
|
||||
.getBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
.getBean(org.springframework.cloud.context.scope.refresh.RefreshScope.class);
|
||||
scope.refreshAll();
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RefreshScopeConfigurationTests {
|
||||
LifecycleMvcEndpointAutoConfiguration.class);
|
||||
Application application = this.context.getBean(Application.class);
|
||||
then(this.context.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("application")).getScope())
|
||||
.isEqualTo("refresh");
|
||||
.isEqualTo("refresh");
|
||||
application.hello();
|
||||
refresh();
|
||||
String message = application.hello();
|
||||
|
||||
@@ -35,7 +35,9 @@ public class RefreshScopeSerializationTests {
|
||||
@Test
|
||||
public void defaultApplicationContextId() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.properties("spring.cloud.bootstrap.enabled=true").web(WebApplicationType.NONE).run();
|
||||
.properties("spring.cloud.bootstrap.enabled=true")
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
then(context.getId()).isEqualTo("application-1");
|
||||
}
|
||||
|
||||
@@ -50,7 +52,8 @@ public class RefreshScopeSerializationTests {
|
||||
|
||||
private DefaultListableBeanFactory getBeanFactory() {
|
||||
ConfigurableApplicationContext context = new SpringApplicationBuilder(TestConfiguration.class)
|
||||
.web(WebApplicationType.NONE).run();
|
||||
.web(WebApplicationType.NONE)
|
||||
.run();
|
||||
DefaultListableBeanFactory factory = (DefaultListableBeanFactory) context.getAutowireCapableBeanFactory();
|
||||
return factory;
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ public class RefreshScopeWebIntegrationTests {
|
||||
@Test
|
||||
public void scopeOnBeanDefinition() {
|
||||
then(this.beanFactory.getBeanDefinition(ScopedProxyUtils.getTargetBeanName("application")).getScope())
|
||||
.isEqualTo("refresh");
|
||||
.isEqualTo("refresh");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -59,19 +59,20 @@ public class TestConfigDataLocationResolver implements ConfigDataLocationResolve
|
||||
context.getBootstrapContext().registerIfAbsent(aClass, supplier);
|
||||
}
|
||||
String myplaceholder = context.getBinder().bind("myplaceholder", Bindable.of(String.class)).orElse("notfound");
|
||||
boolean createFailsafeDelegate = context.getBinder().bind("createfailsafedelegate", Bindable.of(Boolean.class))
|
||||
.orElse(Boolean.FALSE);
|
||||
boolean createFailsafeDelegate = context.getBinder()
|
||||
.bind("createfailsafedelegate", Bindable.of(Boolean.class))
|
||||
.orElse(Boolean.FALSE);
|
||||
if (createFailsafeDelegate) {
|
||||
assertThat(context.getBootstrapContext().isRegistered(TextEncryptor.class)).isTrue();
|
||||
TextEncryptor textEncryptor = context.getBootstrapContext().get(TextEncryptor.class);
|
||||
assertThat(textEncryptor).isInstanceOf(TextEncryptorUtils.FailsafeTextEncryptor.class);
|
||||
KeyProperties keyProperties = context.getBinder().bindOrCreate(KeyProperties.PREFIX,
|
||||
Bindable.of(KeyProperties.class));
|
||||
KeyProperties keyProperties = context.getBinder()
|
||||
.bindOrCreate(KeyProperties.PREFIX, Bindable.of(KeyProperties.class));
|
||||
assertThat(TextEncryptorUtils.keysConfigured(keyProperties)).isTrue();
|
||||
RsaProperties rsaProperties = context.getBinder().bindOrCreate(RsaProperties.PREFIX,
|
||||
Bindable.of(RsaProperties.class));
|
||||
RsaProperties rsaProperties = context.getBinder()
|
||||
.bindOrCreate(RsaProperties.PREFIX, Bindable.of(RsaProperties.class));
|
||||
((TextEncryptorUtils.FailsafeTextEncryptor) textEncryptor)
|
||||
.setDelegate(TextEncryptorUtils.createTextEncryptor(keyProperties, rsaProperties));
|
||||
.setDelegate(TextEncryptorUtils.createTextEncryptor(keyProperties, rsaProperties));
|
||||
}
|
||||
HashMap<String, Object> props = new HashMap<>(config);
|
||||
props.put(TestEnvPostProcessor.EPP_VALUE, count.get());
|
||||
|
||||
@@ -71,8 +71,10 @@ public class RefreshEndpointTests {
|
||||
@Test
|
||||
@Disabled // FIXME: legacy
|
||||
public void keysComputedWhenAdded() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none").run();
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none")
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
this.context.getEnvironment().setActiveProfiles("local");
|
||||
@@ -85,8 +87,10 @@ public class RefreshEndpointTests {
|
||||
@Test
|
||||
@Disabled // FIXME: legacy
|
||||
public void keysComputedWhenOveridden() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none").run();
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.enabled=true", "spring.cloud.bootstrap.name:none")
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
this.context.getEnvironment().setActiveProfiles("override");
|
||||
@@ -98,12 +102,14 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Test
|
||||
public void keysComputedWhenChangesInExternalProperties() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none", "spring.cloud.bootstrap.enabled=true").run();
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none", "spring.cloud.bootstrap.enabled=true")
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
TestPropertyValues.of("spring.cloud.bootstrap.sources=" + ExternalPropertySourceLocator.class.getName())
|
||||
.applyTo(this.context.getEnvironment(), Type.MAP, "defaultProperties");
|
||||
.applyTo(this.context.getEnvironment(), Type.MAP, "defaultProperties");
|
||||
ContextRefresher contextRefresher = new LegacyContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
@@ -112,15 +118,17 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Test
|
||||
public void springMainSourcesEmptyInRefreshCycle() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none").run();
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.properties("spring.cloud.bootstrap.name:none")
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
// spring.main.sources should be empty when the refresh cycle starts (we don't
|
||||
// want any config files from the application context getting into the one used to
|
||||
// construct the environment for refresh)
|
||||
TestPropertyValues.of("spring.main.sources=" + ExternalPropertySourceLocator.class.getName())
|
||||
.applyTo(this.context);
|
||||
.applyTo(this.context);
|
||||
ContextRefresher contextRefresher = new LegacyContextRefresher(this.context, scope);
|
||||
RefreshEndpoint endpoint = new RefreshEndpoint(contextRefresher);
|
||||
Collection<String> keys = endpoint.refresh();
|
||||
@@ -129,8 +137,9 @@ public class RefreshEndpointTests {
|
||||
|
||||
@Test
|
||||
public void eventsPublishedInOrder() {
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE).bannerMode(Mode.OFF)
|
||||
.run();
|
||||
this.context = new SpringApplicationBuilder(Empty.class).web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.run();
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(this.context);
|
||||
ContextRefresher contextRefresher = new LegacyContextRefresher(this.context, scope);
|
||||
@@ -146,7 +155,9 @@ public class RefreshEndpointTests {
|
||||
@DisabledForJreRange(min = JRE.JAVA_16) // FIXME:
|
||||
public void shutdownHooksCleaned() {
|
||||
try (ConfigurableApplicationContext context = new SpringApplicationBuilder(Empty.class)
|
||||
.web(WebApplicationType.NONE).bannerMode(Mode.OFF).run()) {
|
||||
.web(WebApplicationType.NONE)
|
||||
.bannerMode(Mode.OFF)
|
||||
.run()) {
|
||||
RefreshScope scope = new RefreshScope();
|
||||
scope.setApplicationContext(context);
|
||||
ContextRefresher contextRefresher = new LegacyContextRefresher(context, scope);
|
||||
|
||||
@@ -73,7 +73,7 @@ public class LoggingRebinderTests {
|
||||
@Test
|
||||
public void logLevelFalseResolvedToOff() {
|
||||
ch.qos.logback.classic.Logger logger = (ch.qos.logback.classic.Logger) LoggerFactory
|
||||
.getLogger("org.springframework.cloud");
|
||||
.getLogger("org.springframework.cloud");
|
||||
StandardEnvironment environment = new StandardEnvironment();
|
||||
TestPropertyValues.of("logging.level.org.springframework.cloud=false").applyTo(environment);
|
||||
rebinder.setEnvironment(environment);
|
||||
|
||||
Reference in New Issue
Block a user