Search in sources :

Example 6 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testLocaleEditor.

@Test
public void testLocaleEditor() {
    PropertyEditor localeEditor = new LocaleEditor();
    localeEditor.setAsText("en_CA");
    assertEquals(Locale.CANADA, localeEditor.getValue());
    assertEquals("en_CA", localeEditor.getAsText());
    localeEditor = new LocaleEditor();
    assertEquals("", localeEditor.getAsText());
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.Test)

Example 7 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class CustomEditorTests method testClassEditorWithArray.

@Test
public void testClassEditorWithArray() {
    PropertyEditor classEditor = new ClassEditor();
    classEditor.setAsText("org.springframework.tests.sample.beans.TestBean[]");
    assertEquals(TestBean[].class, classEditor.getValue());
    assertEquals("org.springframework.tests.sample.beans.TestBean[]", classEditor.getAsText());
}
Also used : IndexedTestBean(org.springframework.tests.sample.beans.IndexedTestBean) BooleanTestBean(org.springframework.tests.sample.beans.BooleanTestBean) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) NumberTestBean(org.springframework.tests.sample.beans.NumberTestBean) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.Test)

Example 8 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class FileEditorTests method testAbsoluteFileName.

@Test
public void testAbsoluteFileName() throws Exception {
    PropertyEditor fileEditor = new FileEditor();
    fileEditor.setAsText("/no_way_this_file_is_found.doc");
    Object value = fileEditor.getValue();
    assertTrue(value instanceof File);
    File file = (File) value;
    assertTrue(!file.exists());
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.Test)

Example 9 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class FileEditorTests method testWithNonExistentFile.

@Test
public void testWithNonExistentFile() throws Exception {
    PropertyEditor fileEditor = new FileEditor();
    fileEditor.setAsText("file:no_way_this_file_is_found.doc");
    Object value = fileEditor.getValue();
    assertTrue(value instanceof File);
    File file = (File) value;
    assertTrue(!file.exists());
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.Test)

Example 10 with PropertyEditor

use of java.beans.PropertyEditor in project spring-framework by spring-projects.

the class FileEditorTests method testUnqualifiedFileNameFound.

@Test
public void testUnqualifiedFileNameFound() throws Exception {
    PropertyEditor fileEditor = new FileEditor();
    String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class";
    fileEditor.setAsText(fileName);
    Object value = fileEditor.getValue();
    assertTrue(value instanceof File);
    File file = (File) value;
    assertTrue(file.exists());
    String absolutePath = file.getAbsolutePath().replace('\\', '/');
    assertTrue(absolutePath.endsWith(fileName));
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.Test)

Aggregations

PropertyEditor (java.beans.PropertyEditor)96 Test (org.junit.Test)59 TestBean (org.springframework.tests.sample.beans.TestBean)10 File (java.io.File)9 URI (java.net.URI)8 ITestBean (org.springframework.tests.sample.beans.ITestBean)6 IndexedTestBean (org.springframework.tests.sample.beans.IndexedTestBean)6 Path (java.nio.file.Path)5 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 StringArrayPropertyEditor (org.springframework.beans.propertyeditors.StringArrayPropertyEditor)4 IOException (java.io.IOException)3 URL (java.net.URL)3 TypeDescriptor (org.springframework.core.convert.TypeDescriptor)3 Resource (org.springframework.core.io.Resource)3 BooleanTestBean (org.springframework.tests.sample.beans.BooleanTestBean)3 NumberTestBean (org.springframework.tests.sample.beans.NumberTestBean)3 BindStatus (org.springframework.web.servlet.support.BindStatus)3 StringReader (java.io.StringReader)2