01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.util.location;
18:
19: import java.io.ByteArrayInputStream;
20: import java.io.ByteArrayOutputStream;
21: import java.io.ObjectInputStream;
22: import java.io.ObjectOutputStream;
23:
24: import junit.framework.TestCase;
25:
26: public class LocationTestCase extends TestCase {
27:
28: public LocationTestCase(String name) {
29: super (name);
30: }
31:
32: static final String str = "path/to/file.xml:1:40";
33:
34: public void testParse() throws Exception {
35: String str = "<map:generate> - path/to/file.xml:1:40";
36: Location loc = LocationUtils.parse(str);
37:
38: assertEquals("<map:generate>", loc.getDescription());
39: assertEquals("URI", "path/to/file.xml", loc.getURI());
40: assertEquals("line", 1, loc.getLineNumber());
41: assertEquals("column", 40, loc.getColumnNumber());
42: assertEquals("string representation", str, loc.toString());
43: }
44:
45: public void testEquals() throws Exception {
46: Location loc1 = LocationUtils.parse(str);
47: Location loc2 = new LocationImpl(null, "path/to/file.xml", 1,
48: 40);
49:
50: assertEquals("locations", loc1, loc2);
51: assertEquals("hashcode", loc1.hashCode(), loc2.hashCode());
52: assertEquals("string representation", loc1.toString(), loc2
53: .toString());
54: }
55:
56: /**
57: * Test that Location.UNKNOWN is kept identical on deserialization
58: */
59: public void testSerializeUnknown() throws Exception {
60: ByteArrayOutputStream bos = new ByteArrayOutputStream();
61: ObjectOutputStream oos = new ObjectOutputStream(bos);
62:
63: oos.writeObject(Location.UNKNOWN);
64: oos.close();
65: bos.close();
66:
67: ByteArrayInputStream bis = new ByteArrayInputStream(bos
68: .toByteArray());
69: ObjectInputStream ois = new ObjectInputStream(bis);
70:
71: Object obj = ois.readObject();
72:
73: assertSame("unknown location", Location.UNKNOWN, obj);
74: }
75: }
|