KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.ca.commons.naming;
2
3 import junit.framework.*;
4
5 import javax.naming.InvalidNameException JavaDoc;
6
7
8
9 /**
10  * A class to exercise and test the RDN class
11  */

12
13 public class RDNTest extends TestCase
14 {
15
16     public RDNTest(String JavaDoc name)
17     {
18         super(name);
19     }
20
21     public static Test suite()
22     {
23         return new TestSuite(RDNTest.class);
24     }
25
26     public static void main (String JavaDoc[] args)
27     {
28         junit.textui.TestRunner.run(suite());
29     }
30
31     static final String JavaDoc SMALL_RDN = "l=a";
32     static final String JavaDoc TRIPLE_RDN = "cn=fred+l=a+sn=x";
33     static final String JavaDoc NASTY_RDN = "cn=x\\=y\\+z+l=a\\ +sn=x";
34     static final String JavaDoc SMALL_MULTIVALUED_RDN = "o=o+l=l";
35
36
37     public void testSmallRDN()
38     {
39         RDN stringRDN = new RDN(SMALL_RDN);
40         assertEquals(stringRDN.toString(), SMALL_RDN);
41         assertEquals(stringRDN.getAtt(), "l");
42         assertEquals(stringRDN.getRawVal(), "a");
43
44         System.out.println("RDN " + stringRDN.toString() + " : " + stringRDN.getAtt() + " " + stringRDN.getRawVal() );
45     }
46
47     public void testTripleRDN()
48     {
49         RDN stringRDN = new RDN(TRIPLE_RDN);
50         assertEquals(stringRDN.toString(), TRIPLE_RDN);
51         assertEquals(stringRDN.getAtt(0), "cn");
52         assertEquals(stringRDN.getRawVal(0), "fred");
53         assertEquals(stringRDN.getAtt(1), "l");
54         assertEquals(stringRDN.getRawVal(1), "a");
55         assertEquals(stringRDN.getAtt(2), "sn");
56         assertEquals(stringRDN.getRawVal(2), "x");
57     }
58
59     public void testNastyRDN()
60     {
61         RDN stringRDN = new RDN(NASTY_RDN);
62         assertEquals(stringRDN.toString(), NASTY_RDN);
63         assertEquals(stringRDN.getAtt(0), "cn");
64         assertEquals(stringRDN.getRawVal(0), "x=y+z");
65         assertEquals(stringRDN.getAtt(1), "l");
66         assertEquals(stringRDN.getRawVal(1), "a ");
67         assertEquals(stringRDN.getAtt(2), "sn");
68         assertEquals(stringRDN.getRawVal(2), "x");
69     }
70
71     public void testAddEscaped()
72         throws InvalidNameException JavaDoc
73     {
74         RDN rdn = new RDN("o=o");
75         rdn.addEscaped("l=l");
76         assertEquals(rdn.toString(), SMALL_MULTIVALUED_RDN);
77     }
78
79     public void testAddEscapedFail1()
80     {
81         try
82         {
83             RDN rdn = new RDN("o=o");
84             rdn.addEscaped("l=");
85
86             fail("Should have raised an InvalidNameException");
87         }
88         catch (InvalidNameException JavaDoc success)
89         {
90             //TE: this is what we expect to happen i.e. this indicates a test pass.
91
}
92     }
93
94     public void testAddEscapedFail2()
95     {
96         try
97         {
98             RDN rdn = new RDN("o=o");
99             rdn.addEscaped("=l");
100
101             fail("Should have raised an InvalidNameException");
102         }
103         catch (InvalidNameException JavaDoc success)
104         {
105             //TE: this is what we expect to happen i.e. this indicates a test pass.
106
}
107     }
108
109
110 }
111
Popular Tags