01: package org.objectweb.celtix.helpers;
02:
03: import junit.framework.TestCase;
04:
05: public class NameSpaceTest extends TestCase {
06:
07: private final String myURL1 = "http://test.objectweb.com/testurl1";
08: private final String myURL2 = "http://test.objectweb.com/testurl2";
09: private final String myCustomURL = "http://test.objectweb.com/custom-prefix-url";
10: private final String myOwnPrefix = "myown-prefix";
11:
12: public NameSpaceTest(String arg0) {
13: super (arg0);
14: }
15:
16: /**
17: * @param args
18: */
19: public static void main(String[] args) {
20: junit.textui.TestRunner.run(NameSpaceTest.class);
21: }
22:
23: public void testNSStackOperations() throws Exception {
24: NSStack nsStackObj = new NSStack();
25:
26: nsStackObj.push();
27:
28: nsStackObj.add(myURL1);
29: nsStackObj.add(myOwnPrefix, myCustomURL);
30: nsStackObj.add(myURL2);
31:
32: assertEquals(myURL1, nsStackObj.getURI("ns1"));
33: assertEquals(myCustomURL, nsStackObj.getURI(myOwnPrefix));
34: assertEquals(myURL2, nsStackObj.getURI("ns2"));
35: assertNull(nsStackObj.getURI("non-existent-prefix"));
36:
37: assertEquals("ns2", nsStackObj.getPrefix(myURL2));
38: assertEquals(myOwnPrefix, nsStackObj.getPrefix(myCustomURL));
39: assertEquals("ns1", nsStackObj.getPrefix(myURL1));
40: assertNull(nsStackObj.getPrefix("non-existent-prefix"));
41:
42: nsStackObj.pop();
43: assertNull(nsStackObj.getPrefix("non-existent-prefix"));
44: assertNull(nsStackObj.getPrefix(myCustomURL));
45: }
46:
47: public void testNSDeclOperaions() throws Exception {
48: NSDecl nsDecl1 = new NSDecl(myOwnPrefix, myCustomURL);
49: NSDecl nsDecl2 = new NSDecl("ns2", myURL2);
50: NSDecl nsDecl3 = new NSDecl(myOwnPrefix, myCustomURL);
51:
52: assertFalse(nsDecl2.equals(nsDecl1));
53: assertTrue(nsDecl3.equals(nsDecl1));
54:
55: }
56: }
|