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
4d311821
Commit
4d311821
authored
Apr 07, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish "Add detection of Azure App Service to CloudPlatform"
See gh-25829
parent
98a1017e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
46 deletions
+45
-46
CloudPlatform.java
...in/java/org/springframework/boot/cloud/CloudPlatform.java
+18
-18
CloudPlatformTests.java
...va/org/springframework/boot/cloud/CloudPlatformTests.java
+27
-28
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/cloud/CloudPlatform.java
View file @
4d311821
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -45,23 +45,6 @@ public enum CloudPlatform {
},
/**
* Azure App Service platform.
*/
AZURE_APP_SERVICE
{
private
static
final
String
WEBSITE_SITE_NAME
=
"WEBSITE_SITE_NAME"
;
private
static
final
String
WEBSITES_ENABLE_APP_SERVICE_STORAGE
=
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
;
@Override
public
boolean
isDetected
(
Environment
environment
)
{
return
environment
.
containsProperty
(
WEBSITE_SITE_NAME
)
&&
environment
.
containsProperty
(
WEBSITES_ENABLE_APP_SERVICE_STORAGE
);
}
},
/**
* Cloud Foundry platform.
*/
...
...
@@ -147,6 +130,23 @@ public enum CloudPlatform {
return
false
;
}
},
/**
* Azure App Service platform.
*/
AZURE_APP_SERVICE
{
private
static
final
String
WEBSITE_SITE_NAME
=
"WEBSITE_SITE_NAME"
;
private
static
final
String
WEBSITES_ENABLE_APP_SERVICE_STORAGE
=
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
;
@Override
public
boolean
isDetected
(
Environment
environment
)
{
return
environment
.
containsProperty
(
WEBSITE_SITE_NAME
)
&&
environment
.
containsProperty
(
WEBSITES_ENABLE_APP_SERVICE_STORAGE
);
}
};
private
static
final
String
PROPERTY_NAME
=
"spring.main.cloud-platform"
;
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/cloud/CloudPlatformTests.java
View file @
4d311821
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -52,33 +52,6 @@ class CloudPlatformTests {
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService
()
{
Map
<
String
,
Object
>
envVars
=
new
HashMap
<>();
envVars
.
put
(
"WEBSITE_SITE_NAME"
,
"---"
);
envVars
.
put
(
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
,
"false"
);
Environment
environment
=
getEnvironmentWithEnvVariables
(
envVars
);
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isEqualTo
(
CloudPlatform
.
AZURE_APP_SERVICE
);
assertThat
(
platform
.
isActive
(
environment
)).
isTrue
();
}
@Test
void
getActiveWhenHasWebsiteSiteNameShouldReturnNull
()
{
Environment
environment
=
getEnvironmentWithEnvVariables
(
Collections
.
singletonMap
(
"WEBSITE_SITE_NAME"
,
"---"
));
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasWebsitesEnableAppServiceStorageShouldReturnNull
()
{
Environment
environment
=
getEnvironmentWithEnvVariables
(
Collections
.
singletonMap
(
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
,
"---"
));
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasVcapApplicationShouldReturnCloudFoundry
()
{
Environment
environment
=
new
MockEnvironment
().
withProperty
(
"VCAP_APPLICATION"
,
"---"
);
...
...
@@ -157,6 +130,32 @@ class CloudPlatformTests {
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasWebsiteSiteNameAndWebsitesEnableAppServiceStorageShouldReturnAzureAppService
()
{
Map
<
String
,
Object
>
envVars
=
new
HashMap
<>();
envVars
.
put
(
"WEBSITE_SITE_NAME"
,
"---"
);
envVars
.
put
(
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
,
"false"
);
Environment
environment
=
getEnvironmentWithEnvVariables
(
envVars
);
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isEqualTo
(
CloudPlatform
.
AZURE_APP_SERVICE
);
assertThat
(
platform
.
isActive
(
environment
)).
isTrue
();
}
@Test
void
getActiveWhenHasWebsiteSiteNameAndNoWebsitesEnableAppServiceStorageShouldNotReturnAzureAppService
()
{
Environment
environment
=
getEnvironmentWithEnvVariables
(
Collections
.
singletonMap
(
"WEBSITE_SITE_NAME"
,
"---"
));
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasWebsitesEnableAppServiceStorageAndNoWebsiteNameShouldNotReturnAzureAppService
()
{
Environment
environment
=
getEnvironmentWithEnvVariables
(
Collections
.
singletonMap
(
"WEBSITES_ENABLE_APP_SERVICE_STORAGE"
,
"---"
));
CloudPlatform
platform
=
CloudPlatform
.
getActive
(
environment
);
assertThat
(
platform
).
isNull
();
}
@Test
void
getActiveWhenHasEnforcedCloudPlatform
()
{
Environment
environment
=
getEnvironmentWithEnvVariables
(
...
...
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