Source Code Cross Referenced for TestResourceFinderClasspath.java in  » Web-Framework » rife-1.6.1 » com » uwyn » rife » resources » 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 » Web Framework » rife 1.6.1 » com.uwyn.rife.resources 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
003:         * Distributed under the terms of either:
004:         * - the common development and distribution license (CDDL), v1.0; or
005:         * - the GNU Lesser General Public License, v2.1 or later
006:         * $Id: TestResourceFinderClasspath.java 3634 2007-01-08 21:42:24Z gbevin $
007:         */
008:        package com.uwyn.rife.resources;
009:
010:        import com.uwyn.rife.resources.ResourceFinder;
011:        import com.uwyn.rife.resources.ResourceFinderClasspath;
012:        import com.uwyn.rife.resources.exceptions.ResourceFinderErrorException;
013:        import com.uwyn.rife.tools.ExceptionUtils;
014:        import com.uwyn.rife.tools.FileUtils;
015:        import com.uwyn.rife.tools.InnerClassException;
016:        import com.uwyn.rife.tools.InputStreamUser;
017:        import com.uwyn.rife.tools.exceptions.FileUtilsErrorException;
018:        import java.io.InputStream;
019:        import java.net.MalformedURLException;
020:        import java.net.URL;
021:        import junit.framework.TestCase;
022:
023:        public class TestResourceFinderClasspath extends TestCase {
024:            public TestResourceFinderClasspath(String name) {
025:                super (name);
026:            }
027:
028:            public void testInstantiation() {
029:                ResourceFinder resource_finder1 = ResourceFinderClasspath
030:                        .getInstance();
031:                ResourceFinder resource_finder2 = ResourceFinderClasspath
032:                        .getInstance();
033:                assertNotNull(resource_finder1);
034:                assertNotNull(resource_finder2);
035:                assertSame(resource_finder1, resource_finder2);
036:            }
037:
038:            public void testGetUnknownResource() {
039:                ResourceFinder resource_finder = ResourceFinderClasspath
040:                        .getInstance();
041:                assertNull(resource_finder
042:                        .getResource("this/resource/doesnt/exist.txt"));
043:            }
044:
045:            public void testGetResourceByName() {
046:                ResourceFinder resource_finder = ResourceFinderClasspath
047:                        .getInstance();
048:                assertNotNull(resource_finder.getResource("resources/test.txt"));
049:            }
050:
051:            public void testGetUnknownStreamByName() {
052:                ResourceFinder resource_finder = ResourceFinderClasspath
053:                        .getInstance();
054:
055:                try {
056:                    resource_finder.useStream("this/resource/doesnt/exist.txt",
057:                            new InputStreamUser() {
058:                                public Object useInputStream(InputStream stream)
059:                                        throws InnerClassException {
060:                                    assertNull(stream);
061:
062:                                    return null;
063:                                }
064:                            });
065:                } catch (ResourceFinderErrorException e) {
066:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
067:                }
068:            }
069:
070:            public void testGetUnknownStreamByResource() {
071:                ResourceFinder resource_finder = ResourceFinderClasspath
072:                        .getInstance();
073:
074:                try {
075:                    resource_finder.useStream(new URL(
076:                            "file://this/resource/doesnt/exist.txt"),
077:                            new InputStreamUser() {
078:                                public Object useInputStream(InputStream stream)
079:                                        throws InnerClassException {
080:                                    assertNull(stream);
081:
082:                                    return null;
083:                                }
084:                            });
085:                } catch (ResourceFinderErrorException e) {
086:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
087:                } catch (MalformedURLException e) {
088:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
089:                }
090:            }
091:
092:            public void testGetStreamByName() {
093:                ResourceFinder resource_finder = ResourceFinderClasspath
094:                        .getInstance();
095:
096:                try {
097:                    resource_finder.useStream("resources/test.txt",
098:                            new InputStreamUser() {
099:                                public Object useInputStream(InputStream stream)
100:                                        throws InnerClassException {
101:                                    assertNotNull(stream);
102:                                    try {
103:                                        assertEquals(
104:                                                "This just contains some text to\n"
105:                                                        + "verify if\n"
106:                                                        + "\n"
107:                                                        + "resources can be found\n"
108:                                                        + "\n" + "and\n"
109:                                                        + "read\n" + "\n"
110:                                                        + "correctly.\n",
111:                                                FileUtils.readString(stream));
112:                                    } catch (FileUtilsErrorException e) {
113:                                        assertFalse(ExceptionUtils
114:                                                .getExceptionStackTrace(e),
115:                                                false);
116:                                    }
117:                                    return null;
118:                                }
119:                            });
120:                } catch (ResourceFinderErrorException e) {
121:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
122:                }
123:            }
124:
125:            public void testGetStreamByResource() {
126:                ResourceFinder resource_finder = ResourceFinderClasspath
127:                        .getInstance();
128:
129:                URL resource = resource_finder
130:                        .getResource("resources/test.txt");
131:                try {
132:                    resource_finder.useStream(resource, new InputStreamUser() {
133:                        public Object useInputStream(InputStream stream)
134:                                throws InnerClassException {
135:                            assertNotNull(stream);
136:                            try {
137:                                assertEquals(
138:                                        "This just contains some text to\n"
139:                                                + "verify if\n" + "\n"
140:                                                + "resources can be found\n"
141:                                                + "\n" + "and\n" + "read\n"
142:                                                + "\n" + "correctly.\n",
143:                                        FileUtils.readString(stream));
144:                            } catch (FileUtilsErrorException e) {
145:                                assertFalse(ExceptionUtils
146:                                        .getExceptionStackTrace(e), false);
147:                            }
148:                            return null;
149:                        }
150:                    });
151:                } catch (ResourceFinderErrorException e) {
152:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
153:                }
154:            }
155:
156:            public void testGetUnknownContentByName() {
157:                ResourceFinder resource_finder = ResourceFinderClasspath
158:                        .getInstance();
159:
160:                try {
161:                    String content = resource_finder
162:                            .getContent("this/resource/doesnt/exist.txt");
163:                    assertNull(content);
164:                } catch (ResourceFinderErrorException e) {
165:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
166:                }
167:            }
168:
169:            public void testGetUnknownContentByResource() {
170:                ResourceFinder resource_finder = ResourceFinderClasspath
171:                        .getInstance();
172:
173:                try {
174:                    String content = resource_finder.getContent(new URL(
175:                            "file://this/resource/doesnt/exist.txt"));
176:                    assertNull(content);
177:                } catch (ResourceFinderErrorException e) {
178:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
179:                } catch (MalformedURLException e) {
180:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
181:                }
182:            }
183:
184:            public void testGetContentByName() {
185:                ResourceFinder resource_finder = ResourceFinderClasspath
186:                        .getInstance();
187:
188:                try {
189:                    String content = resource_finder
190:                            .getContent("resources/test.txt");
191:                    assertNotNull(content);
192:                    assertEquals(content, "This just contains some text to\n"
193:                            + "verify if\n" + "\n" + "resources can be found\n"
194:                            + "\n" + "and\n" + "read\n" + "\n" + "correctly.\n");
195:                } catch (ResourceFinderErrorException e) {
196:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
197:                }
198:            }
199:
200:            public void testGetContentByResource() {
201:                ResourceFinder resource_finder = ResourceFinderClasspath
202:                        .getInstance();
203:
204:                URL resource = resource_finder
205:                        .getResource("resources/test.txt");
206:                try {
207:                    String content = resource_finder.getContent(resource);
208:                    assertNotNull(content);
209:                    assertEquals(content, "This just contains some text to\n"
210:                            + "verify if\n" + "\n" + "resources can be found\n"
211:                            + "\n" + "and\n" + "read\n" + "\n" + "correctly.\n");
212:                } catch (ResourceFinderErrorException e) {
213:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
214:                }
215:            }
216:
217:            public void testGetContentByNameAndEncoding() {
218:                ResourceFinder resource_finder = ResourceFinderClasspath
219:                        .getInstance();
220:
221:                try {
222:                    String content = resource_finder.getContent(
223:                            "resources/test-utf8.txt", "UTF-8");
224:                    assertNotNull(content);
225:                    assertEquals(
226:                            content,
227:                            "This just contains some text to\n"
228:                                    + "verify if\n"
229:                                    + "\n"
230:                                    + "resources can be found\n"
231:                                    + "\n"
232:                                    + "and\n"
233:                                    + "read\n"
234:                                    + "\n"
235:                                    + "correctly.\n"
236:                                    + "Here are some encoding-specific chars : ¡¢£¤¥¦§¨©ª«¬­®.\n");
237:                } catch (ResourceFinderErrorException e) {
238:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
239:                }
240:            }
241:
242:            public void testGetContentByResourceAndEncoding() {
243:                ResourceFinder resource_finder = ResourceFinderClasspath
244:                        .getInstance();
245:
246:                URL resource = resource_finder
247:                        .getResource("resources/test-utf8.txt");
248:                try {
249:                    String content = resource_finder.getContent(resource,
250:                            "UTF-8");
251:                    assertNotNull(content);
252:                    assertEquals(
253:                            content,
254:                            "This just contains some text to\n"
255:                                    + "verify if\n"
256:                                    + "\n"
257:                                    + "resources can be found\n"
258:                                    + "\n"
259:                                    + "and\n"
260:                                    + "read\n"
261:                                    + "\n"
262:                                    + "correctly.\n"
263:                                    + "Here are some encoding-specific chars : ¡¢£¤¥¦§¨©ª«¬­®.\n");
264:                } catch (ResourceFinderErrorException e) {
265:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
266:                }
267:            }
268:
269:            public void testGetUnknownModificationTimeByName() {
270:                ResourceFinder resource_finder = ResourceFinderClasspath
271:                        .getInstance();
272:
273:                try {
274:                    long time = resource_finder
275:                            .getModificationTime("this/resource/doesnt/exist.txt");
276:                    assertEquals(-1, time);
277:                } catch (ResourceFinderErrorException e) {
278:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
279:                }
280:            }
281:
282:            public void testGetUnknownModificationTimeByResource() {
283:                ResourceFinder resource_finder = ResourceFinderClasspath
284:                        .getInstance();
285:
286:                try {
287:                    long time = resource_finder.getModificationTime(new URL(
288:                            "file://this/resource/doesnt/exist.txt"));
289:                    assertEquals(-1, time);
290:                } catch (ResourceFinderErrorException e) {
291:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
292:                } catch (MalformedURLException e) {
293:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
294:                }
295:            }
296:
297:            public void testGetModificationTimeByName() {
298:                ResourceFinder resource_finder = ResourceFinderClasspath
299:                        .getInstance();
300:
301:                try {
302:                    long time = resource_finder
303:                            .getModificationTime("resources/test.txt");
304:                    assertTrue(time != -1);
305:                } catch (ResourceFinderErrorException e) {
306:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
307:                }
308:            }
309:
310:            public void testGetModificationTimeByResource() {
311:                ResourceFinder resource_finder = ResourceFinderClasspath
312:                        .getInstance();
313:
314:                URL resource = resource_finder
315:                        .getResource("resources/test.txt");
316:                try {
317:                    long time = resource_finder.getModificationTime(resource);
318:                    assertTrue(time != -1);
319:                } catch (ResourceFinderErrorException e) {
320:                    assertFalse(ExceptionUtils.getExceptionStackTrace(e), false);
321:                }
322:            }
323:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.