|
1 | 1 | /*
|
2 |
| - * Copyright 2012-2017 the original author or authors. |
| 2 | + * Copyright 2012-2018 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
16 | 16 |
|
17 | 17 | package org.springframework.boot.bind;
|
18 | 18 |
|
| 19 | +import java.io.File; |
19 | 20 | import java.io.IOException;
|
20 | 21 | import java.util.Collections;
|
21 | 22 | import java.util.Properties;
|
|
27 | 28 |
|
28 | 29 | import org.springframework.beans.NotWritablePropertyException;
|
29 | 30 | import org.springframework.boot.context.config.RandomValuePropertySource;
|
| 31 | +import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
30 | 32 | import org.springframework.context.support.StaticMessageSource;
|
| 33 | +import org.springframework.core.convert.support.DefaultConversionService; |
31 | 34 | import org.springframework.core.env.MutablePropertySources;
|
32 | 35 | import org.springframework.core.env.PropertiesPropertySource;
|
33 | 36 | import org.springframework.core.env.StandardEnvironment;
|
@@ -209,6 +212,22 @@ public void propertyWithAllUpperCaseInTheMiddleCanBeBound() throws Exception {
|
209 | 212 | assertThat(foo.fooDLQBar).isEqualTo(("baz"));
|
210 | 213 | }
|
211 | 214 |
|
| 215 | + @Test |
| 216 | + public void currentDirectoryCanBeBoundToFileProperty() throws Exception { |
| 217 | + PropertiesConfigurationFactory<FileProperties> factory = new PropertiesConfigurationFactory<FileProperties>( |
| 218 | + FileProperties.class); |
| 219 | + factory.setApplicationContext(new AnnotationConfigApplicationContext()); |
| 220 | + factory.setConversionService(new DefaultConversionService()); |
| 221 | + Properties properties = PropertiesLoaderUtils |
| 222 | + .loadProperties(new ByteArrayResource("someFile: .".getBytes())); |
| 223 | + MutablePropertySources propertySources = new MutablePropertySources(); |
| 224 | + propertySources.addFirst(new PropertiesPropertySource("test", properties)); |
| 225 | + factory.setPropertySources(propertySources); |
| 226 | + factory.afterPropertiesSet(); |
| 227 | + FileProperties fileProperties = factory.getObject(); |
| 228 | + assertThat(fileProperties.getSomeFile()).isEqualTo(new File(".")); |
| 229 | + } |
| 230 | + |
212 | 231 | private Foo createFoo(final String values) throws Exception {
|
213 | 232 | setupFactory();
|
214 | 233 | return bindFoo(values);
|
@@ -298,4 +317,18 @@ public void setFooDLQBar(String fooDLQBar) {
|
298 | 317 |
|
299 | 318 | }
|
300 | 319 |
|
| 320 | + public static class FileProperties { |
| 321 | + |
| 322 | + private File someFile; |
| 323 | + |
| 324 | + public File getSomeFile() { |
| 325 | + return this.someFile; |
| 326 | + } |
| 327 | + |
| 328 | + public void setSomeFile(File someFile) { |
| 329 | + this.someFile = someFile; |
| 330 | + } |
| 331 | + |
| 332 | + } |
| 333 | + |
301 | 334 | }
|
0 commit comments