KickJava   Java API By Example, From Geeks To Geeks.

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


1 /**
2  *
3  */

4
5  
6 package com.ca.commons.naming;
7
8 import junit.framework.*;
9 import javax.naming.NamingException JavaDoc;
10
11 public class NameUtilityTest extends TestCase
12 {
13
14     private static final String JavaDoc myLdapDN = "\\e6\\90\\ad\\e9\\85\\8d\\e5\\90\\b8\\e6\\94\\b6\\e5\\a4\\96\\e8\\b5\\84";
15     private static final String JavaDoc myUnicode = "\u642d\u914d\u5438\u6536\u5916\u8d44";
16
17     private static final String JavaDoc finalSpaceTest = "bloop\\ ";
18     private static final String JavaDoc finalSpaceTestOutcome = "bloop ";
19     private static final String JavaDoc badFinalSpace = "bloop\\";
20     private static final String JavaDoc badFinalSpaceOutcome = "bloop ";
21     
22     private static final String JavaDoc specialCharRDNVal = "jon\\,fred\\+erick (\\\"\\<http:\\\\\\\\www.blarg.com\\>\\\")" ;
23
24     public NameUtilityTest(String JavaDoc name)
25     {
26         super(name);
27     }
28
29     public static Test suite()
30     {
31         return new TestSuite(NameUtilityTest.class);
32     }
33
34     public static void main (String JavaDoc[] args)
35     {
36         junit.textui.TestRunner.run(suite());
37     }
38
39     
40     public void testCodec() throws NamingException JavaDoc
41     {
42         String JavaDoc unicode1 = NameUtility.unescape(myLdapDN);
43         assertEquals("testing escaped UTF8 to unicode conversion", unicode1, myUnicode);
44         
45         String JavaDoc temp = NameUtility.unescape(specialCharRDNVal);
46         String JavaDoc backAgain = NameUtility.escape(temp);
47         
48         assertEquals("testing escaping/unescaping of special rfc 2253 characters", specialCharRDNVal, backAgain);
49     }
50     
51     public void testFinalSpace() throws NamingException JavaDoc
52     {
53         String JavaDoc temp = NameUtility.unescape(finalSpaceTest);
54         assertEquals("Test that a final escaped space is decoded o.k.", finalSpaceTestOutcome, temp);
55
56         temp = NameUtility.escape(temp);
57         assertEquals("Test that a final escaped space is encoded o.k.", finalSpaceTest, temp);
58         
59         temp = NameUtility.unescape(badFinalSpace);
60         assertEquals("Test that a malformed final slash is encoded to a slash and a space", badFinalSpaceOutcome, temp);
61         
62     }
63 }
64
Popular Tags