1 16 package org.apache.cocoon.util.location; 17 18 import java.io.ByteArrayInputStream ; 19 import java.io.ByteArrayOutputStream ; 20 import java.io.ObjectInputStream ; 21 import java.io.ObjectOutputStream ; 22 23 import junit.framework.TestCase; 24 25 public class LocationTestCase extends TestCase { 26 27 public LocationTestCase(String name) { 28 super(name); 29 } 30 31 static final String str = "path/to/file.xml:1:40"; 32 33 public void testParse() throws Exception { 34 String str = "<map:generate> - path/to/file.xml:1:40"; 35 Location loc = LocationUtils.parse(str); 36 37 assertEquals("<map:generate>", loc.getDescription()); 38 assertEquals("URI", "path/to/file.xml", loc.getURI()); 39 assertEquals("line", 1, loc.getLineNumber()); 40 assertEquals("column", 40, loc.getColumnNumber()); 41 assertEquals("string representation", str, loc.toString()); 42 } 43 44 public void testEquals() throws Exception { 45 Location loc1 = LocationUtils.parse(str); 46 Location loc2 = new LocationImpl(null, "path/to/file.xml", 1, 40); 47 48 assertEquals("locations", loc1, loc2); 49 assertEquals("hashcode", loc1.hashCode(), loc2.hashCode()); 50 assertEquals("string representation", loc1.toString(), loc2.toString()); 51 } 52 53 56 public void testSerializeUnknown() throws Exception { 57 ByteArrayOutputStream bos = new ByteArrayOutputStream (); 58 ObjectOutputStream oos = new ObjectOutputStream (bos); 59 60 oos.writeObject(Location.UNKNOWN); 61 oos.close(); 62 bos.close(); 63 64 ByteArrayInputStream bis = new ByteArrayInputStream (bos.toByteArray()); 65 ObjectInputStream ois = new ObjectInputStream (bis); 66 67 Object obj = ois.readObject(); 68 69 assertSame("unknown location", Location.UNKNOWN, obj); 70 } 71 } 72 | Popular Tags |