Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
282a8e09
Commit
282a8e09
authored
Apr 15, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.4.x'
Closes gh-26125
parents
b4c9bb0d
5b836f3a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
1 deletion
+15
-1
CloudPlatform.java
...in/java/org/springframework/boot/cloud/CloudPlatform.java
+3
-1
CloudPlatformTests.java
...va/org/springframework/boot/cloud/CloudPlatformTests.java
+12
-0
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java
View file @
282a8e09
...
@@ -29,6 +29,7 @@ import org.springframework.core.env.StandardEnvironment;
...
@@ -29,6 +29,7 @@ import org.springframework.core.env.StandardEnvironment;
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Brian Clozel
* @author Brian Clozel
* @author Nguyen Sach
* @since 1.3.0
* @since 1.3.0
*/
*/
public
enum
CloudPlatform
{
public
enum
CloudPlatform
{
...
@@ -157,7 +158,8 @@ public enum CloudPlatform {
...
@@ -157,7 +158,8 @@ public enum CloudPlatform {
* @return if the platform is active.
* @return if the platform is active.
*/
*/
public
boolean
isActive
(
Environment
environment
)
{
public
boolean
isActive
(
Environment
environment
)
{
return
isEnforced
(
environment
)
||
isDetected
(
environment
);
String
platformProperty
=
environment
.
getProperty
(
PROPERTY_NAME
);
return
isEnforced
(
platformProperty
)
||
(
platformProperty
==
null
&&
isDetected
(
environment
));
}
}
/**
/**
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java
View file @
282a8e09
...
@@ -19,6 +19,7 @@ package org.springframework.boot.cloud;
...
@@ -19,6 +19,7 @@ package org.springframework.boot.cloud;
import
java.util.Collections
;
import
java.util.Collections
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
import
java.util.stream.Stream
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
...
@@ -36,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
...
@@ -36,6 +37,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link CloudPlatform}.
* Tests for {@link CloudPlatform}.
*
*
* @author Phillip Webb
* @author Phillip Webb
* @author Nguyen Sach
*/
*/
class
CloudPlatformTests
{
class
CloudPlatformTests
{
...
@@ -202,6 +204,16 @@ class CloudPlatformTests {
...
@@ -202,6 +204,16 @@ class CloudPlatformTests {
assertThat
(
CloudPlatform
.
KUBERNETES
.
isEnforced
(
binder
)).
isFalse
();
assertThat
(
CloudPlatform
.
KUBERNETES
.
isEnforced
(
binder
)).
isFalse
();
}
}
void
isActiveWhenNoCloudPlatformIsEnforcedAndHasKubernetesServiceHostAndKubernetesServicePort
()
{
Map
<
String
,
Object
>
envVars
=
new
HashMap
<>();
envVars
.
put
(
"EXAMPLE_SERVICE_HOST"
,
"---"
);
envVars
.
put
(
"EXAMPLE_SERVICE_PORT"
,
"8080"
);
Environment
environment
=
getEnvironmentWithEnvVariables
(
envVars
);
((
MockEnvironment
)
environment
).
setProperty
(
"spring.main.cloud-platform"
,
"none"
);
assertThat
(
Stream
.
of
(
CloudPlatform
.
values
()).
filter
((
platform
)
->
platform
.
isActive
(
environment
)))
.
containsExactly
(
CloudPlatform
.
NONE
);
}
private
Environment
getEnvironmentWithEnvVariables
(
Map
<
String
,
Object
>
environmentVariables
)
{
private
Environment
getEnvironmentWithEnvVariables
(
Map
<
String
,
Object
>
environmentVariables
)
{
MockEnvironment
environment
=
new
MockEnvironment
();
MockEnvironment
environment
=
new
MockEnvironment
();
PropertySource
<?>
propertySource
=
new
SystemEnvironmentPropertySource
(
PropertySource
<?>
propertySource
=
new
SystemEnvironmentPropertySource
(
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment