Skip to content

Commit 7b4daa2

Browse files
authored
Add unit test to verify spring.config.activate.on-profile is supported in bootstrap.yaml (#1469)
See GH-1416 Signed-off-by: Yanming Zhou <[email protected]>
1 parent 6ed6e44 commit 7b4daa2

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

spring-cloud-context/src/test/java/org/springframework/cloud/bootstrap/config/BootstrapConfigurationTests.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -49,6 +49,7 @@
4949

5050
/**
5151
* @author Dave Syer
52+
* @author Yanming Zhou
5253
*
5354
*/
5455
public class BootstrapConfigurationTests {
@@ -740,6 +741,23 @@ void activeAndIncludeProfileFromBootstrapPropertySource_WhenMultiplePlacesHaveAc
740741
.anyMatch("local"::equals)).isTrue();
741742
}
742743

744+
@Test // GH-1416
745+
public void bootstrapPropertiesWithActivateOnProfile() {
746+
String bootstrapLocation = "spring.cloud.bootstrap.location=classpath:external-properties/bootstrap.yaml";
747+
String legacyProcessing = "spring.config.use-legacy-processing=true";
748+
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
749+
.sources(BareConfiguration.class)
750+
.properties(bootstrapLocation, legacyProcessing)
751+
.run();
752+
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName");
753+
754+
this.context = new SpringApplicationBuilder().web(WebApplicationType.NONE)
755+
.sources(BareConfiguration.class)
756+
.properties(bootstrapLocation, legacyProcessing, "spring.profiles.active=bar")
757+
.run();
758+
then(this.context.getEnvironment().getProperty("info.name")).isEqualTo("externalPropertiesInfoName from bar");
759+
}
760+
743761
@Configuration(proxyBeanMethods = false)
744762
@EnableConfigurationProperties
745763
protected static class BareConfiguration {
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
spring.main.sources: org.springframework.cloud.bootstrap.config.BootstrapConfigurationTests.PropertySourceConfiguration
2+
info.name: externalPropertiesInfoName
3+
4+
---
5+
spring.config.activate.on-profile: bar
6+
info.name: externalPropertiesInfoName from bar
7+

0 commit comments

Comments
 (0)