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
ef1838c7
Commit
ef1838c7
authored
Jul 02, 2015
by
Phillip Webb
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '1.2.x'
parents
b1f8a692
48009bfe
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
80 additions
and
12 deletions
+80
-12
RelaxedDataBinder.java
...java/org/springframework/boot/bind/RelaxedDataBinder.java
+8
-2
PropertiesConfigurationFactoryTests.java
...mework/boot/bind/PropertiesConfigurationFactoryTests.java
+10
-0
RelaxedDataBinderTests.java
...org/springframework/boot/bind/RelaxedDataBinderTests.java
+22
-10
ConfigurationPropertiesBindingPostProcessorTests.java
...ies/ConfigurationPropertiesBindingPostProcessorTests.java
+40
-0
No files found.
spring-boot/src/main/java/org/springframework/boot/bind/RelaxedDataBinder.java
View file @
ef1838c7
...
...
@@ -20,10 +20,12 @@ import java.net.InetAddress;
import
java.util.ArrayList
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.LinkedHashMap
;
import
java.util.LinkedList
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Set
;
import
org.springframework.beans.BeanWrapper
;
import
org.springframework.beans.BeanWrapperImpl
;
...
...
@@ -139,10 +141,14 @@ public class RelaxedDataBinder extends DataBinder {
wrapper
.
setConversionService
(
new
RelaxedConversionService
(
getConversionService
()));
wrapper
.
setAutoGrowNestedPaths
(
true
);
List
<
PropertyValue
>
sortedValues
=
new
ArrayList
<
PropertyValue
>();
Set
<
String
>
modifiedNames
=
new
HashSet
<
String
>();
List
<
String
>
sortedNames
=
getSortedPropertyNames
(
propertyValues
);
for
(
String
name
:
sortedNames
)
{
sortedValues
.
add
(
modifyProperty
(
wrapper
,
propertyValues
.
getPropertyValue
(
name
)));
PropertyValue
propertyValue
=
propertyValues
.
getPropertyValue
(
name
);
PropertyValue
modifiedProperty
=
modifyProperty
(
wrapper
,
propertyValue
);
if
(
modifiedNames
.
add
(
modifiedProperty
.
getName
()))
{
sortedValues
.
add
(
modifiedProperty
);
}
}
return
new
MutablePropertyValues
(
sortedValues
);
}
...
...
spring-boot/src/test/java/org/springframework/boot/bind/PropertiesConfigurationFactoryTests.java
View file @
ef1838c7
...
...
@@ -139,6 +139,8 @@ public class PropertiesConfigurationFactoryTests {
private
String
spring_foo_baz
;
private
String
fooBar
;
public
String
getSpringFooBaz
()
{
return
this
.
spring_foo_baz
;
}
...
...
@@ -163,6 +165,14 @@ public class PropertiesConfigurationFactoryTests {
this
.
bar
=
bar
;
}
public
String
getFooBar
()
{
return
this
.
fooBar
;
}
public
void
setFooBar
(
String
fooBar
)
{
this
.
fooBar
=
fooBar
;
}
}
}
spring-boot/src/test/java/org/springframework/boot/bind/RelaxedDataBinderTests.java
View file @
ef1838c7
...
...
@@ -554,6 +554,18 @@ public class RelaxedDataBinderTests {
assertThat
(
target
.
getFoo
(),
equalTo
(
"b"
));
}
@Test
public
void
testMixed
()
throws
Exception
{
// gh-3385
VanillaTarget
target
=
new
VanillaTarget
();
RelaxedDataBinder
binder
=
getBinder
(
target
,
"test"
);
MutablePropertyValues
values
=
new
MutablePropertyValues
();
values
.
add
(
"test.FOO_BAZ"
,
"boo"
);
values
.
add
(
"test.foo-baz"
,
"bar"
);
binder
.
bind
(
values
);
assertEquals
(
"boo"
,
target
.
getFooBaz
());
}
private
void
doTestBindCaseInsensitiveEnums
(
VanillaTarget
target
)
throws
Exception
{
BindingResult
result
=
bind
(
target
,
"bingo: THIS"
);
assertThat
(
result
.
getErrorCount
(),
equalTo
(
0
));
...
...
@@ -584,16 +596,6 @@ public class RelaxedDataBinderTests {
return
bind
(
target
,
values
,
null
);
}
private
BindingResult
bind
(
DataBinder
binder
,
Object
target
,
String
values
)
throws
Exception
{
Properties
properties
=
PropertiesLoaderUtils
.
loadProperties
(
new
ByteArrayResource
(
values
.
getBytes
()));
binder
.
bind
(
new
MutablePropertyValues
(
properties
));
binder
.
validate
();
return
binder
.
getBindingResult
();
}
private
BindingResult
bind
(
Object
target
,
String
values
,
String
namePrefix
)
throws
Exception
{
return
bind
(
getBinder
(
target
,
namePrefix
),
target
,
values
);
...
...
@@ -609,6 +611,16 @@ public class RelaxedDataBinderTests {
return
binder
;
}
private
BindingResult
bind
(
DataBinder
binder
,
Object
target
,
String
values
)
throws
Exception
{
Properties
properties
=
PropertiesLoaderUtils
.
loadProperties
(
new
ByteArrayResource
(
values
.
getBytes
()));
binder
.
bind
(
new
MutablePropertyValues
(
properties
));
binder
.
validate
();
return
binder
.
getBindingResult
();
}
@Documented
@Target
({
ElementType
.
FIELD
})
@Retention
(
RUNTIME
)
...
...
spring-boot/src/test/java/org/springframework/boot/context/properties/ConfigurationPropertiesBindingPostProcessorTests.java
View file @
ef1838c7
...
...
@@ -236,6 +236,29 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
this
.
context
.
refresh
();
}
@Test
public
void
relaxedPropertyNamesSame
()
throws
Exception
{
this
.
context
=
new
AnnotationConfigApplicationContext
();
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
public
void
relaxedPropertyNamesMixed
()
throws
Exception
{
// gh-3385
this
.
context
=
new
AnnotationConfigApplicationContext
();
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"
));
}
@Configuration
@EnableConfigurationProperties
public
static
class
TestConfigurationWithValidatingSetter
{
...
...
@@ -468,6 +491,23 @@ public class ConfigurationPropertiesBindingPostProcessorTests {
}
@Configuration
@EnableConfigurationProperties
@ConfigurationProperties
(
prefix
=
"test"
)
public
static
class
RelaxedPropertyNames
{
private
String
fooBar
;
public
String
getFooBar
()
{
return
this
.
fooBar
;
}
public
void
setFooBar
(
String
fooBar
)
{
this
.
fooBar
=
fooBar
;
}
}
@SuppressWarnings
(
"rawtypes"
)
// Must be a raw type
static
class
FactoryBeanTester
implements
FactoryBean
,
InitializingBean
{
...
...
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