Skip to content

Commit 93d316d

Browse files
committed
Add additional ConfigDataProperties tests
Add more `isActive` tests to cover negative cases. See gh-27017
1 parent b91c66b commit 93d316d

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataPropertiesTests.java

Lines changed: 25 additions & 4 deletions
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-2021 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.
@@ -160,18 +160,39 @@ void isActiveWhenActivateIsNull() {
160160
@Test
161161
void isActiveAgainstBoundData() {
162162
MapConfigurationPropertySource source = new MapConfigurationPropertySource();
163-
source.put("spring.config.import", "one,two,three");
164163
source.put("spring.config.activate.on-cloud-platform", "kubernetes");
165164
source.put("spring.config.activate.on-profile", "a | b");
166165
Binder binder = new Binder(source);
167166
ConfigDataProperties properties = ConfigDataProperties.get(binder);
168167
ConfigDataActivationContext context = new ConfigDataActivationContext(CloudPlatform.KUBERNETES,
169168
createTestProfiles());
170-
assertThat(properties.getImports()).containsExactly(ConfigDataLocation.of("one"), ConfigDataLocation.of("two"),
171-
ConfigDataLocation.of("three"));
172169
assertThat(properties.isActive(context)).isTrue();
173170
}
174171

172+
@Test
173+
void isActiveAgainstBoundDataWhenProfilesDontMatch() {
174+
MapConfigurationPropertySource source = new MapConfigurationPropertySource();
175+
source.put("spring.config.activate.on-cloud-platform", "kubernetes");
176+
source.put("spring.config.activate.on-profile", "x | z");
177+
Binder binder = new Binder(source);
178+
ConfigDataProperties properties = ConfigDataProperties.get(binder);
179+
ConfigDataActivationContext context = new ConfigDataActivationContext(CloudPlatform.KUBERNETES,
180+
createTestProfiles());
181+
assertThat(properties.isActive(context)).isFalse();
182+
}
183+
184+
@Test
185+
void isActiveAgainstBoundDataWhenCloudPlatformDoesntMatch() {
186+
MapConfigurationPropertySource source = new MapConfigurationPropertySource();
187+
source.put("spring.config.activate.on-cloud-platform", "cloud-foundry");
188+
source.put("spring.config.activate.on-profile", "a | b");
189+
Binder binder = new Binder(source);
190+
ConfigDataProperties properties = ConfigDataProperties.get(binder);
191+
ConfigDataActivationContext context = new ConfigDataActivationContext(CloudPlatform.KUBERNETES,
192+
createTestProfiles());
193+
assertThat(properties.isActive(context)).isFalse();
194+
}
195+
175196
@Test
176197
void isActiveWhenBindingToLegacyProperty() {
177198
MapConfigurationPropertySource source = new MapConfigurationPropertySource();

0 commit comments

Comments
 (0)