Search in sources :

Example 1 with PropertyEditor

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");
    }
}
Also used : PropertyEditor(java.beans.PropertyEditor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 2 with PropertyEditor

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");
    }
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.Test)

Example 3 with PropertyEditor

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());
}
Also used : Resource(org.springframework.core.io.Resource) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.Test)

Example 4 with PropertyEditor

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");
    }
}
Also used : Resource(org.springframework.core.io.Resource) PropertyEditor(java.beans.PropertyEditor) StandardEnvironment(org.springframework.core.env.StandardEnvironment) Test(org.junit.Test)

Example 5 with PropertyEditor

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

the class ResourceArrayPropertyEditorTests method testSystemPropertyReplacement.

@Test
public void testSystemPropertyReplacement() {
    PropertyEditor editor = new ResourceArrayPropertyEditor();
    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");
    }
}
Also used : Resource(org.springframework.core.io.Resource) PropertyEditor(java.beans.PropertyEditor) Test(org.junit.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