File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed
spring-boot-project/spring-boot/src
main/java/org/springframework/boot/cloud
test/java/org/springframework/boot/cloud Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change 29
29
*
30
30
* @author Phillip Webb
31
31
* @author Brian Clozel
32
+ * @author Nguyen Sach
32
33
* @since 1.3.0
33
34
*/
34
35
public enum CloudPlatform {
@@ -157,7 +158,8 @@ public boolean isDetected(Environment environment) {
157
158
* @return if the platform is active.
158
159
*/
159
160
public boolean isActive (Environment environment ) {
160
- return isEnforced (environment ) || isDetected (environment );
161
+ String platformProperty = environment .getProperty (PROPERTY_NAME );
162
+ return isEnforced (platformProperty ) || (platformProperty == null && isDetected (environment ));
161
163
}
162
164
163
165
/**
Original file line number Diff line number Diff line change 19
19
import java .util .Collections ;
20
20
import java .util .HashMap ;
21
21
import java .util .Map ;
22
+ import java .util .stream .Stream ;
22
23
23
24
import org .junit .jupiter .api .Test ;
24
25
36
37
* Tests for {@link CloudPlatform}.
37
38
*
38
39
* @author Phillip Webb
40
+ * @author Nguyen Sach
39
41
*/
40
42
class CloudPlatformTests {
41
43
@@ -202,6 +204,16 @@ void isEnforcedWhenBinderPropertyIsMissingReturnsFalse() {
202
204
assertThat (CloudPlatform .KUBERNETES .isEnforced (binder )).isFalse ();
203
205
}
204
206
207
+ void isActiveWhenNoCloudPlatformIsEnforcedAndHasKubernetesServiceHostAndKubernetesServicePort () {
208
+ Map <String , Object > envVars = new HashMap <>();
209
+ envVars .put ("EXAMPLE_SERVICE_HOST" , "---" );
210
+ envVars .put ("EXAMPLE_SERVICE_PORT" , "8080" );
211
+ Environment environment = getEnvironmentWithEnvVariables (envVars );
212
+ ((MockEnvironment ) environment ).setProperty ("spring.main.cloud-platform" , "none" );
213
+ assertThat (Stream .of (CloudPlatform .values ()).filter ((platform ) -> platform .isActive (environment )))
214
+ .containsExactly (CloudPlatform .NONE );
215
+ }
216
+
205
217
private Environment getEnvironmentWithEnvVariables (Map <String , Object > environmentVariables ) {
206
218
MockEnvironment environment = new MockEnvironment ();
207
219
PropertySource <?> propertySource = new SystemEnvironmentPropertySource (
You can’t perform that action at this time.
0 commit comments