1 7 package org.jboss.cache.tests.basic; 8 9 10 import junit.framework.Test; 11 import junit.framework.TestCase; 12 import junit.framework.TestSuite; 13 import org.jboss.cache.Fqn; 14 15 import java.util.HashMap ; 16 17 18 22 public class FqnTest extends TestCase { 23 24 public FqnTest(String s) { 25 super(s); 26 } 27 28 public void setUp() throws Exception { 29 super.setUp(); 30 } 31 32 public void tearDown() throws Exception { 33 super.tearDown(); 34 } 35 36 public void testNull() { 37 Fqn fqn=new Fqn(); 38 log("null fqn is " + fqn); 39 assertEquals(0, fqn.size()); 40 } 41 42 public void testOne() { 43 Fqn fqn=new Fqn(new Integer (22)); 44 log("one fqn is " + fqn); 45 assertEquals(1, fqn.size()); 46 } 47 48 public void testEmptyFqn() { 49 Fqn f1=new Fqn(); 50 Fqn f2=new Fqn(); 51 assertEquals(f1, f2); 52 } 53 54 public void testFqn() { 55 Fqn fqn=new Fqn(); 56 fqn.addFqn("/a/b/c"); 57 log("fqn is " + fqn); 58 assertEquals(3, fqn.size()); 59 60 Fqn fqn2=new Fqn(new Object []{"a", "b", "c"}); 61 log("fqn2 is " + fqn2); 62 assertEquals(3, fqn2.size()); 63 assertEquals("fqn should equal fqn2", fqn, fqn2); 64 assertEquals(fqn.hashCode(), fqn2.hashCode()); 65 } 66 67 public void testHereogeneousNames() { 68 Fqn fqn=new Fqn(new Object []{"string", new Integer (38), new Boolean (true)}); 69 log("fqn is " + fqn); 70 assertEquals(3, fqn.size()); 71 72 Fqn fqn2=new Fqn(new Object []{"string", new Integer (38), new Boolean (true)}); 73 assertEquals(fqn, fqn2); 74 assertEquals(fqn.hashCode(), fqn2.hashCode()); 75 } 76 77 public void testHashcode() { 78 Fqn fqn1, fqn2; 79 fqn1=new Fqn(new Object []{"a", "b", "c"}); 80 fqn2=new Fqn(); 81 fqn2.addFqn("/a/b/c"); 82 log("fqn is " + fqn1); 83 assertEquals(fqn1, fqn2); 84 85 HashMap map=new HashMap (); 86 map.put(fqn1, new Integer (33)); 87 map.put(fqn2, new Integer (34)); 88 assertEquals(1, map.size()); 89 assertEquals(new Integer (34), map.get(fqn1)); 90 } 91 92 public void testClone() throws CloneNotSupportedException { 93 Fqn fqn1=new Fqn(); 94 fqn1.addFqn("/a/b/c"); 95 Fqn fqn2=(Fqn)fqn1.clone(); 96 assertEquals(fqn1, fqn2); 97 assertEquals(fqn1.hashCode(), fqn2.hashCode()); 98 } 99 100 public void testNullElements() throws CloneNotSupportedException { 101 Fqn fqn0=new Fqn((Object )null); 102 assertEquals(1, fqn0.size()); 103 104 Fqn fqn1=new Fqn(new Object []{"NULL", null, new Integer (0)}); 105 assertEquals(3, fqn1.size()); 106 107 Fqn fqn2=new Fqn(new Object []{"NULL", null, new Integer (0), }); 108 assertEquals(fqn1.hashCode(), fqn2.hashCode()); 109 assertEquals(fqn1, fqn2); 110 assertEquals(fqn1, fqn1.clone()); 111 } 112 113 public void testIteration() { 114 Fqn fqn=Fqn.fromString("/a/b/c"); 115 assertEquals(3, fqn.size()); 116 Fqn tmp_fqn=new Fqn(); 117 assertEquals(0, tmp_fqn.size()); 118 for(int i=0; i < fqn.size(); i++) { 119 Object obj=fqn.get(i); 120 tmp_fqn=new Fqn(tmp_fqn, obj); 121 assertEquals(tmp_fqn.size(), i+1); 122 } 123 assertEquals(3, tmp_fqn.size()); 124 assertEquals(fqn, tmp_fqn); 125 } 126 127 public void testIsChildOf() { 128 Fqn child=Fqn.fromString("/a/b"); 129 Fqn parent=Fqn.fromString("/a"); 130 assertTrue("Is child of ", child.isChildOf(parent)); 131 assertFalse("Is child of ", parent.isChildOf(child)); 132 133 parent=Fqn.fromString("/a/b/c"); 134 child=Fqn.fromString("/a/b/c/d/e/f/g/h/e/r/e/r/t/tt/"); 135 assertTrue(child.isChildOf(parent)); 136 } 137 138 139 140 void log(String msg) { 141 System.out.println("-- " + msg); 142 } 143 144 public static Test suite() { 145 return new TestSuite(FqnTest.class); 146 } 147 148 public static void main(String [] args) { 149 junit.textui.TestRunner.run(suite()); 150 } 151 152 } 153 | Popular Tags |