Source Code Cross Referenced for FileManagerTest.java in  » Blogger-System » apache-roller-3.1 » org » apache » roller » business » 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 » Blogger System » apache roller 3.1 » org.apache.roller.business 
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.  The ASF licenses this file to You
004:         * under the Apache License, Version 2.0 (the "License"); you may not
005:         * use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.  For additional information regarding
015:         * copyright in this work, please see the NOTICE file in the top level
016:         * directory of this distribution.
017:         */
018:
019:        package org.apache.roller.business;
020:
021:        import java.io.InputStream;
022:        import java.util.Map;
023:        import junit.framework.Test;
024:        import junit.framework.TestCase;
025:        import junit.framework.TestSuite;
026:        import org.apache.commons.logging.Log;
027:        import org.apache.commons.logging.LogFactory;
028:        import org.apache.roller.TestUtils;
029:        import org.apache.roller.business.FileManager;
030:        import org.apache.roller.business.PropertiesManager;
031:        import org.apache.roller.business.RollerFactory;
032:        import org.apache.roller.pojos.RollerPropertyData;
033:        import org.apache.roller.pojos.UserData;
034:        import org.apache.roller.pojos.WeblogResource;
035:        import org.apache.roller.pojos.WebsiteData;
036:
037:        /**
038:         * Test File Management business layer operations.
039:         */
040:        public class FileManagerTest extends TestCase {
041:
042:            private static Log log = LogFactory.getLog(FileManagerTest.class);
043:
044:            UserData testUser = null;
045:            WebsiteData testWeblog = null;
046:
047:            public FileManagerTest(String name) {
048:                super (name);
049:            }
050:
051:            public static Test suite() {
052:                return new TestSuite(FileManagerTest.class);
053:            }
054:
055:            public void setUp() throws Exception {
056:
057:                try {
058:                    testUser = TestUtils.setupUser("FileManagerTest_userName");
059:                    testWeblog = TestUtils.setupWeblog(
060:                            "FileManagerTest_handle", testUser);
061:                    TestUtils.endSession(true);
062:                } catch (Exception ex) {
063:                    log.error(ex);
064:                }
065:            }
066:
067:            public void tearDown() throws Exception {
068:
069:                try {
070:                    TestUtils.teardownWeblog(testWeblog.getId());
071:                    TestUtils.teardownUser(testUser.getId());
072:                    TestUtils.endSession(true);
073:                } catch (Exception ex) {
074:                    log.error(ex);
075:                }
076:            }
077:
078:            /**
079:             * Test simple file save/delete.
080:             */
081:            public void testFileCRUD() throws Exception {
082:
083:                // update roller properties to prepare for test
084:                PropertiesManager pmgr = RollerFactory.getRoller()
085:                        .getPropertiesManager();
086:                Map config = pmgr.getProperties();
087:                ((RollerPropertyData) config.get("uploads.enabled"))
088:                        .setValue("true");
089:                ((RollerPropertyData) config.get("uploads.types.allowed"))
090:                        .setValue("opml");
091:                ((RollerPropertyData) config.get("uploads.dir.maxsize"))
092:                        .setValue("1.00");
093:                pmgr.saveProperties(config);
094:                TestUtils.endSession(true);
095:
096:                /* NOTE: upload dir for unit tests is set in
097:                       roller/testdata/roller-custom.properties */
098:                FileManager fmgr = RollerFactory.getRoller().getFileManager();
099:
100:                // we should be starting with 0 files
101:                assertEquals(0, fmgr.getFiles(testWeblog, null).length);
102:
103:                // store a file
104:                InputStream is = getClass().getResourceAsStream(
105:                        "/bookmarks.opml");
106:                fmgr.saveFile(testWeblog, "bookmarks.opml", "text/plain", 1545,
107:                        is);
108:
109:                // make sure file was stored successfully
110:                assertEquals("bookmarks.opml", fmgr.getFile(testWeblog,
111:                        "bookmarks.opml").getName());
112:                assertEquals(1, fmgr.getFiles(testWeblog, null).length);
113:
114:                // delete file
115:                fmgr.deleteFile(testWeblog, "bookmarks.opml");
116:
117:                // make sure delete was successful
118:                assertEquals(0, fmgr.getFiles(testWeblog, null).length);
119:            }
120:
121:            /**
122:             * Test simple directory create/delete.
123:             */
124:            public void testDirectoryCRUD() throws Exception {
125:
126:                // update roller properties to prepare for test
127:                PropertiesManager pmgr = RollerFactory.getRoller()
128:                        .getPropertiesManager();
129:                Map config = pmgr.getProperties();
130:                ((RollerPropertyData) config.get("uploads.enabled"))
131:                        .setValue("true");
132:                ((RollerPropertyData) config.get("uploads.types.allowed"))
133:                        .setValue("opml");
134:                ((RollerPropertyData) config.get("uploads.dir.maxsize"))
135:                        .setValue("1.00");
136:                pmgr.saveProperties(config);
137:                TestUtils.endSession(true);
138:
139:                FileManager fmgr = RollerFactory.getRoller().getFileManager();
140:
141:                // we should be starting with 0 directories
142:                assertEquals(0, fmgr.getDirectories(testWeblog).length);
143:
144:                // create a directory
145:                fmgr.createDirectory(testWeblog, "bucket0");
146:
147:                // make sure directory was created
148:                WeblogResource[] dirs = fmgr.getDirectories(testWeblog);
149:                assertNotNull(dirs);
150:                assertEquals(1, dirs.length);
151:                assertEquals("bucket0", dirs[0].getName());
152:
153:                // cleanup
154:                fmgr.deleteFile(testWeblog, "bucket0");
155:
156:                // make sure delete was successful
157:                assertEquals(0, fmgr.getDirectories(testWeblog).length);
158:            }
159:
160:            /**
161:             * Test save/delete of files in a directory.
162:             */
163:            public void testFilesInDirectoriesCRUD() throws Exception {
164:
165:                // update roller properties to prepare for test
166:                PropertiesManager pmgr = RollerFactory.getRoller()
167:                        .getPropertiesManager();
168:                Map config = pmgr.getProperties();
169:                ((RollerPropertyData) config.get("uploads.enabled"))
170:                        .setValue("true");
171:                ((RollerPropertyData) config.get("uploads.types.allowed"))
172:                        .setValue("opml");
173:                ((RollerPropertyData) config.get("uploads.dir.maxsize"))
174:                        .setValue("1.00");
175:                pmgr.saveProperties(config);
176:                TestUtils.endSession(true);
177:
178:                FileManager fmgr = RollerFactory.getRoller().getFileManager();
179:
180:                // we should be starting with 0 files and 0 directories
181:                assertEquals(0, fmgr.getFiles(testWeblog, null).length);
182:                assertEquals(0, fmgr.getDirectories(testWeblog).length);
183:
184:                // create a directory
185:                fmgr.createDirectory(testWeblog, "bucket1");
186:
187:                // make sure directory was created
188:                WeblogResource[] dirs = fmgr.getDirectories(testWeblog);
189:                assertNotNull(dirs);
190:                assertEquals(1, dirs.length);
191:                assertEquals("bucket1", dirs[0].getName());
192:
193:                // store a file into a subdirectory
194:                InputStream is = getClass().getResourceAsStream(
195:                        "/bookmarks.opml");
196:                fmgr.saveFile(testWeblog, "bucket1/bookmarks.opml",
197:                        "text/plain", 1545, is);
198:
199:                // make sure file was stored successfully
200:                assertEquals("bucket1/bookmarks.opml", fmgr.getFile(testWeblog,
201:                        "bucket1/bookmarks.opml").getPath());
202:                assertEquals(1, fmgr.getFiles(testWeblog, "bucket1").length);
203:
204:                // cleanup
205:                fmgr.deleteFile(testWeblog, "bucket1/bookmarks.opml");
206:                fmgr.deleteFile(testWeblog, "bucket1");
207:
208:                // we should be back to 0 files and 0 directories
209:                assertEquals(0, fmgr.getFiles(testWeblog, null).length);
210:                assertEquals(0, fmgr.getDirectories(testWeblog).length);
211:            }
212:
213:            /**
214:             * Test FileManager.saveFile() checks.
215:             *
216:             * This should test all conditions where a save should fail.
217:             */
218:            public void testCanSave() throws Exception {
219:
220:                FileManager fmgr = RollerFactory.getRoller().getFileManager();
221:                PropertiesManager pmgr = RollerFactory.getRoller()
222:                        .getPropertiesManager();
223:                Map config = config = pmgr.getProperties();
224:                ((RollerPropertyData) config.get("uploads.dir.maxsize"))
225:                        .setValue("1.00");
226:                ((RollerPropertyData) config.get("uploads.types.forbid"))
227:                        .setValue("");
228:                ((RollerPropertyData) config.get("uploads.types.allowed"))
229:                        .setValue("");
230:                ((RollerPropertyData) config.get("uploads.enabled"))
231:                        .setValue("true");
232:                pmgr.saveProperties(config);
233:                TestUtils.endSession(true);
234:
235:                Exception exception = null;
236:                InputStream is = null;
237:
238:                try {
239:                    // path check should fail
240:                    fmgr.saveFile(testWeblog, "some/path/foo.gif",
241:                            "text/plain", 10, is);
242:                } catch (Exception ex) {
243:                    log.error(ex);
244:                    exception = ex;
245:                }
246:                assertNotNull(exception);
247:                exception = null;
248:
249:                config = pmgr.getProperties();
250:                ((RollerPropertyData) config.get("uploads.dir.maxsize"))
251:                        .setValue("1.00");
252:                pmgr.saveProperties(config);
253:                TestUtils.endSession(true);
254:
255:                try {
256:                    // quota check should fail
257:                    fmgr.saveFile(testWeblog, "test.gif", "text/plain",
258:                            2500000, is);
259:                } catch (Exception ex) {
260:                    log.error(ex);
261:                    exception = ex;
262:                }
263:                assertNotNull(exception);
264:                exception = null;
265:
266:                config = pmgr.getProperties();
267:                ((RollerPropertyData) config.get("uploads.types.forbid"))
268:                        .setValue("gif");
269:                pmgr.saveProperties(config);
270:                TestUtils.endSession(true);
271:
272:                try {
273:                    // forbidden types check should fail
274:                    fmgr.saveFile(testWeblog, "test.gif", "text/plain", 10, is);
275:                } catch (Exception ex) {
276:                    log.error(ex);
277:                    exception = ex;
278:                }
279:                assertNotNull(exception);
280:                exception = null;
281:
282:                config = pmgr.getProperties();
283:                ((RollerPropertyData) config.get("uploads.enabled"))
284:                        .setValue("false");
285:                pmgr.saveProperties(config);
286:                TestUtils.endSession(true);
287:
288:                try {
289:                    // uploads disabled should fail
290:                    fmgr.saveFile(testWeblog, "test.gif", "text/plain", 10, is);
291:                } catch (Exception ex) {
292:                    log.error(ex);
293:                    exception = ex;
294:                }
295:                assertNotNull(exception);
296:                exception = null;
297:            }
298:
299:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.