Add unit test to verify spring.config.activate.on-profile is supported in bootstrap.yaml (#1469)

See GH-1416

Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
This commit is contained in:
Yanming Zhou
2025-03-13 18:48:57 +08:00
committed by GitHub
parent 6ed6e440fb
commit 7b4daa219c
2 changed files with 26 additions and 1 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2020 the original author or authors.
* Copyright 2012-2025 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@ import static org.assertj.core.api.BDDAssertions.then;
/**
* @author Dave Syer
* @author Yanming Zhou
*
*/
public class BootstrapConfigurationTests {
@@ -740,6 +741,23 @@ public class BootstrapConfigurationTests {
.anyMatch("local"::equals)).isTrue();
}
@Test // GH-1416
public void bootstrapPropertiesWithActivateOnProfile() {
String bootstrapLocation = "spring.cloud.bootstrap.location=classpath:external-properties/bootstrap.yaml";
String legacyProcessing = "spring.config.use-legacy-processing=true";
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.sources(BareConfiguration.class)
.properties(bootstrapLocation, legacyProcessing)
.run();
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName");
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
.sources(BareConfiguration.class)
.properties(bootstrapLocation, legacyProcessing, "spring.profiles.active=bar")
.run();
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName from bar");
}
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties
protected static class BareConfiguration {

View File

@@ -0,0 +1,7 @@
spring.main.sources: org.springframework.cloud.bootstrap.config.BootstrapConfigurationTests.PropertySourceConfiguration
info.name: externalPropertiesInfoName
---
spring.config.activate.on-profile: bar
info.name: externalPropertiesInfoName from bar