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
954d1372
Commit
954d1372
authored
Oct 28, 2015
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce code duplication
parent
1173f771
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
51 deletions
+22
-51
ConfigurationPropertiesBindingPostProcessorTests.java
...ies/ConfigurationPropertiesBindingPostProcessorTests.java
+22
-51
No files found.
spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java
View file @
954d1372
...
@@ -78,14 +78,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -78,14 +78,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.foo:spam"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.foo:spam"
);
this
.
context
.
register
(
TestConfigurationWithValidatingSetter
.
class
);
this
.
context
.
register
(
TestConfigurationWithValidatingSetter
.
class
);
try
{
assertBindingFailure
(
1
);
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
1
,
bex
.
getErrorCount
());
}
}
}
@Test
@Test
...
@@ -110,28 +103,14 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -110,28 +103,14 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
public
void
testValidationWithoutJSR303
()
{
public
void
testValidationWithoutJSR303
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
TestConfigurationWithoutJSR303
.
class
);
this
.
context
.
register
(
TestConfigurationWithoutJSR303
.
class
);
try
{
assertBindingFailure
(
1
);
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
1
,
bex
.
getErrorCount
());
}
}
}
@Test
@Test
public
void
testValidationWithJSR303
()
{
public
void
testValidationWithJSR303
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
TestConfigurationWithJSR303
.
class
);
this
.
context
.
register
(
TestConfigurationWithJSR303
.
class
);
try
{
assertBindingFailure
(
2
);
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
2
,
bex
.
getErrorCount
());
}
}
}
@Test
@Test
...
@@ -159,14 +138,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -159,14 +138,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
public
void
testValidationWithCustomValidator
()
{
public
void
testValidationWithCustomValidator
()
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
.
register
(
TestConfigurationWithCustomValidator
.
class
);
this
.
context
.
register
(
TestConfigurationWithCustomValidator
.
class
);
try
{
assertBindingFailure
(
1
);
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
1
,
bex
.
getErrorCount
());
}
}
}
@Test
@Test
...
@@ -177,15 +149,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -177,15 +149,7 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
setEnvironment
(
env
);
this
.
context
.
register
(
TestConfigurationWithCustomValidator
.
class
,
this
.
context
.
register
(
TestConfigurationWithCustomValidator
.
class
,
PropertyWithValidatingSetter
.
class
);
PropertyWithValidatingSetter
.
class
);
try
{
assertBindingFailure
(
1
);
// PropertyWithValidatingSetter should not use validator
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
1
,
bex
.
getErrorCount
());
}
}
}
@Test
@Test
...
@@ -294,21 +258,17 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -294,21 +258,17 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
@Test
@Test
public
void
relaxedPropertyNamesSame
()
throws
Exception
{
public
void
relaxedPropertyNamesSame
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
testRelaxedPropertyNames
(
"test.FOO_BAR:test1"
,
"test.FOO_BAR:test2"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.FOO_BAR:test1"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.FOO_BAR:test2"
);
this
.
context
.
register
(
RelaxedPropertyNames
.
class
);
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
RelaxedPropertyNames
.
class
).
getFooBar
(),
equalTo
(
"test2"
));
}
}
@Test
@Test
public
void
relaxedPropertyNamesMixed
()
throws
Exception
{
public
void
relaxedPropertyNamesMixed
()
throws
Exception
{
// gh-3385
testRelaxedPropertyNames
(
"test.foo-bar:test1"
,
"test.FOO_BAR:test2"
);
}
private
void
testRelaxedPropertyNames
(
String
...
environment
)
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
this
.
context
=
new
AnnotationConfigApplicationContext
();
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.foo-bar:test1"
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
environment
);
EnvironmentTestUtils
.
addEnvironment
(
this
.
context
,
"test.FOO_BAR:test2"
);
this
.
context
.
register
(
RelaxedPropertyNames
.
class
);
this
.
context
.
register
(
RelaxedPropertyNames
.
class
);
this
.
context
.
refresh
();
this
.
context
.
refresh
();
assertThat
(
this
.
context
.
getBean
(
RelaxedPropertyNames
.
class
).
getFooBar
(),
assertThat
(
this
.
context
.
getBean
(
RelaxedPropertyNames
.
class
).
getFooBar
(),
...
@@ -326,6 +286,17 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
...
@@ -326,6 +286,17 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
.
getValue
(),
equalTo
(
"test1"
));
.
getValue
(),
equalTo
(
"test1"
));
}
}
private
void
assertBindingFailure
(
int
errorCount
)
{
try
{
this
.
context
.
refresh
();
fail
(
"Expected exception"
);
}
catch
(
BeanCreationException
ex
)
{
BindException
bex
=
(
BindException
)
ex
.
getRootCause
();
assertEquals
(
errorCount
,
bex
.
getErrorCount
());
}
}
@Configuration
@Configuration
@EnableConfigurationProperties
@EnableConfigurationProperties
public
static
class
TestConfigurationWithValidatingSetter
{
public
static
class
TestConfigurationWithValidatingSetter
{
...
...
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