1 package org.sapia.soto.util; 2 3 import junit.framework.TestCase; 4 5 import java.io.File ; 6 7 8 12 public class UtilsTest extends TestCase { 13 17 public UtilsTest(String arg0) { 18 super(arg0); 19 } 20 21 public void testIsRelativePath() { 22 String path = "/absolute"; 23 super.assertTrue("Path is absolute", !Utils.isRelativePath(path)); 24 path = "relative"; 25 super.assertTrue("Path is relative", Utils.isRelativePath(path)); 26 path = "file:/relative"; 27 super.assertTrue("Path is not relative", !Utils.isRelativePath(path)); 28 path = "./etc/config"; 29 super.assertTrue("Path is not relative", !Utils.isRelativePath(path)); 30 } 31 32 public void testGetRelativePath() { 33 String base = "base"; 34 String path = "relative"; 35 super.assertEquals("base" + File.separator + "relative", 36 Utils.getRelativePath(base, path, false)); 37 38 base = "root/base.xml"; 39 super.assertEquals("root" + File.separator + "relative", 40 Utils.getRelativePath(base, path, true)); 41 42 base = "base"; 43 super.assertEquals("base" + File.separator + "relative", 44 Utils.getRelativePath(base, path, true)); 45 } 46 47 public void testChopLocalUrl() { 48 String path = "resource:/org/sapia/soto\\included.xml"; 49 super.assertEquals("/org/sapia/soto\\included.xml", Utils.chopScheme(path)); 50 } 51 52 public void testChopNetworkUrl() { 53 String path = "http://org/sapia/soto\\included.xml"; 54 super.assertEquals("/org/sapia/soto\\included.xml", Utils.chopScheme(path)); 55 } 56 57 public void testChopRelativePath() { 58 String path = "org/sapia/soto\\included.xml"; 59 super.assertEquals("org/sapia/soto\\included.xml", Utils.chopScheme(path)); 60 } 61 62 public void testChopAbsolutePath() { 63 String path = "/org/sapia/soto\\included.xml"; 64 super.assertEquals("/org/sapia/soto\\included.xml", Utils.chopScheme(path)); 65 } 66 } 67 | Popular Tags |