Source Code Cross Referenced for BookmarkTest.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.BufferedReader;
022:        import java.io.InputStream;
023:        import java.io.InputStreamReader;
024:        import java.util.List;
025:        import junit.framework.Test;
026:        import junit.framework.TestCase;
027:        import junit.framework.TestSuite;
028:        import org.apache.commons.logging.Log;
029:        import org.apache.commons.logging.LogFactory;
030:        import org.apache.roller.RollerException;
031:        import org.apache.roller.TestUtils;
032:        import org.apache.roller.business.BookmarkManager;
033:        import org.apache.roller.business.Roller;
034:        import org.apache.roller.business.RollerFactory;
035:        import org.apache.roller.pojos.BookmarkData;
036:        import org.apache.roller.pojos.FolderData;
037:        import org.apache.roller.pojos.UserData;
038:        import org.apache.roller.pojos.WebsiteData;
039:        import org.apache.roller.util.Utilities;
040:
041:        /**
042:         * Test Roller Bookmark Management.
043:         */
044:        public class BookmarkTest extends TestCase {
045:
046:            public static Log log = LogFactory.getLog(BookmarkTest.class);
047:
048:            UserData testUser = null;
049:            WebsiteData testWeblog = null;
050:
051:            public BookmarkTest(String name) {
052:                super (name);
053:            }
054:
055:            public static Test suite() {
056:                return new TestSuite(BookmarkTest.class);
057:            }
058:
059:            /**
060:             * All tests in this suite require a user and a weblog.
061:             */
062:            public void setUp() throws Exception {
063:
064:                try {
065:                    testUser = TestUtils.setupUser("bkmrkTestUser");
066:                    testWeblog = TestUtils.setupWeblog("bkmrkTestWeblog",
067:                            testUser);
068:                    TestUtils.endSession(true);
069:                } catch (Exception ex) {
070:                    log.error(ex);
071:                    throw new Exception("Test setup failed", ex);
072:                }
073:            }
074:
075:            public void tearDown() throws Exception {
076:
077:                try {
078:                    TestUtils.teardownWeblog(testWeblog.getId());
079:                    TestUtils.teardownUser(testUser.getId());
080:                    TestUtils.endSession(true);
081:                } catch (Exception ex) {
082:                    log.error(ex);
083:                    throw new Exception("Test teardown failed", ex);
084:                }
085:            }
086:
087:            public Roller getRoller() {
088:                return RollerFactory.getRoller();
089:            }
090:
091:            public void testAddBookmarkToFolder() throws Exception {
092:
093:                BookmarkManager bmgr = getRoller().getBookmarkManager();
094:                FolderData folder = null;
095:                BookmarkData bookmark1 = null, bookmark2 = null;
096:
097:                FolderData root = bmgr.getRootFolder(testWeblog);
098:
099:                folder = new FolderData();
100:                folder.setName("TestFolder1");
101:                folder.setDescription("created by testAddBookmarkToFolder()");
102:                folder.setWebsite(testWeblog);
103:                folder.setParent(root);
104:                bmgr.saveFolder(folder);
105:
106:                // Add bookmark by adding to folder
107:                bookmark1 = new BookmarkData(folder, "TestBookmark1",
108:                        "created by testAddBookmarkToFolder()",
109:                        "http://www.example.com",
110:                        "http://www.example.com/rss.xml", new Integer(1),
111:                        new Integer(12), "test.jpg");
112:                folder.addBookmark(bookmark1);
113:
114:                // Add another bookmark
115:                bookmark2 = new BookmarkData(folder, "TestBookmark2",
116:                        "created by testAddBookmarkToFolder()",
117:                        "http://www.example.com",
118:                        "http://www.example.com/rss.xml", new Integer(1),
119:                        new Integer(12), "test.jpf");
120:                folder.addBookmark(bookmark2);
121:
122:                TestUtils.endSession(true);
123:
124:                FolderData testFolder = null;
125:                BookmarkData bookmarkb = null, bookmarka = null;
126:
127:                // See that two bookmarks were stored
128:                testFolder = bmgr.getFolder(folder.getId());
129:                assertEquals(2, testFolder.getBookmarks().size());
130:                bookmarka = (BookmarkData) testFolder.getBookmarks().iterator()
131:                        .next();
132:                bookmarkb = (BookmarkData) testFolder.getBookmarks().iterator()
133:                        .next();
134:                // Remove one bookmark
135:                testFolder.removeBookmark(bookmarka);
136:                bmgr.removeBookmark(bookmarka);
137:                TestUtils.endSession(true);
138:
139:                // Folder should now contain one bookmark
140:                testFolder = bmgr.getFolder(folder.getId());
141:                assertEquals(1, testFolder.getBookmarks().size());
142:                TestUtils.endSession(true);
143:
144:                // Remove folder
145:                testFolder = bmgr.getFolder(folder.getId());
146:                bmgr.removeFolder(testFolder);
147:                TestUtils.endSession(true);
148:
149:                // Folder and one remaining bookmark should be gone
150:                assertNull(bmgr.getBookmark(bookmarkb.getId()));
151:                assertNull(bmgr.getFolder(folder.getId()));
152:            }
153:
154:            public void testBookmarkImport() throws Exception {
155:                importBookmarks("/bookmarks.opml");
156:            }
157:
158:            public void importBookmarks(String fileName) throws Exception {
159:
160:                InputStream fis = this .getClass().getResourceAsStream(fileName);
161:                getRoller().getBookmarkManager().importBookmarks(testWeblog,
162:                        "ZZZ_imports_ZZZ", fileToString(fis));
163:                TestUtils.endSession(true);
164:
165:                FolderData fd = null;
166:
167:                fd = getRoller().getBookmarkManager().getFolder(testWeblog,
168:                        "ZZZ_imports_ZZZ");
169:                assertTrue("no bookmarks found", fd.retrieveBookmarks(true)
170:                        .size() > 0);
171:                getRoller().getBookmarkManager().removeFolder(fd);
172:                TestUtils.endSession(true);
173:            }
174:
175:            public String fileToString(InputStream is)
176:                    throws java.io.IOException {
177:                BufferedReader br = new BufferedReader(
178:                        new InputStreamReader(is));
179:                String s = null;
180:                StringBuffer sb = new StringBuffer();
181:                while ((s = br.readLine()) != null) {
182:                    sb.append(s);
183:                }
184:                return sb.toString();
185:            }
186:
187:            /**
188:             * Creates folder tree like this:
189:             *    root/
190:             *       dest/
191:             *       f1/
192:             *          b1
193:             *          f2/
194:             *             f3/
195:             */
196:            public void testMoveFolderContents() throws Exception {
197:
198:                BookmarkManager bmgr = getRoller().getBookmarkManager();
199:
200:                FolderData root = bmgr.getRootFolder(testWeblog);
201:
202:                FolderData dest = new FolderData();
203:                dest.setName("dest");
204:                dest.setParent(root);
205:                dest.setWebsite(testWeblog);
206:                bmgr.saveFolder(dest);
207:
208:                // create source folder f1
209:                FolderData f1 = new FolderData();
210:                f1.setName("f1");
211:                f1.setParent(root);
212:                f1.setWebsite(testWeblog);
213:                bmgr.saveFolder(f1);
214:
215:                // create bookmark b1 inside source folder f1
216:                BookmarkData b1 = new BookmarkData(f1, "b1", "testbookmark",
217:                        "http://example.com", "http://example.com/rss",
218:                        new Integer(1), new Integer(1), "image.gif");
219:                f1.addBookmark(b1);
220:
221:                // create folder f2 inside f1
222:                FolderData f2 = new FolderData();
223:                f2.setName("f2");
224:                f2.setParent(f1);
225:                f2.setWebsite(testWeblog);
226:                bmgr.saveFolder(f2);
227:
228:                // create bookmark b2 inside folder f2
229:                BookmarkData b2 = new BookmarkData(f2, "b2", "testbookmark",
230:                        "http://example.com", "http://example.com/rss",
231:                        new Integer(1), new Integer(1), "image.gif");
232:                f2.addBookmark(b2);
233:
234:                // create folder f3 inside folder f2
235:                FolderData f3 = new FolderData();
236:                f3.setName("f3");
237:                f3.setParent(f2);
238:                f3.setWebsite(testWeblog);
239:                bmgr.saveFolder(f3);
240:
241:                // crete bookmark b3 inside folder f3
242:                BookmarkData b3 = new BookmarkData(f3, "b3", "testbookmark",
243:                        "http://example.com", "http://example.com/rss",
244:                        new Integer(1), new Integer(1), "image.gif");
245:                f3.addBookmark(b3);
246:
247:                TestUtils.endSession(true);
248:
249:                // test that parent cannot be moved into child
250:                boolean safe = false;
251:                try {
252:
253:                    // Move folder into one of it's children
254:                    f1 = bmgr.getFolder(f1.getId());
255:                    f3 = bmgr.getFolder(f3.getId());
256:                    bmgr.moveFolderContents(f1, f3);
257:                    //f3.save();
258:                    //f1.save();
259:                    TestUtils.endSession(true);
260:                } catch (RollerException e) {
261:                    safe = true;
262:                }
263:                assertTrue(safe);
264:
265:                // verify number of entries in each folder
266:                dest = bmgr.getFolder(dest.getId());
267:                f1 = bmgr.getFolder(f1.getId());
268:                assertEquals(0, dest.retrieveBookmarks(true).size());
269:                assertEquals(0, dest.retrieveBookmarks(false).size());
270:                assertEquals(1, f1.retrieveBookmarks(false).size());
271:
272:                List f1list = f1.retrieveBookmarks(true);
273:                assertEquals(3, f1list.size());
274:
275:                // move contents of source category c1 to destination catetory dest
276:                f1.moveContents(dest);
277:                bmgr.saveFolder(f1);
278:                bmgr.saveFolder(dest);
279:                TestUtils.endSession(true);
280:
281:                // after move, verify number of entries in eacch folder
282:                dest = bmgr.getFolder(dest.getId());
283:                f1 = bmgr.getFolder(f1.getId());
284:                assertEquals(3, dest.retrieveBookmarks(true).size());
285:                assertEquals(3, dest.retrieveBookmarks(false).size());
286:                assertEquals(0, f1.retrieveBookmarks(true).size());
287:                assertEquals(0, f1.retrieveBookmarks(false).size());
288:            }
289:
290:            /** Test bookmark folder paths. */
291:            public void testPaths() throws Exception {
292:
293:                BookmarkManager bmgr = getRoller().getBookmarkManager();
294:
295:                try {
296:                    FolderData root = bmgr.getRootFolder(testWeblog);
297:
298:                    FolderData f1 = new FolderData();
299:                    f1.setName("f1");
300:                    f1.setParent(root);
301:                    f1.setWebsite(testWeblog);
302:                    bmgr.saveFolder(f1);
303:
304:                    FolderData f2 = new FolderData();
305:                    f2.setName("f2");
306:                    f2.setParent(f1);
307:                    f2.setWebsite(testWeblog);
308:                    bmgr.saveFolder(f2);
309:
310:                    FolderData f3 = new FolderData();
311:                    f3.setName("f3");
312:                    f3.setParent(f2);
313:                    f3.setWebsite(testWeblog);
314:                    bmgr.saveFolder(f3);
315:
316:                    TestUtils.endSession(true);
317:                } catch (RollerException e) {
318:                    TestUtils.endSession(true);
319:                    log.error(e);
320:                }
321:
322:                try {
323:
324:                    assertEquals("f1", bmgr.getFolderByPath(testWeblog, null,
325:                            "/f1").getName());
326:                    assertEquals("f2", bmgr.getFolderByPath(testWeblog, null,
327:                            "/f1/f2").getName());
328:                    assertEquals("f3", bmgr.getFolderByPath(testWeblog, null,
329:                            "/f1/f2/f3").getName());
330:
331:                    FolderData f3 = bmgr.getFolderByPath(testWeblog, null,
332:                            "/f1/f2/f3");
333:                    String pathString = bmgr.getPath(f3);
334:                    String[] pathArray = Utilities.stringToStringArray(
335:                            pathString, "/");
336:                    assertEquals("f1", pathArray[0]);
337:                    assertEquals("f2", pathArray[1]);
338:                    assertEquals("f3", pathArray[2]);
339:
340:                } catch (RollerException e) {
341:                    TestUtils.endSession(true);
342:                    log.error(e);
343:                }
344:            }
345:
346:            /** Ensure that duplicate folder name will throw RollerException */
347:            public void testUniquenessOfFolderNames() throws Exception {
348:
349:                boolean exception = false;
350:                FolderData f3 = null;
351:                BookmarkManager bmgr = getRoller().getBookmarkManager();
352:                try {
353:                    FolderData root = bmgr.getRootFolder(testWeblog);
354:
355:                    FolderData f1 = new FolderData();
356:                    f1.setName("f1");
357:                    f1.setParent(root);
358:                    f1.setWebsite(testWeblog);
359:                    bmgr.saveFolder(f1);
360:
361:                    // first child folder
362:                    FolderData f2 = new FolderData();
363:                    f2.setName("f2");
364:                    f2.setParent(f1);
365:                    f2.setWebsite(testWeblog);
366:                    bmgr.saveFolder(f2);
367:
368:                    TestUtils.endSession(true);
369:
370:                    // child folder with same name as first
371:                    f3 = new FolderData();
372:                    f3.setName("f2");
373:                    f3.setParent(f1);
374:                    f3.setWebsite(testWeblog);
375:                    bmgr.saveFolder(f3);
376:
377:                    TestUtils.endSession(true);
378:                } catch (RollerException e) {
379:                    exception = true;
380:                }
381:
382:                assertTrue(exception);
383:            }
384:
385:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.