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