KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > util > location > LocationTestCase


1 /*
2  * Copyright 2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.util.location;
17
18 import java.io.ByteArrayInputStream JavaDoc;
19 import java.io.ByteArrayOutputStream JavaDoc;
20 import java.io.ObjectInputStream JavaDoc;
21 import java.io.ObjectOutputStream JavaDoc;
22
23 import junit.framework.TestCase;
24
25 public class LocationTestCase extends TestCase {
26     
27     public LocationTestCase(String JavaDoc name) {
28         super(name);
29     }
30     
31     static final String JavaDoc str = "path/to/file.xml:1:40";
32
33     public void testParse() throws Exception JavaDoc {
34         String JavaDoc 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 JavaDoc {
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     /**
54      * Test that Location.UNKNOWN is kept identical on deserialization
55      */

56     public void testSerializeUnknown() throws Exception JavaDoc {
57         ByteArrayOutputStream JavaDoc bos = new ByteArrayOutputStream JavaDoc();
58         ObjectOutputStream JavaDoc oos = new ObjectOutputStream JavaDoc(bos);
59         
60         oos.writeObject(Location.UNKNOWN);
61         oos.close();
62         bos.close();
63         
64         ByteArrayInputStream JavaDoc bis = new ByteArrayInputStream JavaDoc(bos.toByteArray());
65         ObjectInputStream JavaDoc ois = new ObjectInputStream JavaDoc(bis);
66         
67         Object JavaDoc obj = ois.readObject();
68         
69         assertSame("unknown location", Location.UNKNOWN, obj);
70     }
71 }
72
Popular Tags