Search in sources :

Example 61 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();
    boolean condition = value instanceof File;
    assertThat(condition).isTrue();
    File file = (File) value;
    assertThat(file.exists()).isTrue();
    String absolutePath = file.getAbsolutePath().replace('\\', '/');
    assertThat(absolutePath.endsWith(fileName)).isTrue();
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 62 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();
    boolean condition1 = value instanceof File;
    assertThat(condition1).isTrue();
    File file = (File) value;
    boolean condition = !file.exists();
    assertThat(condition).isTrue();
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 63 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();
    boolean condition1 = value instanceof File;
    assertThat(condition1).isTrue();
    File file = (File) value;
    boolean condition = !file.exists();
    assertThat(condition).isTrue();
}
Also used : PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 64 with PropertyEditor

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

the class PathEditorTests method testAbsolutePath.

@Test
public void testAbsolutePath() {
    PropertyEditor pathEditor = new PathEditor();
    pathEditor.setAsText("/no_way_this_file_is_found.doc");
    Object value = pathEditor.getValue();
    assertThat(value instanceof Path).isTrue();
    Path path = (Path) value;
    assertThat(!path.toFile().exists()).isTrue();
}
Also used : Path(java.nio.file.Path) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.jupiter.api.Test)

Example 65 with PropertyEditor

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

the class PathEditorTests method testUnqualifiedPathNameNotFound.

@Test
public void testUnqualifiedPathNameNotFound() {
    PropertyEditor pathEditor = new PathEditor();
    String fileName = ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".clazz";
    pathEditor.setAsText(fileName);
    Object value = pathEditor.getValue();
    assertThat(value instanceof Path).isTrue();
    Path path = (Path) value;
    File file = path.toFile();
    assertThat(file.exists()).isFalse();
    String absolutePath = file.getAbsolutePath();
    if (File.separatorChar == '\\') {
        absolutePath = absolutePath.replace('\\', '/');
    }
    assertThat(absolutePath.endsWith(fileName)).isTrue();
}
Also used : Path(java.nio.file.Path) PropertyEditor(java.beans.PropertyEditor) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

PropertyEditor (java.beans.PropertyEditor)167 Test (org.junit.jupiter.api.Test)59 HashMap (java.util.HashMap)14 Test (org.junit.Test)13 Map (java.util.Map)11 File (java.io.File)10 URI (java.net.URI)9 TestBean (org.springframework.beans.testfixture.beans.TestBean)9 IOException (java.io.IOException)7 Path (java.nio.file.Path)7 Resource (org.springframework.core.io.Resource)7 Method (java.lang.reflect.Method)6 URL (java.net.URL)6 ITestBean (org.springframework.beans.testfixture.beans.ITestBean)6 IndexedTestBean (org.springframework.beans.testfixture.beans.IndexedTestBean)6 PropertyDescriptor (java.beans.PropertyDescriptor)5 Field (java.lang.reflect.Field)4 ArrayList (java.util.ArrayList)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)4 StringArrayPropertyEditor (org.springframework.beans.propertyeditors.StringArrayPropertyEditor)4