Search in sources :

Example 16 with PropertyEditor

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

the class URIEditorTests method standardURLWithWhitespace.

@Test
public void standardURLWithWhitespace() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("  http://www.springframework.org  ");
    Object value = uriEditor.getValue();
    assertTrue(value instanceof URI);
    URI uri = (URI) value;
    assertEquals("http://www.springframework.org", uri.toString());
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.Test)

Example 17 with PropertyEditor

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

the class URIEditorTests method encodeURI.

@Test
public void encodeURI() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("http://example.com/spaces and €");
    Object value = uriEditor.getValue();
    assertTrue(value instanceof URI);
    URI uri = (URI) value;
    assertEquals(uri.toString(), uriEditor.getAsText());
    assertEquals("http://example.com/spaces%20and%20%E2%82%AC", uri.toASCIIString());
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.Test)

Example 18 with PropertyEditor

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

the class URIEditorTests method classpathURLWithWhitespace.

@Test
public void classpathURLWithWhitespace() throws Exception {
    PropertyEditor uriEditor = new URIEditor(getClass().getClassLoader());
    uriEditor.setAsText("  classpath:" + ClassUtils.classPackageAsResourcePath(getClass()) + "/" + ClassUtils.getShortName(getClass()) + ".class  ");
    Object value = uriEditor.getValue();
    assertTrue(value instanceof URI);
    URI uri = (URI) value;
    assertEquals(uri.toString(), uriEditor.getAsText());
    assertTrue(!uri.getScheme().startsWith("classpath"));
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) Test(org.junit.Test)

Example 19 with PropertyEditor

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

the class URIEditorTests method getAsTextReturnsEmptyStringIfValueNotSet.

@Test
public void getAsTextReturnsEmptyStringIfValueNotSet() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    assertEquals("", uriEditor.getAsText());
}
Also used : PropertyEditor(java.beans.PropertyEditor) Test(org.junit.Test)

Example 20 with PropertyEditor

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

the class URIEditorTests method classpathURLAsIs.

@Test
public void classpathURLAsIs() throws Exception {
    PropertyEditor uriEditor = new URIEditor();
    uriEditor.setAsText("classpath:test.txt");
    Object value = uriEditor.getValue();
    assertTrue(value instanceof URI);
    URI uri = (URI) value;
    assertEquals(uri.toString(), uriEditor.getAsText());
    assertTrue(uri.getScheme().startsWith("classpath"));
}
Also used : PropertyEditor(java.beans.PropertyEditor) URI(java.net.URI) 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