KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > commons > naming > DNTest


1 /*
2  * To change template for new class use
3  * Code Style | Class Templates options (Tools | IDE Options).
4  *
5  * User: betch01
6  * Date: 15/05/2002 / 15:45:25
7  */

8 package com.ca.commons.naming;
9
10 import junit.framework.*;
11 import junit.extensions.*;
12
13 import javax.naming.InvalidNameException JavaDoc;
14 import javax.naming.Name JavaDoc;
15 import javax.naming.NamingException JavaDoc;
16 import java.util.Vector JavaDoc;
17 import java.util.Enumeration JavaDoc;
18
19
20 /**
21  * A class to exercise and test the DN class
22  * @author Chris Betts
23  */

24 public class DNTest extends TestCase
25 {
26     public static final String JavaDoc RDN3Att = "cn";
27     public static final String JavaDoc RDN2Att = "ou";
28     public static final String JavaDoc RDN1Att = "o";
29     public static final String JavaDoc RDN0Att = "c";
30
31     public static final String JavaDoc RDN3Val = "fred";
32     public static final String JavaDoc RDN2Val = "\\+research";
33     public static final String JavaDoc RDN1Val = "x\\=y\\+\\\"z\\\"";
34     public static final String JavaDoc RDN0Val = "af";
35
36     public static final String JavaDoc RDN3 = RDN3Att + '=' + RDN3Val + "+sn=bloggs";
37     public static final String JavaDoc RDN2 = RDN2Att + '=' + RDN2Val;
38     public static final String JavaDoc RDN1 = RDN1Att + '=' + RDN1Val;
39     public static final String JavaDoc RDN0 = RDN0Att + '=' + RDN0Val;
40
41     public static final String JavaDoc NODE = "cn=foo\\'tle+sn=snort";
42
43     // should come out as: "cn=fred+sn=bloggs,ou=\\+research,o=x\\=y\\+\\'z\\',c=af";
44
public static String JavaDoc bigComplicatedDN = RDN3 + ',' + RDN2 + ',' + RDN1 + ',' + RDN0;
45     public static String JavaDoc anotherComplicatedDN = NODE + ',' + RDN2 + ',' + RDN1 + ',' + RDN0;
46
47
48     public static final String JavaDoc DERDN5Att = "cn";
49     public static final String JavaDoc DERDN4Att = "ou";
50     public static final String JavaDoc DERDN3Att = "ou";
51     public static final String JavaDoc DERDN2Att = "ou";
52     public static final String JavaDoc DERDN1Att = "o";
53     public static final String JavaDoc DERDN0Att = "c";
54
55     public static final String JavaDoc DERDN5Val = "por-p201";
56     public static final String JavaDoc DERDN4Val = "P 2.01 Koordinierung\\, Controlling\\, Strategische Personalplanung (P 2.01)";
57     public static final String JavaDoc DERDN3Val = "P 2 Personalbetreuung\\, Stellenwirtschaft";
58     public static final String JavaDoc DERDN2Val = "Personal- und Organisationsreferat";
59     public static final String JavaDoc DERDN1Val = "Landeshauptstadt München";
60     public static final String JavaDoc DERDN0Val = "DE";
61
62     public static final String JavaDoc DERDN5 = DERDN5Att + '=' + DERDN5Val;
63     public static final String JavaDoc DERDN4 = DERDN4Att + '=' + DERDN4Val;
64     public static final String JavaDoc DERDN3 = DERDN3Att + '=' + DERDN3Val;
65     public static final String JavaDoc DERDN2 = DERDN2Att + '=' + DERDN2Val;
66     public static final String JavaDoc DERDN1 = DERDN1Att + '=' + DERDN1Val;
67     public static final String JavaDoc DERDN0 = DERDN0Att + '=' + DERDN0Val;
68
69     public static String JavaDoc DEbigComplicatedDN = DERDN5 + ',' + DERDN4 + ',' + DERDN3 + ',' + DERDN2 + ',' + DERDN1 + ',' + DERDN0;
70
71     public static final String JavaDoc strangeDN = "cn=\\\"Craig \\\\nLink\\\",ou=Administration,ou=Corporate,o= DEMOCORP,c=AU";
72     public static final String JavaDoc strangeRDN1 = "cn=\"Craig \\nLink\"";
73     public static final String JavaDoc strangeRDN2 = "ou=Administration";
74     public static final String JavaDoc strangeRDN3 = "ou=Corporate";
75     public static final String JavaDoc strangeRDN4 = "o= DEMOCORP";
76     public static final String JavaDoc strangeRDN5 = "c=AU";
77
78     public DNTest(String JavaDoc name)
79     {
80         super(name);
81     }
82
83     public static Test suite()
84     {
85         return new TestSuite(DNTest.class);
86     }
87
88     public static void main (String JavaDoc[] args)
89     {
90         junit.textui.TestRunner.run(suite());
91     }
92
93     public void testEmptyConstructor()
94     {
95         DN bloop = new DN();
96         assertEquals(bloop.size(), 0);
97     }
98
99     public void testCopyConstructor()
100     {
101
102         DN copyMe = new DN(bigComplicatedDN);
103         DN copy = new DN(copyMe);
104         DN bloop = new DN(copy);
105         assertEquals("dn equality", copyMe, bloop);
106     }
107
108
109     public void testStringConstructor()
110     {
111         DN stringDN = new DN(bigComplicatedDN);
112         assertEquals(stringDN.toString(), bigComplicatedDN);
113     }
114
115     public void testDEStringConstructor()
116     {
117         DN stringDN = new DN(DEbigComplicatedDN);
118         assertEquals(stringDN.toString(), DEbigComplicatedDN);
119         System.out.println(stringDN);
120     }
121
122
123     // this is actually a fair bit of work to test, since it
124
// requires creating a JNDI ldap Name, which is a bitch.
125
/* public void testNameConstructor()
126     {
127         assertTrue(true); // placeholder
128         //DN(Name name)
129     }
130 */

131
132     // Kaff - pretty much the same test as the string constructor.
133
public void testToString()
134     {
135         DN stringDN = new DN(bigComplicatedDN);
136         assertEquals(stringDN.toString(), bigComplicatedDN);
137     }
138
139     public void testGetDN()
140     {
141         testToString(); // deprecated method chains to toString()
142
}
143
144     public void testMakeStrangeDN()
145         throws NamingException JavaDoc
146     {
147         DN testDN = new DN();
148         testDN.add(strangeRDN5);
149         testDN.add(strangeRDN4);
150         testDN.add(strangeRDN3);
151         testDN.add(strangeRDN2);
152
153         RDN testRDN = new RDN();
154         testRDN.addRaw(strangeRDN1);
155         testDN.add(testRDN);
156         assertEquals(testDN.toString(), strangeDN);
157     }
158
159     public void testDEGetRDNAttribute()
160     {
161         DN testDN = new DN(DEbigComplicatedDN);
162         assertEquals(DERDN0Att, testDN.getRDNAttribute(0));
163         assertEquals(DERDN1Att, testDN.getRDNAttribute(1));
164         assertEquals(DERDN2Att, testDN.getRDNAttribute(2));
165         assertEquals(DERDN3Att, testDN.getRDNAttribute(3));
166         assertEquals(DERDN4Att, testDN.getRDNAttribute(4));
167         assertEquals(DERDN5Att, testDN.getRDNAttribute(5));
168         assertEquals("", testDN.getRDNAttribute(6));
169         assertEquals("", testDN.getRDNAttribute(-1));
170     }
171
172
173     public void testGetRDNAttribute()
174     {
175         DN testDN = new DN(bigComplicatedDN);
176         assertEquals(RDN0Att, testDN.getRDNAttribute(0));
177         assertEquals(RDN1Att, testDN.getRDNAttribute(1));
178         assertEquals(RDN2Att, testDN.getRDNAttribute(2));
179         assertEquals(RDN3Att, testDN.getRDNAttribute(3));
180         assertEquals("", testDN.getRDNAttribute(4));
181         assertEquals("", testDN.getRDNAttribute(-1));
182     }
183
184     public void testGetRDNValue()
185     {
186         DN testDN = new DN(bigComplicatedDN);
187
188         try
189         {
190             assertEquals(NameUtility.unescape(RDN0Val), testDN.getRDNValue(0));
191             assertEquals(NameUtility.unescape(RDN1Val), testDN.getRDNValue(1));
192             assertEquals(NameUtility.unescape(RDN2Val), testDN.getRDNValue(2));
193             assertEquals(NameUtility.unescape(RDN3Val), testDN.getRDNValue(3));
194         }
195         catch (InvalidNameException JavaDoc e)
196         {
197             assertTrue(false);
198         }
199
200         assertEquals("", testDN.getRDNValue(4));
201         assertEquals("", testDN.getRDNValue(-1));
202     }
203
204     public void testSetRDN()
205     {
206         DN test = new DN("x=x,x=x,x=x,x=x");
207         test.setRDN(new RDN(RDN0), 0);
208         test.setRDN(new RDN(RDN1), 1);
209         test.setRDN(new RDN(RDN2), 2);
210         test.setRDN(new RDN(RDN3), 3);
211         assertEquals(new DN(bigComplicatedDN), test);
212     }
213
214     public void testGetRDN()
215     {
216         DN test = new DN(bigComplicatedDN);
217         assertEquals(test.getRDN(0), new RDN(RDN0));
218         assertEquals(test.getRDN(1), new RDN(RDN1));
219         assertEquals(test.getRDN(2), new RDN(RDN2));
220         assertEquals(test.getRDN(3), new RDN(RDN3));
221     }
222
223     public void testGetRootRDN()
224     {
225         DN test = new DN(bigComplicatedDN);
226         assertEquals(test.getRootRDN(), new RDN(RDN0));
227         assertEquals(test.getRootRDN(), test.getRDN(0));
228     }
229
230     public void testGetLowestRDN()
231     {
232         DN test = new DN(bigComplicatedDN);
233         assertEquals(test.getLowestRDN(), new RDN(RDN3));
234         assertEquals(test.getLowestRDN(), test.getRDN(3));
235     }
236
237     public void testStartsWith()
238     {
239         DN big = new DN(bigComplicatedDN);
240         DN prefix = new DN(RDN0);
241
242         assertTrue(big.startsWith(prefix));
243
244         prefix.add(new RDN(RDN1));
245         assertTrue(big.startsWith(prefix));
246
247         prefix.add(new RDN(RDN2));
248         assertTrue(big.startsWith(prefix));
249     }
250
251     public void testSharesParent()
252     {
253         DN big = new DN(bigComplicatedDN);
254         DN sibling = new DN(anotherComplicatedDN);
255
256         assertTrue(big.sharesParent(sibling));
257     }
258
259     public void testParentDN()
260     {
261         DN veryLongDN = new DN("cn=new level,"+bigComplicatedDN);
262         assertEquals(veryLongDN.parentDN(), new DN(bigComplicatedDN));
263     }
264
265     public void testReverse()
266     {
267         String JavaDoc bigComplicatedDN = RDN3 + ',' + RDN2 + ',' + RDN1 + ',' + RDN0;
268         String JavaDoc reverseDN = RDN0 + ',' + RDN1 + ',' + RDN2 + ',' + RDN3;
269
270         DN testReversal = new DN(bigComplicatedDN);
271         testReversal.reverse();
272         assertEquals(testReversal.toString(), reverseDN); // placeholder
273
}
274
275     public void testClear()
276     {
277         DN big = new DN(bigComplicatedDN);
278         big.clear();
279         assertTrue(big.size()==0); // placeholder
280
}
281
282
283
284     // NN N A MM MM EEEEEE
285
// NNN N A A M MMM M EE
286
// N NN N A A M M M EEEE (Interface Def.)
287
// N NNN AAAAAAA M M M EE
288
// N NN AA AA M M M EEEEEE
289

290     public void testAdd()
291     {
292         assertTrue(true); // placeholder
293
//Name add(int posn, RDN rdn)
294
}
295
296     public void testStringAdd()
297     {
298         assertTrue(true); // placeholder
299
// public Name add(String rdn)
300
}
301
302     public void testAddAll()
303     {
304         assertTrue(true); // placeholder
305
//public Name addAll(int posn, Name n)
306
}
307
308
309     /*
310      * Adds the components of a name -- in order -- to the end of this name.
311      */

312     public void testAddAllName()
313     {
314         assertTrue(true); // placeholder
315
//public Name addAll(Name suffix)
316
}
317
318     public void testClone()
319     {
320         assertTrue(true); // placeholder
321
}
322
323
324     /*
325      * Compares this name with another name for order.
326      * ... for the time being, ordering is alphabetical by rdns ordered
327      * right to left. Damn but the ldap rdn ordering system is screwed.
328      */

329     public void testCompareTo()
330     {
331         assertTrue(true); // placeholder
332
//public int compareTo(Object obj)
333
}
334
335
336     public void testEndsWith()
337     {
338         assertTrue(true); // placeholder
339
//public boolean endsWith(Name n)
340
}
341
342     public void testGet()
343     {
344         //public String get(int posn)
345
assertTrue(true); // placeholder
346
}
347
348     public void testGetAll()
349     {
350         assertTrue(true); // placeholder
351
//public java.util.Enumeration getAll() // returns en of strings...
352
}
353
354     public void testGetPrefix()
355     {
356         assertTrue(true); // placeholder
357
//public Name getPrefix(int posn)
358
}
359
360     public void testGetSuffix()
361     {
362         assertTrue(true); // placeholder
363
//public Name getSuffix(int posn)
364
}
365
366     public void testIsEmpty()
367     {
368         assertTrue(true); // placeholder
369
//public boolean isEmpty()
370
}
371
372     public void testRemove()
373     {
374         //public Object remove(int posn)
375
assertTrue(true); // placeholder
376
}
377
378     public void testSize()
379     {
380         //public int size()
381
assertTrue(true); // placeholder
382
}
383
384     public void testStartsWithName()
385     {
386         //public boolean startsWith(Name n)
387
assertTrue(true); // placeholder
388
}
389 }
390
Popular Tags