Source Code Cross Referenced for TestRdnWhiteBoxDevelopment.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jndi » tests » javax » naming » ldap » whitebox » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jndi.tests.javax.naming.ldap.whitebox 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         *  Licensed to the Apache Software Foundation (ASF) under one or more 
003:         *  contributor license agreements.  See the NOTICE file distributed with 
004:         *  this work for additional information regarding copyright ownership. 
005:         *  The ASF licenses this file to You under the Apache License, Version 2.0 
006:         *  (the "License"); you may not use this file except in compliance with 
007:         *  the License.  You may obtain a copy of the License at 
008:         * 
009:         *     http://www.apache.org/licenses/LICENSE-2.0 
010:         * 
011:         *  Unless required by applicable law or agreed to in writing, software 
012:         *  distributed under the License is distributed on an "AS IS" BASIS, 
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
014:         *  See the License for the specific language governing permissions and 
015:         *  limitations under the License. 
016:         */
017:        /**
018:         * @author Hugo Beilis
019:         * @author Leonardo Soler
020:         * @author Gabriel Miretti
021:         * @version 1.0
022:         */package org.apache.harmony.jndi.tests.javax.naming.ldap.whitebox;
023:
024:        import java.util.Arrays;
025:
026:        import javax.naming.InvalidNameException;
027:        import javax.naming.directory.BasicAttributes;
028:        import javax.naming.ldap.Rdn;
029:
030:        import junit.framework.TestCase;
031:
032:        /**
033:         * <p>
034:         * This class test is made to test all cases of package where the coverage was
035:         * not 100%.
036:         * </p>
037:         * <p>
038:         * We are going to find here a lot cases from different classes, notice here that
039:         * the conventional structure followed in the rest of the project is applied
040:         * here.
041:         * </p>
042:         * 
043:         */
044:        public class TestRdnWhiteBoxDevelopment extends TestCase {
045:
046:            public static void main(String[] args) {
047:                junit.textui.TestRunner.run(TestRdnWhiteBoxDevelopment.class);
048:            }
049:
050:            /**
051:             * <p>
052:             * Test method for 'javax.naming.ldap.Rdn.Rdn(String)'
053:             * </p>
054:             * <p>
055:             * Here we are testing if the constructor can receive several multivalued
056:             * types.
057:             * </p>
058:             * <p>
059:             * The expected result is a not null instance.
060:             * </p>
061:             */
062:            public void testRdnString() throws Exception {
063:                new Rdn("test=now+cn=mio+cn=mio2+ou=please+cn=mio3+ou=please2");
064:                new Rdn("cn=mio+ou=please+cn=mio2+cn=mio3");
065:                new Rdn(
066:                        "ou=please+test=now+cn=mio+cn=mio2+ou=please+cn=mio3+ou=please2+nueva=prueba");
067:                new Rdn(
068:                        "au=please+d=d+b=now+cn=mio+cn=mio2+ou=please+cn=mio3+b=please2+na=prueba");
069:                new Rdn("au=#00420ced");
070:                new Rdn("au=\\#00420ced");
071:                new Rdn("t=\\#0FA3TA");
072:                new Rdn("t=\\4CM\\4E+u=Minombre\\40+a=\\4C\\0d");
073:                new Rdn("v=a=a");
074:                new Rdn("v=a=+a=+v=#0D8F");
075:                new Rdn("v=======");
076:                new Rdn("v=<");
077:            }
078:
079:            /**
080:             * <p>
081:             * Test method for 'javax.naming.ldap.Rdn.Rdn(String)'
082:             * </p>
083:             * <p>
084:             * Here we are testing if the constructor can receive the special character
085:             * "\".
086:             * </p>
087:             * <p>
088:             * The expected result is a not null instance.
089:             * </p>
090:             */
091:            public void testQuotedTypeCHECK() {
092:                try {
093:                    // +v=#0D8F";
094:                    new Rdn("v=+a=+\\\\a=");
095:                    fail("Type should not contains quoted chars");
096:                } catch (InvalidNameException e) {
097:                }
098:            }
099:
100:            /**
101:             * <p>
102:             * Test method for 'javax.naming.ldap.Rdn.Rdn(String)'
103:             * </p>
104:             * <p>
105:             * Here we are testing if the constructor can receive the special character
106:             * "+".
107:             * </p>
108:             * <p>
109:             * The expected result is a not null instance.
110:             * </p>
111:             */
112:            public void testIgnoreEndingPlusChar() throws Exception {
113:                Rdn rdn = new Rdn("a=k+");
114:                Rdn rdn2 = new Rdn("a=k");
115:                assertTrue(rdn.equals(rdn2));
116:            }
117:
118:            /**
119:             * <p>
120:             * Test method for 'javax.naming.ldap.Rdn.Rdn(String)'
121:             * </p>
122:             * <p>
123:             * Here we are testing if the constructor can receive the special character
124:             * "#".
125:             * </p>
126:             * <p>
127:             * The expected result is that two rdns must not be the same.
128:             * </p>
129:             */
130:            public void testEquals() throws Exception {
131:                assertNotSame(new Rdn("au=#00420ced"),
132:                        new Rdn("au=\\#00420ced"));
133:            }
134:
135:            /**
136:             * <p>
137:             * Test method for 'javax.naming.ldap.Rdn.equals(Rdn)'
138:             * </p>
139:             * <p>
140:             * Here we are testing if the method can receive a Rdn.
141:             * </p>
142:             * <p>
143:             * The expected result is that two rdns must be the same.
144:             * </p>
145:             */
146:            public void testRDNEqualsCompare() throws Exception {
147:                Rdn rdn = new Rdn(
148:                        "t=test+v=\\4C\\4C+t=test+a=a=a+v=fsdasd+a=<a");
149:                Rdn rdn1 = new Rdn(rdn.toString());
150:                assertTrue(rdn.equals(rdn1));
151:            }
152:
153:            /**
154:             * <p>
155:             * Test method for 'javax.naming.ldap.Rdn.equals(Rdn)'
156:             * </p>
157:             * <p>
158:             * Here we are testing if the method can receive a Rdn.
159:             * </p>
160:             * <p>
161:             * The expected result is that two rdns must be the same.
162:             * </p>
163:             */
164:            public void testRDNequals() throws Exception {
165:                Rdn x1 = new Rdn("t=test");
166:                Rdn x2 = new Rdn(x1);
167:                assertEquals(x1, x2);
168:            }
169:
170:            /**
171:             * <p>
172:             * Test method for 'javax.naming.ldap.Rdn.equals(Rdn)'
173:             * </p>
174:             * <p>
175:             * Here we are testing if the method can receive a Rdn.
176:             * </p>
177:             * <p>
178:             * The expected result is that two rdns must be the same.
179:             * </p>
180:             */
181:            public void testRDNequals2() throws Exception {
182:                Rdn x2 = new Rdn("cn", "#0001");
183:                Rdn x3 = new Rdn("cn", new byte[] { 0, 1 });
184:
185:                assertEquals(x2, x3);
186:            }
187:
188:            /**
189:             * <p>
190:             * Test method for 'javax.naming.ldap.Rdn.equals(Rdn)'
191:             * </p>
192:             * <p>
193:             * Here we are testing if the method can receive a Rdn.
194:             * </p>
195:             * <p>
196:             * The expected result is that two rdns must be the same.
197:             * </p>
198:             */
199:            public void testRDNequals3() throws Exception {
200:                Rdn x1 = null;
201:                Rdn x2 = null;
202:                Rdn x3 = null;
203:                Rdn x4 = null;
204:                Rdn x5 = null;
205:                MyBasicAttributes set = new MyBasicAttributes("cn", new byte[] {
206:                        116, 116, 116 });
207:
208:                x2 = new Rdn("cn=ttt");
209:                x3 = new Rdn("cn", new byte[] { 116, 116, 116 });
210:                x1 = new Rdn(x2);
211:                x4 = new Rdn(set);
212:
213:                assertFalse("Should not be equals.", x3.equals(x2));
214:                assertFalse("Should not be equals.", x1.equals(x3));
215:                assertTrue("Should be equals.", x3.equals(x3));
216:                assertTrue("Should be equals.", x3.equals(x4));
217:
218:                x1 = new Rdn("cn", new byte[] { 11, 116, 11 });
219:                x2 = new Rdn("cn", new byte[] { 116, 116, 116 });
220:                x3 = new Rdn("cn", new byte[] { 116, 116, 116 });
221:                x4 = new Rdn("cn=#30");
222:                x5 = new Rdn("cn", new byte[] { 0 });
223:
224:                assertFalse(x1.equals(x3));
225:                assertTrue(x2.equals(x3));
226:                assertFalse(x5.equals(x4));
227:
228:            }
229:
230:            /**
231:             * <p>
232:             * Test method for 'javax.naming.ldap.Rdn.equals(Rdn)'
233:             * </p>
234:             * <p>
235:             * Here we are testing if the method can receive a Rdn with a different
236:             * array.
237:             * </p>
238:             * <p>
239:             * The expected result is that two rdns must not be the same.
240:             * </p>
241:             */
242:            public final void testEqualsArrays() throws Exception {
243:                Rdn x = new Rdn("t", new byte[] { 01, 00, 02 });
244:                Rdn y = new Rdn("t", new byte[] { 00, 03, 01 });
245:                assertFalse(x.equals(y));
246:            }
247:
248:            /**
249:             * <p>
250:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
251:             * </p>
252:             * <p>
253:             * Here we are testing if this method can escape some values.
254:             * </p>
255:             * <p>
256:             * The expected result is that the method return the string escaped.
257:             * </p>
258:             */
259:            public final void testEscapedValue001() {
260:                assertEquals(
261:                        "t\u00ef\u00bf\u00bda\\, mar\u00ef\u00bf\u00bda",
262:                        Rdn
263:                                .escapeValue("t\u00ef\u00bf\u00bda, mar\u00ef\u00bf\u00bda"));
264:            }
265:
266:            /**
267:             * <p>
268:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
269:             * </p>
270:             * <p>
271:             * Here we are testing if this method can escape some values.
272:             * </p>
273:             * <p>
274:             * The expected result is that the method return the string escaped.
275:             * </p>
276:             */
277:            public final void testEscapedValue002() {
278:                assertEquals("#00420ced", Rdn.escapeValue(new byte[] { 0, 66,
279:                        12, -19 }));
280:            }
281:
282:            /**
283:             * <p>
284:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
285:             * </p>
286:             * <p>
287:             * Here we are testing if this method can escape some values.
288:             * </p>
289:             * <p>
290:             * The expected result is that the method return the string escaped.
291:             * </p>
292:             */
293:            public final void testescapedValue003() {
294:                assertEquals("#fa08", Rdn.escapeValue(new byte[] { -6, 8 }));
295:            }
296:
297:            /**
298:             * <p>
299:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
300:             * </p>
301:             * <p>
302:             * Here we are testing if this method can escape some values.
303:             * </p>
304:             * <p>
305:             * The expected result is that the method return the string escaped.
306:             * </p>
307:             */
308:            public final void testEscapedValue004() {
309:                assertEquals(
310:                        "t\u00ef\u00bf\u00bda\\, mar\u00ef\u00bf\u00bda \\#\\,sobrante\\>\\<",
311:                        Rdn
312:                                .escapeValue("t\u00ef\u00bf\u00bda, mar\u00ef\u00bf\u00bda #,sobrante><"));
313:            }
314:
315:            /**
316:             * <p>
317:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
318:             * </p>
319:             * <p>
320:             * Here we are testing if this method can escape some values.
321:             * </p>
322:             * <p>
323:             * The expected result is that the method return the string escaped.
324:             * </p>
325:             */
326:            public final void testEscapedValue005() {
327:                assertEquals(
328:                        "t\u00ef\u00bf\u00bda\\, mar\u00ef\u00bf\u00bda \\#\\,sobrante\\>\\<",
329:                        Rdn
330:                                .escapeValue("t\u00ef\u00bf\u00bda, mar\u00ef\u00bf\u00bda #,sobrante><"));
331:            }
332:
333:            /**
334:             * <p>
335:             * Test method for 'javax.naming.ldap.Rdn.toString()'
336:             * </p>
337:             * <p>
338:             * Here we are testing if this method returns the correct string.
339:             * </p>
340:             */
341:            public void testToString001() throws Exception {
342:                String t = "t=test+v=value+t=test2+v=value2";
343:                Rdn rdn = new Rdn(t);
344:                assertEquals("t=test+t=test2+v=value+v=value2", rdn.toString());
345:            }
346:
347:            /**
348:             * <p>
349:             * Test method for 'javax.naming.ldap.Rdn.toString()'
350:             * </p>
351:             * <p>
352:             * Here we are testing if this method returns the correct string.
353:             * </p>
354:             */
355:            public void testToString002() throws Exception {
356:                String t = "SN=Lu\\C4\\8Di\\C4\\87";
357:                Rdn rdn = new Rdn(t);
358:                assertEquals(8, rdn.toString().length());
359:            }
360:
361:            /**
362:             * <p>
363:             * Test method for 'javax.naming.ldap.Rdn.toString()'
364:             * </p>
365:             * <p>
366:             * Here we are testing if this method returns the correct string.
367:             * </p>
368:             */
369:            public void testToString003() throws Exception {
370:                String t = "v=#080100";
371:                Rdn rdn = new Rdn("v", new byte[] { 8, 01, 0 });
372:                assertEquals(t, rdn.toString());
373:            }
374:
375:            /**
376:             * <p>
377:             * Test method for 'javax.naming.ldap.Rdn.toString()'
378:             * </p>
379:             * <p>
380:             * Here we are testing if this method returns the correct string.
381:             * </p>
382:             */
383:            public void testToString004() throws Exception {
384:                Rdn rdn = new Rdn("v", " ");
385:                assertFalse("v=\\ " == rdn.toString());
386:            }
387:
388:            /**
389:             * <p>
390:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
391:             * </p>
392:             * <p>
393:             * Here we are testing if this method can escape some values.
394:             * </p>
395:             * <p>
396:             * The expected result is that the method return the string escaped.
397:             * </p>
398:             */
399:            public void testUnescapedValue001() {
400:                assertEquals(Arrays.toString(new byte[] { -6, 8 }), Arrays
401:                        .toString((byte[]) Rdn.unescapeValue("#fa08")));
402:            }
403:
404:            /**
405:             * <p>
406:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
407:             * </p>
408:             * <p>
409:             * Here we are testing if this method can escape some values.
410:             * </p>
411:             * <p>
412:             * The expected result is that the method return the string escaped.
413:             * </p>
414:             */
415:            public void testUnescapedValue002() {
416:                try {
417:                    Rdn.unescapeValue("##fa08");
418:                    fail("An exception must be thrown.");
419:                } catch (IllegalArgumentException e) {
420:                }
421:            }
422:
423:            /**
424:             * <p>
425:             * Test method for 'javax.naming.ldap.Rdn.escapedValue(Object)'
426:             * </p>
427:             * <p>
428:             * Here we are testing if this method can escape some values.
429:             * </p>
430:             * <p>
431:             * The expected result is that the method return the string escaped.
432:             * </p>
433:             */
434:            public void testUnescapedValue003() {
435:                assertEquals("t=LMN+u=Minombre@+a=L", Rdn
436:                        .unescapeValue("t=\\4CM\\4E+u=Minombre\\40+a=\\4C"));
437:            }
438:
439:            /**
440:             * <p>
441:             * Test method for 'javax.naming.ldap.Rdn.hashCode()'
442:             * </p>
443:             * <p>
444:             * Here we are testing if this method return the hash of an object distinct
445:             * in the value of a string.
446:             * </p>
447:             */
448:            public void testHashCode() throws Exception {
449:                Rdn x = new Rdn("t", new byte[] { 01, 00, 02 });
450:                assertNotNull(x);
451:                assertNotSame(0, x.hashCode());
452:            }
453:
454:            /**
455:             * <p>
456:             * Test method for 'javax.naming.ldap.Rdn.getValue()'
457:             * </p>
458:             * <p>
459:             * Here we are testing if this method retrieves one of this Rdn's value. In
460:             * this case should raise an exception because the rdn is empty.
461:             * </p>
462:             * <p>
463:             * The expected result is an exception.
464:             * </p>
465:             */
466:            public void testGetValue001() throws Exception {
467:                new Rdn("t", " ").getValue();
468:            }
469:
470:            /**
471:             * <p>
472:             * Test method to test if the constructor take literally what is between
473:             * '"'.
474:             * </p>
475:             * 
476:             */
477:            public void testRDNComillas() throws Exception {
478:                Rdn x2 = new Rdn("cn", "\"mio\"");
479:                Rdn x3 = new Rdn("cn", "\"mio\"");
480:                assertTrue("Should be equals.", x2.equals(x3));
481:            }
482:
483:            /**
484:             * <p>
485:             * Test method to test if the constructor take literally what is between
486:             * '"'.
487:             * </p>
488:             * 
489:             */
490:            public void testRDNComillas2() throws Exception {
491:                Rdn x2 = null;
492:                String temp = "cn=mio\\,zapato\\,veloz\\;\\\" \\#";
493:                x2 = new Rdn("cn=\"mio,zapato,veloz;\\\" \\#\"");
494:                assertEquals(0, temp.compareToIgnoreCase(x2.toString()));
495:            }
496:
497:            /**
498:             * <p>
499:             * Test method to test if the constructor can receive the correct length to a
500:             * byte array.
501:             * </p>
502:             * 
503:             */
504:            public void testRDNWrongHexValue() {
505:                try {
506:                    new Rdn("cn=#A");
507:                    fail();
508:                } catch (InvalidNameException e) {
509:                } catch (IllegalArgumentException e) {
510:                }
511:            }
512:
513:            /**
514:             * Here we are testing to send the escaped special characters and utf8.
515:             * 
516:             */
517:            public void testRdnEscapeValue() throws Exception {
518:                new Rdn("cn=\\;\\\"");
519:                new Rdn("cn=\\<\\>");
520:                new Rdn("cn=\\<\\>\\\\");
521:                new Rdn("cn=\\<\\>\\=");
522:                new Rdn("cn=\\<\\>\"\\+\"");
523:                new Rdn("cn=\\<\\>\\4C");
524:                new Rdn("cn=\\<\\>\\ ");
525:            }
526:
527:            /*
528:             * Class to help us to do the white box.
529:             */
530:            private class MyBasicAttributes extends BasicAttributes {
531:
532:                private static final long serialVersionUID = 1L;
533:
534:                private Object myo;
535:
536:                MyBasicAttributes(String x, Object o) {
537:                    super (x, o);
538:                    this .myo = o;
539:                }
540:
541:                public Object getValue() {
542:                    return myo;
543:                }
544:            }
545:
546:        }
w___w___w_.__j___a_v_a_2s__.co__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.