RESOLVED - issue SPR-6321: Regression: ResourceEditor in 3.0 does not ignore unresolvable placeholders, but it did in 2.5.6

This commit is contained in:
David Syer
2009-11-12 11:07:15 +00:00
parent 7685b516f1
commit 38f1383853
4 changed files with 124 additions and 28 deletions

View File

@@ -16,9 +16,12 @@
package org.springframework.core.io;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.beans.PropertyEditor;
import static org.junit.Assert.*;
import org.junit.Test;
/**
@@ -57,4 +60,33 @@ public final class ResourceEditorTests {
assertEquals("", editor.getAsText());
}
@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");
}
}
@Test(expected=IllegalArgumentException.class)
public void testStrictSystemPropertyReplacement() {
ResourceEditor editor = new ResourceEditor();
editor.setIgnoreUnresolvablePlaceholders(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");
}
}
}

View File

@@ -45,6 +45,24 @@ public class SystemPropertyUtilsTests {
assertEquals("foo", resolved);
}
@Test(expected=IllegalArgumentException.class)
public void testReplaceWithNoDefault() {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}");
assertEquals("", resolved);
}
@Test
public void testReplaceWithNoDefaultIgnored() {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop}", true);
assertEquals("${test.prop}", resolved);
}
@Test
public void testReplaceWithEmptyDefault() {
String resolved = SystemPropertyUtils.resolvePlaceholders("${test.prop:}");
assertEquals("", resolved);
}
@Test
public void testRecursiveFromSystemProperty() {
System.setProperty("test.prop", "foo=${bar}");