Source Code Cross Referenced for UtilitiesTest.java in  » Wiki-Engine » JAMWiki » org » jamwiki » utils » 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 » Wiki Engine » JAMWiki » org.jamwiki.utils 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
003:         *
004:         * This program is free software; you can redistribute it and/or modify
005:         * it under the terms of the latest version of the GNU Lesser General
006:         * Public License as published by the Free Software Foundation;
007:         *
008:         * This program is distributed in the hope that it will be useful,
009:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
010:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
011:         * GNU Lesser General Public License for more details.
012:         *
013:         * You should have received a copy of the GNU Lesser General Public License
014:         * along with this program (LICENSE.txt); if not, write to the Free Software
015:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
016:         *
017:         * Based on code generated by Agitar build: Agitator Version 1.0.2.000071 (Build date: Jan 12, 2007) [1.0.2.000071]
018:         */package org.jamwiki.utils;
019:
020:        import java.io.FileNotFoundException;
021:        import junit.framework.TestCase;
022:
023:        public class UtilitiesTest extends TestCase {
024:
025:            public void testConvertEncoding1() throws Throwable {
026:                String expected = "ça va là?";
027:                String utf8 = "ça va là?";
028:                /* data utf8 opened as Latin1*/
029:                String result = Utilities.convertEncoding(utf8, "ISO-8859-1",
030:                        "UTF-8");
031:                assertEquals(expected, result);
032:
033:                /* data Latin1 opened as Latin1 */
034:                result = Utilities.convertEncoding(expected, "ISO-8859-1",
035:                        "ISO-8859-1");
036:                assertEquals(expected, result);
037:            }
038:
039:            /**
040:             *
041:             */
042:            public void testDecodeFromRequest() throws Throwable {
043:                String result = Utilities.decodeFromRequest("Page_requested",
044:                        true);
045:                assertEquals("Page requested", result);
046:                result = Utilities.decodeFromRequest("Page_requested", false);
047:                assertEquals("Page_requested", result);
048:            }
049:
050:            /**
051:             *
052:             */
053:            public void testDecodeFromURL() throws Throwable {
054:                String result = Utilities.decodeFromURL("\u1342%20", true);
055:                assertEquals("\u1342 ", result);
056:            }
057:
058:            /**
059:             *
060:             */
061:            public void testEncodeForFilename() throws Throwable {
062:                //TODO
063:                String result = Utilities
064:                        .encodeForFilename("testUtilitiesName");
065:                assertEquals("result", "testUtilitiesName", result);
066:            }
067:
068:            /**
069:             *
070:             */
071:            public void testEncodeForURL() throws Throwable {
072:                //TODO
073:                String result = Utilities.encodeForURL(null);
074:                assertNull("result", result);
075:            }
076:
077:            /**
078:             *
079:             */
080:            public void testExtractTrailingPunctuation() throws Throwable {
081:                String result = Utilities.extractTrailingPunctuation("(");
082:                assertEquals("result", "(", result);
083:            }
084:
085:            /**
086:             *
087:             */
088:            public void testExtractTrailingPunctuation1() throws Throwable {
089:                String result = Utilities.extractTrailingPunctuation("");
090:                assertSame("result", "", result);
091:            }
092:
093:            /**
094:             *
095:             */
096:            public void testExtractTrailingPunctuation2() throws Throwable {
097:                String result = Utilities.extractTrailingPunctuation(".:");
098:                assertEquals("result", ".:", result);
099:            }
100:
101:            /**
102:             *
103:             */
104:            public void testExtractTrailingPunctuation3() throws Throwable {
105:                String result = Utilities.extractTrailingPunctuation("..");
106:                assertEquals("result", "..", result);
107:            }
108:
109:            /**
110:             *
111:             */
112:            public void testExtractTrailingPunctuation4() throws Throwable {
113:                String result = Utilities.extractTrailingPunctuation("\"[");
114:                assertEquals("result", "[", result);
115:            }
116:
117:            /**
118:             *
119:             */
120:            public void testExtractTrailingPunctuation5() throws Throwable {
121:                String result = Utilities
122:                        .extractTrailingPunctuation("2l+.,).,[.");
123:                assertEquals("result", ".,).,[.", result);
124:            }
125:
126:            /**
127:             *
128:             */
129:            public void testExtractTrailingPunctuation6() throws Throwable {
130:                String result = Utilities.extractTrailingPunctuation(":,");
131:                assertEquals("result", ":,", result);
132:            }
133:
134:            /**
135:             *
136:             */
137:            public void testExtractTrailingPunctuation7() throws Throwable {
138:                String result = Utilities.extractTrailingPunctuation(";(");
139:                assertEquals("result", ";(", result);
140:            }
141:
142:            /**
143:             *
144:             */
145:            public void testExtractTrailingPunctuation8() throws Throwable {
146:                String result = Utilities
147:                        .extractTrailingPunctuation(",HyvFb+$[.r.[");
148:                assertEquals("result", ".[", result);
149:            }
150:
151:            /**
152:             *
153:             */
154:            public void testExtractTrailingPunctuation9() throws Throwable {
155:                String result = Utilities.extractTrailingPunctuation("[.");
156:                assertEquals("result", "[.", result);
157:            }
158:
159:            /**
160:             *
161:             */
162:            public void testExtractTrailingPunctuation10() throws Throwable {
163:                String result = Utilities.extractTrailingPunctuation(":");
164:                assertEquals("result", ":", result);
165:            }
166:
167:            /**
168:             *
169:             */
170:            public void testExtractTrailingPunctuation11() throws Throwable {
171:                String result = Utilities
172:                        .extractTrailingPunctuation("8>q/U,p9:r%%/ZU+C0KQBOd,ulNw1X8[UvJ._p,");
173:                assertEquals("result", ",", result);
174:            }
175:
176:            /**
177:             *
178:             */
179:            public void testExtractTrailingPunctuation12() throws Throwable {
180:                String result = Utilities
181:                        .extractTrailingPunctuation("7EoB  L6z\"zUTVA_hPUQ'z|q*zd#;..");
182:                assertEquals("result", ";..", result);
183:            }
184:
185:            /**
186:             *
187:             */
188:            public void testExtractTrailingPunctuation13() throws Throwable {
189:                String result = Utilities
190:                        .extractTrailingPunctuation("A%!2YR?Ols+Lr'6/4;(r4'\";FSG.$T7u<='..;,");
191:                assertEquals("result", "..;,", result);
192:            }
193:
194:            /**
195:             *
196:             */
197:            public void testExtractTrailingPunctuation14() throws Throwable {
198:                String result = Utilities.extractTrailingPunctuation("-^");
199:                assertEquals("result", "", result);
200:            }
201:
202:            /**
203:             *
204:             */
205:            public void testExtractTrailingPunctuation15() throws Throwable {
206:                String result = Utilities.extractTrailingPunctuation(";.");
207:                assertEquals("result", ";.", result);
208:            }
209:
210:            /**
211:             *
212:             */
213:            public void testExtractTrailingPunctuation16() throws Throwable {
214:                String result = Utilities.extractTrailingPunctuation(";[");
215:                assertEquals("result", ";[", result);
216:            }
217:
218:            /**
219:             *
220:             */
221:            public void testExtractTrailingPunctuation17() throws Throwable {
222:                String result = Utilities.extractTrailingPunctuation(";");
223:                assertEquals("result", ";", result);
224:            }
225:
226:            /**
227:             *
228:             */
229:            public void testExtractTrailingPunctuation18() throws Throwable {
230:                String result = Utilities.extractTrailingPunctuation("+]");
231:                assertEquals("result", "]", result);
232:            }
233:
234:            /**
235:             *
236:             */
237:            public void testExtractTrailingPunctuation19() throws Throwable {
238:                String result = Utilities.extractTrailingPunctuation(" ");
239:                assertEquals("result", "", result);
240:            }
241:
242:            /**
243:             *
244:             */
245:            public void testExtractTrailingPunctuation20() throws Throwable {
246:                String result = Utilities
247:                        .extractTrailingPunctuation("h&#U1!&B2xv.");
248:                assertEquals("result", ".", result);
249:            }
250:
251:            /**
252:             *
253:             */
254:            public void testExtractTrailingPunctuation21() throws Throwable {
255:                String result = Utilities.extractTrailingPunctuation(").");
256:                assertEquals("result", ").", result);
257:            }
258:
259:            /**
260:             *
261:             */
262:            public void testExtractTrailingPunctuation22() throws Throwable {
263:                String result = Utilities.extractTrailingPunctuation(",");
264:                assertEquals("result", ",", result);
265:            }
266:
267:            /**
268:             *
269:             */
270:            public void testExtractTrailingPunctuation23() throws Throwable {
271:                String result = Utilities
272:                        .extractTrailingPunctuation(";..:........");
273:                assertEquals("result", ";..:........", result);
274:            }
275:
276:            /**
277:             *
278:             */
279:            public void testExtractTrailingPunctuation24() throws Throwable {
280:                String result = Utilities
281:                        .extractTrailingPunctuation(".1..[,..");
282:                assertEquals("result", "..[,..", result);
283:            }
284:
285:            /**
286:             *
287:             */
288:            public void testExtractTrailingPunctuation25() throws Throwable {
289:                String result = Utilities
290:                        .extractTrailingPunctuation("IT$&,[e;");
291:                assertEquals("result", ";", result);
292:            }
293:
294:            /**
295:             *
296:             */
297:            public void testIsIpAddress() throws Throwable {
298:                //test ipv4 addresses
299:                assertTrue("0.0.0.0", Utilities.isIpAddress("0.0.0.0"));
300:                assertTrue("1.2.3.4", Utilities.isIpAddress("1.2.3.4"));
301:                assertTrue("127.0.0.1", Utilities.isIpAddress("127.0.0.1"));
302:                assertTrue("255.255.255.255", Utilities
303:                        .isIpAddress("255.255.255.255"));
304:                assertTrue("240.0.199.200", Utilities
305:                        .isIpAddress("240.0.199.200"));
306:                assertFalse("too many numbers", Utilities
307:                        .isIpAddress("1.2.3.4.5"));
308:                assertFalse("too many numbers", Utilities
309:                        .isIpAddress("1.2.3.4."));
310:                assertFalse("too few numbers", Utilities.isIpAddress("256.1.1"));
311:                assertFalse("too few numbers", Utilities
312:                        .isIpAddress("256.1.1."));
313:                assertFalse("256 is out of range", Utilities
314:                        .isIpAddress("256.1.1.1"));
315:                assertFalse("letters instead of numbers", Utilities
316:                        .isIpAddress("a.b.c.d"));
317:                assertFalse("extra period", Utilities.isIpAddress("1.2.3..4"));
318:                //test ipv6 addresses
319:                assertTrue("0:0:0:0:0:0:0:0", Utilities
320:                        .isIpAddress("0:0:0:0:0:0:0:0"));
321:                assertTrue("1234:abcd:eFe9:5500:30:a:99aa:5542", Utilities
322:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa:5542"));
323:                assertFalse("too many entries", Utilities
324:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa:0:0"));
325:                assertFalse("too many entries", Utilities
326:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa:0:"));
327:                assertFalse("too few entries", Utilities
328:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa"));
329:                assertFalse("too few entries", Utilities
330:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa:"));
331:                assertFalse("g is out of range", Utilities
332:                        .isIpAddress("123g:abcd:eFe9:5500:30:a:99aa:0"));
333:                assertFalse("% is out of range", Utilities
334:                        .isIpAddress("1234:abcd:eFe9:5500:30:a:99aa:0%"));
335:                assertFalse("extra colon", Utilities
336:                        .isIpAddress("1234::abcd:eFe9:5500:30:a:99aa:0"));
337:                //empty and null
338:                assertFalse("empty string", Utilities.isIpAddress(""));
339:                assertFalse("null string", Utilities.isIpAddress(null));
340:            }
341:
342:            /**
343:             *
344:             */
345:            public void testExtractTrailingPunctuationThrowsNullPointerException()
346:                    throws Throwable {
347:                try {
348:                    Utilities.extractTrailingPunctuation(null);
349:                    fail("Expected NullPointerException to be thrown");
350:                } catch (NullPointerException ex) {
351:                    assertNull("ex.getMessage()", ex.getMessage());
352:                }
353:            }
354:
355:            /**
356:             *
357:             */
358:            public void testFormatMessageThrowsNullPointerException()
359:                    throws Throwable {
360:                try {
361:                    Utilities.formatMessage("testUtilitiesKey", null);
362:                    fail("Expected NullPointerException to be thrown");
363:                } catch (NullPointerException ex) {
364:                    assertNull("ex.getMessage()", ex.getMessage());
365:                }
366:            }
367:
368:            /**
369:             *
370:             */
371:            public void testFormatMessageThrowsNullPointerException1()
372:                    throws Throwable {
373:                Object[] objects = new Object[2];
374:                try {
375:                    Utilities.formatMessage("testUtilitiesKey", null, objects);
376:                    fail("Expected NullPointerException to be thrown");
377:                } catch (NullPointerException ex) {
378:                    assertNull("ex.getMessage()", ex.getMessage());
379:                }
380:            }
381:
382:            /**
383:             *
384:             */
385:            public void testGetClassLoaderFileThrowsException()
386:                    throws Throwable {
387:                try {
388:                    Utilities.getClassLoaderFile("testUtilitiesFilename");
389:                    fail("Expected Exception to be thrown");
390:                } catch (Exception ex) {
391:                    assertEquals("ex.getMessage()",
392:                            "Unable to find testUtilitiesFilename", ex
393:                                    .getMessage());
394:                }
395:            }
396:
397:            /**
398:             *
399:             */
400:            public void testGetClassLoaderFileThrowsNullPointerException()
401:                    throws Throwable {
402:                // FIXME - this seems to give different results on JDK 1.4 and JDK 1.6
403:                //		try {
404:                //			Utilities.getClassLoaderFile(null);
405:                //			fail("Expected NullPointerException to be thrown");
406:                //		} catch (NullPointerException ex) {
407:                //			assertNull("ex.getMessage()", ex.getMessage()); // Adjusted to other NPE
408:                //		}
409:            }
410:
411:            /**
412:             *
413:             */
414:            public void testGetClassLoaderRootThrowsException()
415:                    throws Throwable {
416:                // FIXME
417:                //		try {
418:                //			Utilities.getClassLoaderRoot();
419:                //			fail("Expected Exception to be thrown");
420:                //		} catch (Exception ex) {
421:                //			assertEquals("ex.getMessage()", "Unable to find ApplicationResources.properties", ex.getMessage());
422:                //		}
423:            }
424:
425:            /**
426:             *
427:             */
428:            public void testReadFileThrowsFileNotFoundException()
429:                    throws Throwable {
430:                try {
431:                    Utilities.readFile("fakeFileName");
432:                    fail("Expected FileNotFoundException to be thrown");
433:                } catch (FileNotFoundException ex) {
434:                    assertTrue("Test completed without Exception", true);
435:                    // dependencies on static and environment state led to removal of 2 assertion(s)
436:                }
437:            }
438:
439:            /**
440:             *
441:             */
442:            public void testReadFileThrowsFileNotFoundException1()
443:                    throws Throwable {
444:                try {
445:                    Utilities.readFile("testUtilitiesFilename");
446:                    fail("Expected FileNotFoundException to be thrown");
447:                } catch (FileNotFoundException ex) {
448:                    assertEquals("ex.getClass()", FileNotFoundException.class,
449:                            ex.getClass());
450:                }
451:            }
452:
453:            /**
454:             *
455:             */
456:            public void testReadFileThrowsNullPointerException()
457:                    throws Throwable {
458:                try {
459:                    Utilities.readFile(null);
460:                    fail("Expected NullPointerException to be thrown");
461:                } catch (NullPointerException ex) {
462:                    assertNull("ex.getMessage()", ex.getMessage());
463:                }
464:            }
465:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.