1 8 package com.ca.commons.naming; 9 10 import junit.framework.*; 11 import junit.extensions.*; 12 13 import javax.naming.InvalidNameException ; 14 import javax.naming.Name ; 15 import javax.naming.NamingException ; 16 import java.util.Vector ; 17 import java.util.Enumeration ; 18 19 20 24 public class DNTest extends TestCase 25 { 26 public static final String RDN3Att = "cn"; 27 public static final String RDN2Att = "ou"; 28 public static final String RDN1Att = "o"; 29 public static final String RDN0Att = "c"; 30 31 public static final String RDN3Val = "fred"; 32 public static final String RDN2Val = "\\+research"; 33 public static final String RDN1Val = "x\\=y\\+\\\"z\\\""; 34 public static final String RDN0Val = "af"; 35 36 public static final String RDN3 = RDN3Att + '=' + RDN3Val + "+sn=bloggs"; 37 public static final String RDN2 = RDN2Att + '=' + RDN2Val; 38 public static final String RDN1 = RDN1Att + '=' + RDN1Val; 39 public static final String RDN0 = RDN0Att + '=' + RDN0Val; 40 41 public static final String NODE = "cn=foo\\'tle+sn=snort"; 42 43 public static String bigComplicatedDN = RDN3 + ',' + RDN2 + ',' + RDN1 + ',' + RDN0; 45 public static String anotherComplicatedDN = NODE + ',' + RDN2 + ',' + RDN1 + ',' + RDN0; 46 47 48 public static final String DERDN5Att = "cn"; 49 public static final String DERDN4Att = "ou"; 50 public static final String DERDN3Att = "ou"; 51 public static final String DERDN2Att = "ou"; 52 public static final String DERDN1Att = "o"; 53 public static final String DERDN0Att = "c"; 54 55 public static final String DERDN5Val = "por-p201"; 56 public static final String DERDN4Val = "P 2.01 Koordinierung\\, Controlling\\, Strategische Personalplanung (P 2.01)"; 57 public static final String DERDN3Val = "P 2 Personalbetreuung\\, Stellenwirtschaft"; 58 public static final String DERDN2Val = "Personal- und Organisationsreferat"; 59 public static final String DERDN1Val = "Landeshauptstadt München"; 60 public static final String DERDN0Val = "DE"; 61 62 public static final String DERDN5 = DERDN5Att + '=' + DERDN5Val; 63 public static final String DERDN4 = DERDN4Att + '=' + DERDN4Val; 64 public static final String DERDN3 = DERDN3Att + '=' + DERDN3Val; 65 public static final String DERDN2 = DERDN2Att + '=' + DERDN2Val; 66 public static final String DERDN1 = DERDN1Att + '=' + DERDN1Val; 67 public static final String DERDN0 = DERDN0Att + '=' + DERDN0Val; 68 69 public static String DEbigComplicatedDN = DERDN5 + ',' + DERDN4 + ',' + DERDN3 + ',' + DERDN2 + ',' + DERDN1 + ',' + DERDN0; 70 71 public static final String strangeDN = "cn=\\\"Craig \\\\nLink\\\",ou=Administration,ou=Corporate,o= DEMOCORP,c=AU"; 72 public static final String strangeRDN1 = "cn=\"Craig \\nLink\""; 73 public static final String strangeRDN2 = "ou=Administration"; 74 public static final String strangeRDN3 = "ou=Corporate"; 75 public static final String strangeRDN4 = "o= DEMOCORP"; 76 public static final String strangeRDN5 = "c=AU"; 77 78 public DNTest(String 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 [] 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 131 132 public void testToString() 134 { 135 DN stringDN = new DN(bigComplicatedDN); 136 assertEquals(stringDN.toString(), bigComplicatedDN); 137 } 138 139 public void testGetDN() 140 { 141 testToString(); } 143 144 public void testMakeStrangeDN() 145 throws NamingException 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 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 bigComplicatedDN = RDN3 + ',' + RDN2 + ',' + RDN1 + ',' + RDN0; 268 String reverseDN = RDN0 + ',' + RDN1 + ',' + RDN2 + ',' + RDN3; 269 270 DN testReversal = new DN(bigComplicatedDN); 271 testReversal.reverse(); 272 assertEquals(testReversal.toString(), reverseDN); } 274 275 public void testClear() 276 { 277 DN big = new DN(bigComplicatedDN); 278 big.clear(); 279 assertTrue(big.size()==0); } 281 282 283 284 290 public void testAdd() 291 { 292 assertTrue(true); } 295 296 public void testStringAdd() 297 { 298 assertTrue(true); } 301 302 public void testAddAll() 303 { 304 assertTrue(true); } 307 308 309 312 public void testAddAllName() 313 { 314 assertTrue(true); } 317 318 public void testClone() 319 { 320 assertTrue(true); } 322 323 324 329 public void testCompareTo() 330 { 331 assertTrue(true); } 334 335 336 public void testEndsWith() 337 { 338 assertTrue(true); } 341 342 public void testGet() 343 { 344 assertTrue(true); } 347 348 public void testGetAll() 349 { 350 assertTrue(true); } 353 354 public void testGetPrefix() 355 { 356 assertTrue(true); } 359 360 public void testGetSuffix() 361 { 362 assertTrue(true); } 365 366 public void testIsEmpty() 367 { 368 assertTrue(true); } 371 372 public void testRemove() 373 { 374 assertTrue(true); } 377 378 public void testSize() 379 { 380 assertTrue(true); } 383 384 public void testStartsWithName() 385 { 386 assertTrue(true); } 389 } 390 | Popular Tags |