|
24 | 24 | import org.junit.Test;
|
25 | 25 | import org.springframework.beans.NotWritablePropertyException;
|
26 | 26 | import org.springframework.context.support.StaticMessageSource;
|
| 27 | +import org.springframework.core.env.MutablePropertySources; |
| 28 | +import org.springframework.core.env.StandardEnvironment; |
27 | 29 | import org.springframework.core.io.ByteArrayResource;
|
28 | 30 | import org.springframework.core.io.support.PropertiesLoaderUtils;
|
| 31 | +import org.springframework.mock.env.MockPropertySource; |
29 | 32 | import org.springframework.validation.BindException;
|
30 | 33 | import org.springframework.validation.Validator;
|
31 | 34 | import org.springframework.validation.beanvalidation.SpringValidatorAdapter;
|
@@ -82,6 +85,37 @@ public void testValidationErrorCanBeSuppressed() throws Exception {
|
82 | 85 | bindFoo("bar: blah");
|
83 | 86 | }
|
84 | 87 |
|
| 88 | + @Test |
| 89 | + public void systemEnvironmentBindingFailuresAreIgnored() throws Exception { |
| 90 | + setupFactory(); |
| 91 | + MutablePropertySources propertySources = new MutablePropertySources(); |
| 92 | + MockPropertySource propertySource = new MockPropertySource( |
| 93 | + StandardEnvironment.SYSTEM_ENVIRONMENT_PROPERTY_SOURCE_NAME); |
| 94 | + propertySource.setProperty("doesNotExist", "foo"); |
| 95 | + propertySource.setProperty("name", "bar"); |
| 96 | + propertySources.addFirst(propertySource); |
| 97 | + this.factory.setPropertySources(propertySources); |
| 98 | + this.factory.setIgnoreUnknownFields(false); |
| 99 | + this.factory.afterPropertiesSet(); |
| 100 | + this.factory.getObject(); |
| 101 | + Foo foo = this.factory.getObject(); |
| 102 | + assertEquals("bar", foo.name); |
| 103 | + } |
| 104 | + |
| 105 | + @Test |
| 106 | + public void systemPropertyBindingFailuresAreIgnored() throws Exception { |
| 107 | + setupFactory(); |
| 108 | + MutablePropertySources propertySources = new MutablePropertySources(); |
| 109 | + MockPropertySource propertySource = new MockPropertySource( |
| 110 | + StandardEnvironment.SYSTEM_PROPERTIES_PROPERTY_SOURCE_NAME); |
| 111 | + propertySource.setProperty("doesNotExist", "foo"); |
| 112 | + propertySource.setProperty("name", "bar"); |
| 113 | + propertySources.addFirst(propertySource); |
| 114 | + this.factory.setPropertySources(propertySources); |
| 115 | + this.factory.setIgnoreUnknownFields(false); |
| 116 | + this.factory.afterPropertiesSet(); |
| 117 | + } |
| 118 | + |
85 | 119 | private Foo createFoo(final String values) throws Exception {
|
86 | 120 | setupFactory();
|
87 | 121 | return bindFoo(values);
|
|
0 commit comments