1 4 5 6 package com.ca.commons.naming; 7 8 import junit.framework.*; 9 import javax.naming.NamingException ; 10 11 public class NameUtilityTest extends TestCase 12 { 13 14 private static final String myLdapDN = "\\e6\\90\\ad\\e9\\85\\8d\\e5\\90\\b8\\e6\\94\\b6\\e5\\a4\\96\\e8\\b5\\84"; 15 private static final String myUnicode = "\u642d\u914d\u5438\u6536\u5916\u8d44"; 16 17 private static final String finalSpaceTest = "bloop\\ "; 18 private static final String finalSpaceTestOutcome = "bloop "; 19 private static final String badFinalSpace = "bloop\\"; 20 private static final String badFinalSpaceOutcome = "bloop "; 21 22 private static final String specialCharRDNVal = "jon\\,fred\\+erick (\\\"\\<http:\\\\\\\\www.blarg.com\\>\\\")" ; 23 24 public NameUtilityTest(String 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 [] args) 35 { 36 junit.textui.TestRunner.run(suite()); 37 } 38 39 40 public void testCodec() throws NamingException 41 { 42 String unicode1 = NameUtility.unescape(myLdapDN); 43 assertEquals("testing escaped UTF8 to unicode conversion", unicode1, myUnicode); 44 45 String temp = NameUtility.unescape(specialCharRDNVal); 46 String 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 52 { 53 String 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 |