use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class ResourceEditorTests method testStrictSystemPropertyReplacement.
@Test(expected = IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceEditor(new DefaultResourceLoader(), new StandardEnvironment(), false);
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
} finally {
System.getProperties().remove("test.prop");
}
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class ResourceEditorTests method testSystemPropertyReplacement.
@Test
public void testSystemPropertyReplacement() {
PropertyEditor editor = new ResourceEditor();
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource resolved = (Resource) editor.getValue();
assertEquals("foo-${bar}", resolved.getFilename());
} finally {
System.getProperties().remove("test.prop");
}
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class DataBinderTests method testBindingWithFormatterAgainstFields.
@Test
public void testBindingWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
DefaultConversionService.addDefaultConverters(conversionService);
conversionService.addFormatterForFieldType(Float.class, new NumberStyleFormatter());
binder.setConversionService(conversionService);
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.add("myFloat", "1,2");
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertEquals(new Float(1.2), tb.getMyFloat());
assertEquals("1,2", binder.getBindingResult().getFieldValue("myFloat"));
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertNotNull(editor);
editor.setValue(new Float(1.4));
assertEquals("1,4", editor.getAsText());
editor = binder.getBindingResult().findEditor("myFloat", null);
assertNotNull(editor);
editor.setAsText("1,6");
assertEquals(new Float(1.6), editor.getValue());
} finally {
LocaleContextHolder.resetLocaleContext();
}
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class ResourceArrayPropertyEditorTests method testPatternResource.
@Test
public void testPatternResource() throws Exception {
// N.B. this will sometimes fail if you use classpath: instead of classpath*:.
// The result depends on the classpath - if test-classes are segregated from classes
// and they come first on the classpath (like in Maven) then it breaks, if classes
// comes first (like in Spring Build) then it is OK.
PropertyEditor editor = new ResourceArrayPropertyEditor();
editor.setAsText("classpath*:org/springframework/core/io/support/Resource*Editor.class");
Resource[] resources = (Resource[]) editor.getValue();
assertNotNull(resources);
assertTrue(resources[0].exists());
}
use of java.beans.PropertyEditor in project spring-framework by spring-projects.
the class ResourceArrayPropertyEditorTests method testStrictSystemPropertyReplacement.
@Test(expected = IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
PropertyEditor editor = new ResourceArrayPropertyEditor(new PathMatchingResourcePatternResolver(), new StandardEnvironment(), false);
System.setProperty("test.prop", "foo");
try {
editor.setAsText("${test.prop}-${bar}");
Resource[] resources = (Resource[]) editor.getValue();
assertEquals("foo-${bar}", resources[0].getFilename());
} finally {
System.getProperties().remove("test.prop");
}
}
Aggregations