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
86dc1561
Commit
86dc1561
authored
Jun 22, 2021
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.5.x'
Closes gh-27006
parents
752a9296
f914dc15
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
44 additions
and
50 deletions
+44
-50
ConfigDataEnvironmentContributors.java
...oot/context/config/ConfigDataEnvironmentContributors.java
+1
-2
ConfigDataImporter.java
...ringframework/boot/context/config/ConfigDataImporter.java
+6
-8
ConfigDataLocationResolvers.java
...work/boot/context/config/ConfigDataLocationResolvers.java
+4
-5
ConfigDataEnvironmentContributorsTests.java
...ontext/config/ConfigDataEnvironmentContributorsTests.java
+14
-16
ConfigDataEnvironmentPostProcessorIntegrationTests.java
...g/ConfigDataEnvironmentPostProcessorIntegrationTests.java
+7
-7
ConfigDataImporterTests.java
...ramework/boot/context/config/ConfigDataImporterTests.java
+8
-8
ConfigDataLocationResolversTests.java
...boot/context/config/ConfigDataLocationResolversTests.java
+4
-4
No files found.
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributors.java
View file @
86dc1561
...
...
@@ -117,10 +117,9 @@ class ConfigDataEnvironmentContributors implements Iterable<ConfigDataEnvironmen
result
,
contributor
,
activationContext
);
ConfigDataLoaderContext
loaderContext
=
new
ContributorDataLoaderContext
(
this
);
List
<
ConfigDataLocation
>
imports
=
contributor
.
getImports
();
boolean
resolveProfileSpecific
=
!
contributor
.
isFromProfileSpecificImport
();
this
.
logger
.
trace
(
LogMessage
.
format
(
"Processing imports %s"
,
imports
));
Map
<
ConfigDataResolutionResult
,
ConfigData
>
imported
=
importer
.
resolveAndLoad
(
activationContext
,
locationResolverContext
,
loaderContext
,
imports
,
resolveProfileSpecific
);
locationResolverContext
,
loaderContext
,
imports
);
this
.
logger
.
trace
(
LogMessage
.
of
(()
->
getImportedMessage
(
imported
.
keySet
())));
ConfigDataEnvironmentContributor
contributorAndChildren
=
contributor
.
withChildren
(
importPhase
,
asContributors
(
imported
));
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataImporter.java
View file @
86dc1561
...
...
@@ -75,16 +75,14 @@ class ConfigDataImporter {
* @param locationResolverContext the location resolver context
* @param loaderContext the loader context
* @param locations the locations to resolve
* @param resolveProfileSpecific if profile specific resolution should be attempted
* @return a map of the loaded locations and data
*/
Map
<
ConfigDataResolutionResult
,
ConfigData
>
resolveAndLoad
(
ConfigDataActivationContext
activationContext
,
ConfigDataLocationResolverContext
locationResolverContext
,
ConfigDataLoaderContext
loaderContext
,
List
<
ConfigDataLocation
>
locations
,
boolean
resolveProfileSpecific
)
{
List
<
ConfigDataLocation
>
locations
)
{
try
{
Profiles
profiles
=
(
activationContext
!=
null
)
?
activationContext
.
getProfiles
()
:
null
;
List
<
ConfigDataResolutionResult
>
resolved
=
resolve
(
locationResolverContext
,
profiles
,
locations
,
resolveProfileSpecific
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolve
(
locationResolverContext
,
profiles
,
locations
);
return
load
(
loaderContext
,
resolved
);
}
catch
(
IOException
ex
)
{
...
...
@@ -93,18 +91,18 @@ class ConfigDataImporter {
}
private
List
<
ConfigDataResolutionResult
>
resolve
(
ConfigDataLocationResolverContext
locationResolverContext
,
Profiles
profiles
,
List
<
ConfigDataLocation
>
locations
,
boolean
resolveProfileSpecific
)
{
Profiles
profiles
,
List
<
ConfigDataLocation
>
locations
)
{
List
<
ConfigDataResolutionResult
>
resolved
=
new
ArrayList
<>(
locations
.
size
());
for
(
ConfigDataLocation
location
:
locations
)
{
resolved
.
addAll
(
resolve
(
locationResolverContext
,
profiles
,
location
,
resolveProfileSpecific
));
resolved
.
addAll
(
resolve
(
locationResolverContext
,
profiles
,
location
));
}
return
Collections
.
unmodifiableList
(
resolved
);
}
private
List
<
ConfigDataResolutionResult
>
resolve
(
ConfigDataLocationResolverContext
locationResolverContext
,
Profiles
profiles
,
ConfigDataLocation
location
,
boolean
resolveProfileSpecific
)
{
Profiles
profiles
,
ConfigDataLocation
location
)
{
try
{
return
this
.
resolvers
.
resolve
(
locationResolverContext
,
location
,
profiles
,
resolveProfileSpecific
);
return
this
.
resolvers
.
resolve
(
locationResolverContext
,
location
,
profiles
);
}
catch
(
ConfigDataNotFoundException
ex
)
{
handle
(
ex
,
location
,
null
);
...
...
spring-boot-project/spring-boot/src/main/java/org/springframework/boot/context/config/ConfigDataLocationResolvers.java
View file @
86dc1561
...
...
@@ -98,23 +98,22 @@ class ConfigDataLocationResolvers {
}
List
<
ConfigDataResolutionResult
>
resolve
(
ConfigDataLocationResolverContext
context
,
ConfigDataLocation
location
,
Profiles
profiles
,
boolean
resolveProfileSpecific
)
{
Profiles
profiles
)
{
if
(
location
==
null
)
{
return
Collections
.
emptyList
();
}
for
(
ConfigDataLocationResolver
<?>
resolver
:
getResolvers
())
{
if
(
resolver
.
isResolvable
(
context
,
location
))
{
return
resolve
(
resolver
,
context
,
location
,
profiles
,
resolveProfileSpecific
);
return
resolve
(
resolver
,
context
,
location
,
profiles
);
}
}
throw
new
UnsupportedConfigDataLocationException
(
location
);
}
private
List
<
ConfigDataResolutionResult
>
resolve
(
ConfigDataLocationResolver
<?>
resolver
,
ConfigDataLocationResolverContext
context
,
ConfigDataLocation
location
,
Profiles
profiles
,
boolean
resolveProfileSpecific
)
{
ConfigDataLocationResolverContext
context
,
ConfigDataLocation
location
,
Profiles
profiles
)
{
List
<
ConfigDataResolutionResult
>
resolved
=
resolve
(
location
,
false
,
()
->
resolver
.
resolve
(
context
,
location
));
if
(
profiles
==
null
||
!
resolveProfileSpecific
)
{
if
(
profiles
==
null
)
{
return
resolved
;
}
List
<
ConfigDataResolutionResult
>
profileSpecific
=
resolve
(
location
,
true
,
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentContributorsTests.java
View file @
86dc1561
...
...
@@ -44,7 +44,6 @@ import org.springframework.mock.env.MockPropertySource;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThatExceptionOfType
;
import
static
org
.
mockito
.
ArgumentMatchers
.
any
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyBoolean
;
import
static
org
.
mockito
.
ArgumentMatchers
.
eq
;
import
static
org
.
mockito
.
BDDMockito
.
given
;
import
static
org
.
mockito
.
Mockito
.
mock
;
...
...
@@ -122,7 +121,7 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
imported
=
new
LinkedHashMap
<>();
imported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
propertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)))
.
willReturn
(
imported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
...
...
@@ -145,14 +144,14 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
initialImported
=
new
LinkedHashMap
<>();
initialImported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
initialPropertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
initialLocations
)
,
anyBoolean
()))
.
willReturn
(
initialImported
);
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
initialLocations
)
))
.
willReturn
(
initialImported
);
List
<
ConfigDataLocation
>
secondLocations
=
Arrays
.
asList
(
LOCATION_2
);
MockPropertySource
secondPropertySource
=
new
MockPropertySource
();
Map
<
ConfigDataResolutionResult
,
ConfigData
>
secondImported
=
new
LinkedHashMap
<>();
secondImported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_2
,
new
TestConfigDataResource
(
"b"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
secondPropertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
secondLocations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
secondLocations
)))
.
willReturn
(
secondImported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
...
...
@@ -179,13 +178,13 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
imported
=
new
LinkedHashMap
<>();
imported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a'"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
propertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)))
.
willReturn
(
imported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
this
.
bootstrapContext
,
Arrays
.
asList
(
existingContributor
,
contributor
));
contributors
.
withProcessedImports
(
this
.
importer
,
this
.
activationContext
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
any
()
,
anyBoolean
()
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
any
());
ConfigDataLocationResolverContext
context
=
this
.
locationResolverContext
.
getValue
();
assertThat
(
context
.
getBinder
().
bind
(
"test"
,
String
.
class
).
get
()).
isEqualTo
(
"springboot"
);
}
...
...
@@ -199,21 +198,20 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
initialImported
=
new
LinkedHashMap
<>();
initialImported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
initialPropertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
initialLocations
)
,
anyBoolean
()))
.
willReturn
(
initialImported
);
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
initialLocations
)
))
.
willReturn
(
initialImported
);
List
<
ConfigDataLocation
>
secondLocations
=
Arrays
.
asList
(
LOCATION_2
);
MockPropertySource
secondPropertySource
=
new
MockPropertySource
();
Map
<
ConfigDataResolutionResult
,
ConfigData
>
secondImported
=
new
LinkedHashMap
<>();
secondImported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_2
,
new
TestConfigDataResource
(
"b"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
secondPropertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
secondLocations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
secondLocations
)))
.
willReturn
(
secondImported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
this
.
bootstrapContext
,
Arrays
.
asList
(
contributor
));
contributors
.
withProcessedImports
(
this
.
importer
,
this
.
activationContext
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
eq
(
secondLocations
),
anyBoolean
());
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
eq
(
secondLocations
));
ConfigDataLocationResolverContext
context
=
this
.
locationResolverContext
.
getValue
();
assertThat
(
context
.
getParent
()).
hasToString
(
"a"
);
}
...
...
@@ -230,13 +228,13 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
imported
=
new
LinkedHashMap
<>();
imported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a'"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
propertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)))
.
willReturn
(
imported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
this
.
bootstrapContext
,
Arrays
.
asList
(
existingContributor
,
contributor
));
contributors
.
withProcessedImports
(
this
.
importer
,
this
.
activationContext
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
any
()
,
anyBoolean
()
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
this
.
locationResolverContext
.
capture
(),
any
(),
any
());
ConfigDataLocationResolverContext
context
=
this
.
locationResolverContext
.
getValue
();
assertThat
(
context
.
getBootstrapContext
()).
isSameAs
(
this
.
bootstrapContext
);
}
...
...
@@ -253,13 +251,13 @@ class ConfigDataEnvironmentContributorsTests {
Map
<
ConfigDataResolutionResult
,
ConfigData
>
imported
=
new
LinkedHashMap
<>();
imported
.
put
(
new
ConfigDataResolutionResult
(
LOCATION_1
,
new
TestConfigDataResource
(
"a'"
),
false
),
new
ConfigData
(
Arrays
.
asList
(
propertySource
)));
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)
,
anyBoolean
()
))
given
(
this
.
importer
.
resolveAndLoad
(
eq
(
this
.
activationContext
),
any
(),
any
(),
eq
(
locations
)))
.
willReturn
(
imported
);
ConfigDataEnvironmentContributor
contributor
=
ConfigDataEnvironmentContributor
.
ofInitialImport
(
LOCATION_1
);
ConfigDataEnvironmentContributors
contributors
=
new
ConfigDataEnvironmentContributors
(
this
.
logFactory
,
this
.
bootstrapContext
,
Arrays
.
asList
(
existingContributor
,
contributor
));
contributors
.
withProcessedImports
(
this
.
importer
,
this
.
activationContext
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
any
(),
this
.
loaderContext
.
capture
(),
any
()
,
anyBoolean
()
);
verify
(
this
.
importer
).
resolveAndLoad
(
any
(),
any
(),
this
.
loaderContext
.
capture
(),
any
());
ConfigDataLoaderContext
context
=
this
.
loaderContext
.
getValue
();
assertThat
(
context
.
getBootstrapContext
()).
isSameAs
(
this
.
bootstrapContext
);
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataEnvironmentPostProcessorIntegrationTests.java
View file @
86dc1561
...
...
@@ -750,8 +750,8 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat
(
environment
.
getProperty
(
"test2"
)).
isEqualTo
(
"test2"
);
}
@Test
// gh-26
752
void
runWhenHasProfileSpecificImportWithImport
DoesNotImport
SecondProfileSpecificFile
()
{
@Test
// gh-26
960
void
runWhenHasProfileSpecificImportWithImport
Imports
SecondProfileSpecificFile
()
{
ConfigurableApplicationContext
context
=
this
.
application
.
run
(
"--spring.config.name=application-profile-specific-import-with-import"
);
ConfigurableEnvironment
environment
=
context
.
getEnvironment
();
...
...
@@ -759,17 +759,17 @@ class ConfigDataEnvironmentPostProcessorIntegrationTests {
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-p1"
)).
isTrue
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-p2"
)).
isFalse
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-import"
)).
isTrue
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-import-p1"
)).
is
Fals
e
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-import-p2"
)).
is
Fals
e
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-import-p1"
)).
is
Tru
e
();
assertThat
(
environment
.
containsProperty
(
"application-profile-specific-import-with-import-import-p2"
)).
is
Tru
e
();
}
@Test
// gh-26
753
void
runWhenHasProfileSpecificImportWithCustomImport
DoesNotResolve
ProfileSpecific
()
{
@Test
// gh-26
960
void
runWhenHasProfileSpecificImportWithCustomImport
Resolves
ProfileSpecific
()
{
ConfigurableApplicationContext
context
=
this
.
application
.
run
(
"--spring.config.name=application-profile-specific-import-with-custom-import"
);
ConfigurableEnvironment
environment
=
context
.
getEnvironment
();
assertThat
(
environment
.
containsProperty
(
"test:boot"
)).
isTrue
();
assertThat
(
environment
.
containsProperty
(
"test:boot:ps"
)).
is
Fals
e
();
assertThat
(
environment
.
containsProperty
(
"test:boot:ps"
)).
is
Tru
e
();
}
@Test
// gh-26593
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataImporterTests.java
View file @
86dc1561
...
...
@@ -80,16 +80,16 @@ class ConfigDataImporterTests {
TestResource
resource2
=
new
TestResource
(
"r2"
);
ConfigData
configData1
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
ConfigData
configData2
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location1
,
this
.
profiles
,
true
))
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location1
,
this
.
profiles
))
.
willReturn
(
Collections
.
singletonList
(
new
ConfigDataResolutionResult
(
location1
,
resource1
,
false
)));
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location2
,
this
.
profiles
,
true
))
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location2
,
this
.
profiles
))
.
willReturn
(
Collections
.
singletonList
(
new
ConfigDataResolutionResult
(
location2
,
resource2
,
false
)));
given
(
this
.
loaders
.
load
(
this
.
loaderContext
,
resource1
)).
willReturn
(
configData1
);
given
(
this
.
loaders
.
load
(
this
.
loaderContext
,
resource2
)).
willReturn
(
configData2
);
ConfigDataImporter
importer
=
new
ConfigDataImporter
(
this
.
logFactory
,
ConfigDataNotFoundAction
.
FAIL
,
this
.
resolvers
,
this
.
loaders
);
Collection
<
ConfigData
>
loaded
=
importer
.
resolveAndLoad
(
this
.
activationContext
,
this
.
locationResolverContext
,
this
.
loaderContext
,
Arrays
.
asList
(
location1
,
location2
)
,
true
).
values
();
this
.
loaderContext
,
Arrays
.
asList
(
location1
,
location2
)).
values
();
assertThat
(
loaded
).
containsExactly
(
configData2
,
configData1
);
}
...
...
@@ -106,11 +106,11 @@ class ConfigDataImporterTests {
ConfigData
configData1
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
ConfigData
configData2
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
ConfigData
configData3
=
new
ConfigData
(
Collections
.
singleton
(
new
MockPropertySource
()));
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location1
,
this
.
profiles
,
true
))
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location1
,
this
.
profiles
))
.
willReturn
(
Collections
.
singletonList
(
new
ConfigDataResolutionResult
(
location1
,
resource1
,
false
)));
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location2
,
this
.
profiles
,
true
))
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location2
,
this
.
profiles
))
.
willReturn
(
Collections
.
singletonList
(
new
ConfigDataResolutionResult
(
location2
,
resource2
,
false
)));
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location3
,
this
.
profiles
,
true
))
given
(
this
.
resolvers
.
resolve
(
this
.
locationResolverContext
,
location3
,
this
.
profiles
))
.
willReturn
(
Collections
.
singletonList
(
new
ConfigDataResolutionResult
(
location3
,
resource3
,
false
)));
given
(
this
.
loaders
.
load
(
this
.
loaderContext
,
resource1
)).
willReturn
(
configData1
);
given
(
this
.
loaders
.
load
(
this
.
loaderContext
,
resource2
)).
willReturn
(
configData2
);
...
...
@@ -118,9 +118,9 @@ class ConfigDataImporterTests {
ConfigDataImporter
importer
=
new
ConfigDataImporter
(
this
.
logFactory
,
ConfigDataNotFoundAction
.
FAIL
,
this
.
resolvers
,
this
.
loaders
);
Collection
<
ConfigData
>
loaded1and2
=
importer
.
resolveAndLoad
(
this
.
activationContext
,
this
.
locationResolverContext
,
this
.
loaderContext
,
locations1and2
,
true
).
values
();
this
.
locationResolverContext
,
this
.
loaderContext
,
locations1and2
).
values
();
Collection
<
ConfigData
>
loaded2and3
=
importer
.
resolveAndLoad
(
this
.
activationContext
,
this
.
locationResolverContext
,
this
.
loaderContext
,
locations2and3
,
true
).
values
();
this
.
locationResolverContext
,
this
.
loaderContext
,
locations2and3
).
values
();
assertThat
(
loaded1and2
).
containsExactly
(
configData2
,
configData1
);
assertThat
(
loaded2and3
).
containsExactly
(
configData3
);
}
...
...
spring-boot-project/spring-boot/src/test/java/org/springframework/boot/context/config/ConfigDataLocationResolversTests.java
View file @
86dc1561
...
...
@@ -131,7 +131,7 @@ class ConfigDataLocationResolversTests {
this
.
binder
,
this
.
resourceLoader
,
Arrays
.
asList
(
LowestTestResolver
.
class
.
getName
(),
HighestTestResolver
.
class
.
getName
()));
ConfigDataLocation
location
=
ConfigDataLocation
.
of
(
"LowestTestResolver:test"
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
null
,
true
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
null
);
assertThat
(
resolved
).
hasSize
(
1
);
TestConfigDataResource
resource
=
(
TestConfigDataResource
)
resolved
.
get
(
0
).
getResource
();
assertThat
(
resource
.
getResolver
()).
isInstanceOf
(
LowestTestResolver
.
class
);
...
...
@@ -145,7 +145,7 @@ class ConfigDataLocationResolversTests {
this
.
binder
,
this
.
resourceLoader
,
Arrays
.
asList
(
LowestTestResolver
.
class
.
getName
(),
HighestTestResolver
.
class
.
getName
()));
ConfigDataLocation
location
=
ConfigDataLocation
.
of
(
"LowestTestResolver:test"
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
this
.
profiles
,
true
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
this
.
profiles
);
assertThat
(
resolved
).
hasSize
(
2
);
TestConfigDataResource
resource
=
(
TestConfigDataResource
)
resolved
.
get
(
0
).
getResource
();
assertThat
(
resource
.
getResolver
()).
isInstanceOf
(
LowestTestResolver
.
class
);
...
...
@@ -164,7 +164,7 @@ class ConfigDataLocationResolversTests {
Arrays
.
asList
(
LowestTestResolver
.
class
.
getName
(),
HighestTestResolver
.
class
.
getName
()));
ConfigDataLocation
location
=
ConfigDataLocation
.
of
(
"Missing:test"
);
assertThatExceptionOfType
(
UnsupportedConfigDataLocationException
.
class
)
.
isThrownBy
(()
->
resolvers
.
resolve
(
this
.
context
,
location
,
null
,
true
))
.
isThrownBy
(()
->
resolvers
.
resolve
(
this
.
context
,
location
,
null
))
.
satisfies
((
ex
)
->
assertThat
(
ex
.
getLocation
()).
isEqualTo
(
location
));
}
...
...
@@ -173,7 +173,7 @@ class ConfigDataLocationResolversTests {
ConfigDataLocationResolvers
resolvers
=
new
ConfigDataLocationResolvers
(
this
.
logFactory
,
this
.
bootstrapContext
,
this
.
binder
,
this
.
resourceLoader
,
Arrays
.
asList
(
OptionalResourceTestResolver
.
class
.
getName
()));
ConfigDataLocation
location
=
ConfigDataLocation
.
of
(
"OptionalResourceTestResolver:test"
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
null
,
true
);
List
<
ConfigDataResolutionResult
>
resolved
=
resolvers
.
resolve
(
this
.
context
,
location
,
null
);
assertThat
(
resolved
.
get
(
0
).
getResource
().
isOptional
()).
isTrue
();
}
...
...
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