KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > cache > tests > basic > FqnTest


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

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 JavaDoc;
16
17
18 /**
19  * @author <a HREF="mailto:bela@jboss.org">Bela Ban</a> May 9, 2003
20  * @version $Revision: 1.1.1.1 $
21  */

22 public class FqnTest extends TestCase {
23
24    public FqnTest(String JavaDoc s) {
25       super(s);
26    }
27
28    public void setUp() throws Exception JavaDoc {
29       super.setUp();
30    }
31
32    public void tearDown() throws Exception JavaDoc {
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 JavaDoc(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 JavaDoc[]{"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 JavaDoc[]{"string", new Integer JavaDoc(38), new Boolean JavaDoc(true)});
69       log("fqn is " + fqn);
70       assertEquals(3, fqn.size());
71
72       Fqn fqn2=new Fqn(new Object JavaDoc[]{"string", new Integer JavaDoc(38), new Boolean JavaDoc(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 JavaDoc[]{"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 JavaDoc map=new HashMap JavaDoc();
86       map.put(fqn1, new Integer JavaDoc(33));
87       map.put(fqn2, new Integer JavaDoc(34));
88       assertEquals(1, map.size());
89       assertEquals(new Integer JavaDoc(34), map.get(fqn1));
90    }
91
92    public void testClone() throws CloneNotSupportedException JavaDoc {
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 JavaDoc {
101       Fqn fqn0=new Fqn((Object JavaDoc)null);
102       assertEquals(1, fqn0.size());
103
104       Fqn fqn1=new Fqn(new Object JavaDoc[]{"NULL", null, new Integer JavaDoc(0)});
105       assertEquals(3, fqn1.size());
106
107       Fqn fqn2=new Fqn(new Object JavaDoc[]{"NULL", null, new Integer JavaDoc(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 JavaDoc 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 JavaDoc 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 JavaDoc[] args) {
149       junit.textui.TestRunner.run(suite());
150    }
151
152 }
153
Popular Tags