Source Code Cross Referenced for BasicAttachmentProviderTest.java in  » Wiki-Engine » JSPWiki » com » ecyrd » jspwiki » providers » 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 » JSPWiki » com.ecyrd.jspwiki.providers 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package com.ecyrd.jspwiki.providers;
002:
003:        import junit.framework.*;
004:        import java.io.*;
005:        import java.util.*;
006:
007:        import com.ecyrd.jspwiki.*;
008:        import com.ecyrd.jspwiki.attachment.*;
009:
010:        public class BasicAttachmentProviderTest extends TestCase {
011:            public static final String NAME1 = "TestPage";
012:            public static final String NAME2 = "TestPageToo";
013:
014:            Properties props = new Properties();
015:
016:            TestEngine m_engine;
017:
018:            BasicAttachmentProvider m_provider;
019:
020:            /**
021:             *  This is the sound of my head hitting the keyboard.
022:             */
023:            private static final String c_fileContents = "gy th tgyhgthygyth tgyfgftrfgvtgfgtr";
024:
025:            public BasicAttachmentProviderTest(String s) {
026:                super (s);
027:            }
028:
029:            public void setUp() throws Exception {
030:                props.load(TestEngine.findTestProperties());
031:
032:                m_engine = new TestEngine(props);
033:
034:                m_provider = new BasicAttachmentProvider();
035:                m_provider.initialize(m_engine, props);
036:
037:                m_engine.saveText(NAME1, "Foobar");
038:                m_engine.saveText(NAME2, "Foobar2");
039:            }
040:
041:            private File makeAttachmentFile() throws Exception {
042:                File tmpFile = File.createTempFile("test", "txt");
043:                tmpFile.deleteOnExit();
044:
045:                FileWriter out = new FileWriter(tmpFile);
046:
047:                FileUtil.copyContents(new StringReader(c_fileContents), out);
048:
049:                out.close();
050:
051:                return tmpFile;
052:            }
053:
054:            private File makeExtraFile(File directory, String name)
055:                    throws Exception {
056:                File tmpFile = new File(directory, name);
057:                FileWriter out = new FileWriter(tmpFile);
058:
059:                FileUtil.copyContents(new StringReader(c_fileContents), out);
060:
061:                out.close();
062:
063:                return tmpFile;
064:            }
065:
066:            public void tearDown() {
067:                TestEngine.deleteTestPage(NAME1);
068:                TestEngine.deleteTestPage(NAME2);
069:
070:                String tmpfiles = props
071:                        .getProperty(BasicAttachmentProvider.PROP_STORAGEDIR);
072:
073:                File f = new File(tmpfiles, NAME1
074:                        + BasicAttachmentProvider.DIR_EXTENSION);
075:
076:                TestEngine.deleteAll(f);
077:
078:                f = new File(tmpfiles, NAME2
079:                        + BasicAttachmentProvider.DIR_EXTENSION);
080:
081:                TestEngine.deleteAll(f);
082:
083:                TestEngine.emptyWorkDir();
084:            }
085:
086:            public void testExtension() {
087:                String s = "test.png";
088:
089:                assertEquals(BasicAttachmentProvider.getFileExtension(s), "png");
090:            }
091:
092:            public void testExtension2() {
093:                String s = ".foo";
094:
095:                assertEquals("foo", BasicAttachmentProvider.getFileExtension(s));
096:            }
097:
098:            public void testExtension3() {
099:                String s = "test.png.3";
100:
101:                assertEquals("3", BasicAttachmentProvider.getFileExtension(s));
102:            }
103:
104:            public void testExtension4() {
105:                String s = "testpng";
106:
107:                assertEquals("bin", BasicAttachmentProvider.getFileExtension(s));
108:            }
109:
110:            public void testExtension5() {
111:                String s = "test.";
112:
113:                assertEquals("bin", BasicAttachmentProvider.getFileExtension(s));
114:            }
115:
116:            public void testExtension6() {
117:                String s = "test.a";
118:
119:                assertEquals("a", BasicAttachmentProvider.getFileExtension(s));
120:            }
121:
122:            /**
123:             *  Can we save attachments with names in UTF-8 range?
124:             */
125:            public void testPutAttachmentUTF8() throws Exception {
126:                File in = makeAttachmentFile();
127:
128:                Attachment att = new Attachment(m_engine, NAME1,
129:                        "\u3072\u3048\u308båäötest.füü");
130:
131:                m_provider.putAttachmentData(att, new FileInputStream(in));
132:
133:                List res = m_provider.listAllChanged(new Date(0L));
134:
135:                Attachment a0 = (Attachment) res.get(0);
136:
137:                assertEquals("name", att.getName(), a0.getName());
138:            }
139:
140:            public void testListAll() throws Exception {
141:                File in = makeAttachmentFile();
142:
143:                Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
144:
145:                m_provider.putAttachmentData(att, new FileInputStream(in));
146:
147:                Thread.sleep(2000L); // So that we get a bit of granularity.
148:
149:                Attachment att2 = new Attachment(m_engine, NAME2, "test2.txt");
150:
151:                m_provider.putAttachmentData(att2, new FileInputStream(in));
152:
153:                List res = m_provider.listAllChanged(new Date(0L));
154:
155:                assertEquals("list size", 2, res.size());
156:
157:                Attachment a2 = (Attachment) res.get(0); // Most recently changed
158:                Attachment a1 = (Attachment) res.get(1); // Least recently changed
159:
160:                assertEquals("a1 name", att.getName(), a1.getName());
161:                assertEquals("a2 name", att2.getName(), a2.getName());
162:            }
163:
164:            /**
165:             *  Check that the system does not fail if there are extra files in the directory.
166:             */
167:            public void testListAllExtrafile() throws Exception {
168:                File in = makeAttachmentFile();
169:
170:                File sDir = new File(m_engine.getWikiProperties().getProperty(
171:                        BasicAttachmentProvider.PROP_STORAGEDIR));
172:                File extrafile = makeExtraFile(sDir, "foobar.blob");
173:
174:                try {
175:                    Attachment att = new Attachment(m_engine, NAME1,
176:                            "test1.txt");
177:
178:                    m_provider.putAttachmentData(att, new FileInputStream(in));
179:
180:                    Thread.sleep(2000L); // So that we get a bit of granularity.
181:
182:                    Attachment att2 = new Attachment(m_engine, NAME2,
183:                            "test2.txt");
184:
185:                    m_provider.putAttachmentData(att2, new FileInputStream(in));
186:
187:                    List res = m_provider.listAllChanged(new Date(0L));
188:
189:                    assertEquals("list size", 2, res.size());
190:
191:                    Attachment a2 = (Attachment) res.get(0); // Most recently changed
192:                    Attachment a1 = (Attachment) res.get(1); // Least recently changed
193:
194:                    assertEquals("a1 name", att.getName(), a1.getName());
195:                    assertEquals("a2 name", att2.getName(), a2.getName());
196:                } finally {
197:                    extrafile.delete();
198:                }
199:            }
200:
201:            /**
202:             *  Check that the system does not fail if there are extra files in the
203:             *  attachment directory.
204:             */
205:            public void testListAllExtrafileInAttachmentDir() throws Exception {
206:                File in = makeAttachmentFile();
207:
208:                File sDir = new File(m_engine.getWikiProperties().getProperty(
209:                        BasicAttachmentProvider.PROP_STORAGEDIR));
210:                File attDir = new File(sDir, NAME1 + "-att");
211:
212:                Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
213:
214:                m_provider.putAttachmentData(att, new FileInputStream(in));
215:
216:                File extrafile = makeExtraFile(attDir, "ping.pong");
217:
218:                try {
219:                    Thread.sleep(2000L); // So that we get a bit of granularity.
220:
221:                    Attachment att2 = new Attachment(m_engine, NAME2,
222:                            "test2.txt");
223:
224:                    m_provider.putAttachmentData(att2, new FileInputStream(in));
225:
226:                    List res = m_provider.listAllChanged(new Date(0L));
227:
228:                    assertEquals("list size", 2, res.size());
229:
230:                    Attachment a2 = (Attachment) res.get(0); // Most recently changed
231:                    Attachment a1 = (Attachment) res.get(1); // Least recently changed
232:
233:                    assertEquals("a1 name", att.getName(), a1.getName());
234:                    assertEquals("a2 name", att2.getName(), a2.getName());
235:                } finally {
236:                    extrafile.delete();
237:                }
238:            }
239:
240:            /**
241:             *  Check that the system does not fail if there are extra dirs in the
242:             *  attachment directory.
243:             */
244:            public void testListAllExtradirInAttachmentDir() throws Exception {
245:                File in = makeAttachmentFile();
246:
247:                File sDir = new File(m_engine.getWikiProperties().getProperty(
248:                        BasicAttachmentProvider.PROP_STORAGEDIR));
249:                File attDir = new File(sDir, NAME1 + "-att");
250:
251:                Attachment att = new Attachment(m_engine, NAME1, "test1.txt");
252:
253:                m_provider.putAttachmentData(att, new FileInputStream(in));
254:
255:                // This is our extraneous directory. 
256:                File extrafile = new File(attDir, "ping.pong");
257:                extrafile.mkdir();
258:
259:                try {
260:                    Thread.sleep(2000L); // So that we get a bit of granularity.
261:
262:                    Attachment att2 = new Attachment(m_engine, NAME2,
263:                            "test2.txt");
264:
265:                    m_provider.putAttachmentData(att2, new FileInputStream(in));
266:
267:                    List res = m_provider.listAllChanged(new Date(0L));
268:
269:                    assertEquals("list size", 2, res.size());
270:
271:                    Attachment a2 = (Attachment) res.get(0); // Most recently changed
272:                    Attachment a1 = (Attachment) res.get(1); // Least recently changed
273:
274:                    assertEquals("a1 name", att.getName(), a1.getName());
275:                    assertEquals("a2 name", att2.getName(), a2.getName());
276:                } finally {
277:                    extrafile.delete();
278:                }
279:            }
280:
281:            public void testListAllNoExtension() throws Exception {
282:                File in = makeAttachmentFile();
283:
284:                Attachment att = new Attachment(m_engine, NAME1, "test1.");
285:
286:                m_provider.putAttachmentData(att, new FileInputStream(in));
287:
288:                Thread.sleep(2000L); // So that we get a bit of granularity.
289:
290:                Attachment att2 = new Attachment(m_engine, NAME2, "test2.");
291:
292:                m_provider.putAttachmentData(att2, new FileInputStream(in));
293:
294:                List res = m_provider.listAllChanged(new Date(0L));
295:
296:                assertEquals("list size", 2, res.size());
297:
298:                Attachment a2 = (Attachment) res.get(0); // Most recently changed
299:                Attachment a1 = (Attachment) res.get(1); // Least recently changed
300:
301:                assertEquals("a1 name", att.getName(), a1.getName());
302:                assertEquals("a2 name", att2.getName(), a2.getName());
303:            }
304:
305:            public static Test suite() {
306:                return new TestSuite(BasicAttachmentProviderTest.class);
307:            }
308:
309:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.