1 42 43 package org.jfree.io.junit; 44 45 import java.io.IOException ; 46 import java.net.URL ; 47 48 import junit.framework.Test; 49 import junit.framework.TestCase; 50 import junit.framework.TestSuite; 51 52 import org.jfree.io.IOUtils; 53 54 57 public class IOUtilsTests extends TestCase { 58 59 64 public static Test suite() { 65 return new TestSuite(IOUtilsTests.class); 66 } 67 68 71 public IOUtilsTests() { 72 super(); 73 } 74 75 80 public IOUtilsTests(final String name) { 81 super(name); 82 } 83 84 89 public void testCreateRelativeURL() throws IOException { 90 final URL baseurl = new URL 91 ("http://test.com:80/test/a/funny/directory/basefile.xml"); 92 93 final URL testInput1 = new URL ("http://test.com:80/test/a/funny/directory/datafile.jpg"); 94 String result = IOUtils.getInstance().createRelativeURL(testInput1, baseurl); 95 assertEquals("datafile.jpg", result); 96 assertEquals(testInput1, new URL (baseurl, result)); 97 98 final URL testInput2 = new URL ("http://test.com:80/test/adatafile.jpg"); 99 result = IOUtils.getInstance().createRelativeURL(testInput2, baseurl); 100 assertEquals("../../../adatafile.jpg", result); 101 assertEquals(testInput2, new URL (baseurl, result)); 102 103 final URL testInput3 = new URL ("http://test.com:80/test/adatafile.jpg?query=test"); 104 result = IOUtils.getInstance().createRelativeURL(testInput3, baseurl); 105 assertEquals("../../../adatafile.jpg?query=test", result); 106 assertEquals(testInput3, new URL (baseurl, result)); 107 } 108 109 } 110 | Popular Tags |