Source Code Cross Referenced for WeblogEntryTest.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.sql.Timestamp;
022:        import java.util.ArrayList;
023:        import java.util.Arrays;
024:        import java.util.HashMap;
025:        import java.util.HashSet;
026:        import java.util.Iterator;
027:        import java.util.List;
028:        import java.util.Map;
029:        import junit.framework.Test;
030:        import junit.framework.TestCase;
031:        import junit.framework.TestSuite;
032:        import org.apache.commons.logging.Log;
033:        import org.apache.commons.logging.LogFactory;
034:        import org.apache.roller.TestUtils;
035:        import org.apache.roller.business.RollerFactory;
036:        import org.apache.roller.business.WeblogManager;
037:        import org.apache.roller.pojos.TagStat;
038:        import org.apache.roller.pojos.UserData;
039:        import org.apache.roller.pojos.WeblogEntryData;
040:        import org.apache.roller.pojos.WeblogEntryTagData;
041:        import org.apache.roller.pojos.WebsiteData;
042:
043:        /**
044:         * Test WeblogEntry related business operations.
045:         */
046:        public class WeblogEntryTest extends TestCase {
047:
048:            public static Log log = LogFactory.getLog(WeblogEntryTest.class);
049:
050:            UserData testUser = null;
051:            WebsiteData testWeblog = null;
052:
053:            public WeblogEntryTest(String name) {
054:                super (name);
055:            }
056:
057:            public static Test suite() {
058:                return new TestSuite(WeblogEntryTest.class);
059:            }
060:
061:            /**
062:             * All tests in this suite require a user and a weblog.
063:             */
064:            public void setUp() throws Exception {
065:
066:                try {
067:                    testUser = TestUtils.setupUser("entryTestUser");
068:                    testWeblog = TestUtils.setupWeblog("entryTestWeblog",
069:                            testUser);
070:                    TestUtils.endSession(true);
071:                } catch (Exception ex) {
072:                    log.error(ex);
073:                    throw new Exception("Test setup failed", ex);
074:                }
075:            }
076:
077:            public void tearDown() throws Exception {
078:
079:                try {
080:                    TestUtils.teardownWeblog(testWeblog.getId());
081:                    TestUtils.teardownUser(testUser.getId());
082:                    TestUtils.endSession(true);
083:                } catch (Exception ex) {
084:                    log.error(ex);
085:                    throw new Exception("Test teardown failed", ex);
086:                }
087:            }
088:
089:            /**
090:             * Test basic persistence operations ... Create, Update, Delete.
091:             */
092:            public void testWeblogEntryCRUD() throws Exception {
093:
094:                WeblogManager mgr = RollerFactory.getRoller()
095:                        .getWeblogManager();
096:                WeblogEntryData entry = null;
097:
098:                WeblogEntryData testEntry = new WeblogEntryData();
099:                testEntry.setTitle("entryTestEntry");
100:                testEntry.setLink("testEntryLink");
101:                testEntry.setText("blah blah entry");
102:                testEntry.setAnchor("testEntryAnchor");
103:                testEntry.setPubTime(new java.sql.Timestamp(
104:                        new java.util.Date().getTime()));
105:                testEntry.setUpdateTime(new java.sql.Timestamp(
106:                        new java.util.Date().getTime()));
107:                testEntry.setWebsite(testWeblog);
108:                testEntry.setCreator(testUser);
109:                testEntry.setCategory(testWeblog.getDefaultCategory());
110:
111:                // create a weblog entry
112:                mgr.saveWeblogEntry(testEntry);
113:                String id = testEntry.getId();
114:                TestUtils.endSession(true);
115:
116:                // make sure entry was created
117:                entry = mgr.getWeblogEntry(id);
118:                assertNotNull(entry);
119:                assertEquals(testEntry, entry);
120:
121:                // update a weblog entry
122:                entry.setTitle("testtest");
123:                mgr.saveWeblogEntry(entry);
124:                TestUtils.endSession(true);
125:
126:                // make sure entry was updated
127:                entry = null;
128:                entry = mgr.getWeblogEntry(id);
129:                assertNotNull(entry);
130:                assertEquals("testtest", entry.getTitle());
131:
132:                // delete a weblog entry
133:                mgr.removeWeblogEntry(entry);
134:                TestUtils.endSession(true);
135:
136:                // make sure entry was deleted
137:                entry = null;
138:                entry = mgr.getWeblogEntry(id);
139:                assertNull(entry);
140:            }
141:
142:            /**
143:             * Test lookup mechanisms ... 
144:             */
145:            public void testWeblogEntryLookups() throws Exception {
146:
147:                WeblogManager mgr = RollerFactory.getRoller()
148:                        .getWeblogManager();
149:                WeblogEntryData entry = null;
150:                List entries = null;
151:                Map entryMap = null;
152:
153:                // setup some test entries to use
154:                WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1",
155:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
156:                WeblogEntryData entry2 = TestUtils.setupWeblogEntry("entry2",
157:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
158:                WeblogEntryData entry3 = TestUtils.setupWeblogEntry("entry3",
159:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
160:
161:                // make a couple changes
162:                entry1.setLocale("en_US");
163:                mgr.saveWeblogEntry(entry1);
164:                entry2.setLocale("ja_JP");
165:                entry2.setPinnedToMain(Boolean.TRUE);
166:                entry2.setUpdateTime(new java.sql.Timestamp(entry2
167:                        .getUpdateTime().getTime() + 8822384));
168:                entry2.setPubTime(entry2.getUpdateTime());
169:                mgr.saveWeblogEntry(entry2);
170:                entry3.setStatus(WeblogEntryData.DRAFT);
171:                entry3.setUpdateTime(new java.sql.Timestamp(entry3
172:                        .getUpdateTime().getTime() + 348829384));
173:                entry3.setPubTime(entry3.getUpdateTime());
174:                mgr.saveWeblogEntry(entry3);
175:
176:                TestUtils.endSession(true);
177:
178:                log.debug("entry1 = " + entry1.getUpdateTime());
179:                log.debug("entry2 = " + entry2.getUpdateTime());
180:                log.debug("entry3 = " + entry3.getUpdateTime());
181:
182:                // get entry by id
183:                entry = null;
184:                entry = mgr.getWeblogEntry(entry1.getId());
185:                assertNotNull(entry);
186:                assertEquals(entry1.getAnchor(), entry.getAnchor());
187:
188:                // get entry by anchor
189:                entry = null;
190:                entry = mgr.getWeblogEntryByAnchor(testWeblog, entry1
191:                        .getAnchor());
192:                assertNotNull(entry);
193:                assertEquals(entry1.getTitle(), entry.getTitle());
194:
195:                // get all entries for weblog
196:                entries = null;
197:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
198:                        null, null, null, null, null, 0, -1);
199:                assertNotNull(entries);
200:                assertEquals(3, entries.size());
201:                assertEquals(entry3, entries.get(0));
202:
203:                // get all entries in category
204:                entries = null;
205:                entries = mgr.getWeblogEntries(testWeblog.getDefaultCategory(),
206:                        false);
207:                assertNotNull(entries);
208:                assertEquals(3, entries.size());
209:
210:                // get all published entries only 
211:                entries = null;
212:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
213:                        null, null, WeblogEntryData.PUBLISHED, null, null, 0,
214:                        -1);
215:                assertNotNull(entries);
216:                assertEquals(2, entries.size());
217:
218:                // get all entries in date range
219:                entries = null;
220:                entries = mgr.getWeblogEntries(testWeblog, null, entry2
221:                        .getPubTime(), entry2.getPubTime(), null, null, null,
222:                        null, null, 0, -1);
223:                assertNotNull(entries);
224:                assertEquals(1, entries.size());
225:                assertEquals(entry2, entries.get(0));
226:
227:                // get all entries, limited to maxSize
228:                entries = null;
229:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
230:                        null, null, null, null, null, 0, 2);
231:                assertNotNull(entries);
232:                assertEquals(2, entries.size());
233:
234:                // get all entries in category
235:                entries = null;
236:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
237:                        testWeblog.getDefaultCategory().getName(), null, null,
238:                        null, null, 0, -1);
239:                assertNotNull(entries);
240:                assertEquals(3, entries.size());
241:
242:                // get all entries, limited by offset/range
243:                entries = null;
244:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
245:                        null, null, null, null, null, 1, 1);
246:                assertNotNull(entries);
247:                assertEquals(1, entries.size());
248:                assertEquals(entry2, entries.get(0));
249:
250:                // get all entries, limited by locale
251:                entries = null;
252:                entries = mgr.getWeblogEntries(testWeblog, null, null, null,
253:                        null, null, null, null, "en_US", 0, -1);
254:                assertNotNull(entries);
255:                assertEquals(1, entries.size());
256:                assertEquals(entry1, entries.get(0));
257:
258:                // get pinned entries only
259:                entries = null;
260:                entries = mgr.getWeblogEntriesPinnedToMain(new Integer(5));
261:                assertNotNull(entries);
262:                assertEquals(1, entries.size());
263:                assertEquals(entry2, entries.get(0));
264:
265:                // get next entries
266:                entries = null;
267:                entries = mgr.getNextEntries(entry1, null, null, 5);
268:                assertNotNull(entries);
269:                assertEquals(1, entries.size());
270:                assertEquals(entry2, entries.get(0));
271:
272:                // get next entry
273:                entry = null;
274:                entry = mgr.getNextEntry(entry1, null, null);
275:                assertNotNull(entry);
276:                assertEquals(entry2, entry);
277:
278:                // get previous entries
279:                entries = null;
280:                entries = mgr.getPreviousEntries(entry2, null, null, 5);
281:                assertNotNull(entries);
282:                assertEquals(1, entries.size());
283:                assertEquals(entry1, entries.get(0));
284:
285:                // get previous entry
286:                entry = null;
287:                entry = mgr.getPreviousEntry(entry2, null, null);
288:                assertNotNull(entry);
289:                assertEquals(entry1, entry);
290:
291:                // get object map
292:                entryMap = null;
293:                entryMap = mgr.getWeblogEntryObjectMap(testWeblog, null, null,
294:                        null, null, null, null, 0, -1);
295:                assertNotNull(entryMap);
296:                assertTrue(entryMap.keySet().size() > 1);
297:
298:                // get string map
299:                entryMap = null;
300:                entryMap = mgr.getWeblogEntryStringMap(testWeblog, null, null,
301:                        null, null, null, null, 0, -1);
302:                assertNotNull(entryMap);
303:                assertTrue(entryMap.keySet().size() > 1);
304:
305:                // teardown our test entries
306:                TestUtils.teardownWeblogEntry(entry1.getId());
307:                TestUtils.teardownWeblogEntry(entry2.getId());
308:                TestUtils.teardownWeblogEntry(entry3.getId());
309:                TestUtils.endSession(true);
310:            }
311:
312:            /**
313:             * Test that the createAnchor() method actually ensures unique anchors.
314:             */
315:            public void testCreateAnchor() throws Exception {
316:
317:                WeblogManager mgr = RollerFactory.getRoller()
318:                        .getWeblogManager();
319:                WeblogEntryData entry = null;
320:                List entries = null;
321:
322:                // setup some test entries to use
323:                WeblogEntryData entry1 = TestUtils.setupWeblogEntry("entry1",
324:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
325:                TestUtils.endSession(true);
326:
327:                // make sure createAnchor gives us a new anchor value
328:                String anchor = mgr.createAnchor(entry1);
329:                assertNotNull(anchor);
330:                assertNotSame("entry1", anchor);
331:
332:                // make sure we can create a new entry with specified anchor
333:                WeblogEntryData entry2 = TestUtils.setupWeblogEntry(anchor,
334:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
335:                TestUtils.endSession(true);
336:                assertNotNull(entry2);
337:
338:                // teardown our test entries
339:                TestUtils.teardownWeblogEntry(entry1.getId());
340:                TestUtils.teardownWeblogEntry(entry2.getId());
341:                TestUtils.endSession(true);
342:            }
343:
344:            public void testCreateAnEntryWithTagsShortcut() throws Exception {
345:
346:                WeblogManager mgr = RollerFactory.getRoller()
347:                        .getWeblogManager();
348:                WeblogEntryData entry = null;
349:
350:                WeblogEntryData testEntry = new WeblogEntryData();
351:                testEntry.setTitle("entryTestEntry");
352:                testEntry.setLink("testEntryLink");
353:                testEntry.setText("blah blah entry");
354:                testEntry.setAnchor("testEntryAnchor");
355:                testEntry.setPubTime(new java.sql.Timestamp(
356:                        new java.util.Date().getTime()));
357:                testEntry.setUpdateTime(new java.sql.Timestamp(
358:                        new java.util.Date().getTime()));
359:                testEntry.setWebsite(testWeblog);
360:                testEntry.setCreator(testUser);
361:                testEntry.setCategory(testWeblog.getDefaultCategory());
362:
363:                // shortcut
364:                testEntry.addTag("testTag");
365:
366:                // create a weblog entry
367:                mgr.saveWeblogEntry(testEntry);
368:                String id = testEntry.getId();
369:                TestUtils.endSession(true);
370:
371:                // make sure entry was created
372:                entry = mgr.getWeblogEntry(id);
373:                assertNotNull(entry);
374:                assertEquals(testEntry, entry);
375:                assertNotNull(entry.getTags());
376:                assertEquals(1, entry.getTags().size());
377:                assertEquals("testtag", ((WeblogEntryTagData) entry.getTags()
378:                        .iterator().next()).getName());
379:
380:                // teardown our test entry
381:                TestUtils.teardownWeblogEntry(id);
382:                TestUtils.endSession(true);
383:            }
384:
385:            public void testAddMultipleTags() throws Exception {
386:
387:                WeblogManager mgr = RollerFactory.getRoller()
388:                        .getWeblogManager();
389:
390:                // setup some test entries to use
391:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
392:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
393:                entry.addTag("testTag");
394:                entry.addTag("whateverTag");
395:                String id = entry.getId();
396:                mgr.saveWeblogEntry(entry);
397:                TestUtils.endSession(true);
398:
399:                entry = mgr.getWeblogEntry(id);
400:                entry.addTag("testTag2");
401:                mgr.saveWeblogEntry(entry);
402:                TestUtils.endSession(true);
403:
404:                entry = mgr.getWeblogEntry(id);
405:                assertEquals(3, entry.getTags().size());
406:
407:                // teardown our test entry
408:                TestUtils.teardownWeblogEntry(id);
409:                TestUtils.endSession(true);
410:            }
411:
412:            public void testAddMultipleIdenticalTags() throws Exception {
413:
414:                WeblogManager mgr = RollerFactory.getRoller()
415:                        .getWeblogManager();
416:
417:                // setup some test entries to use
418:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
419:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
420:                entry.addTag("testTag");
421:                String id = entry.getId();
422:                mgr.saveWeblogEntry(entry);
423:                TestUtils.endSession(true);
424:
425:                entry = mgr.getWeblogEntry(id);
426:                entry.addTag("testTag");
427:                mgr.saveWeblogEntry(entry);
428:                TestUtils.endSession(true);
429:
430:                entry = mgr.getWeblogEntry(id);
431:                assertEquals(1, entry.getTags().size());
432:
433:                // teardown our test entry
434:                TestUtils.teardownWeblogEntry(id);
435:                TestUtils.endSession(true);
436:            }
437:
438:            public void testRemoveTagsViaShortcut() throws Exception {
439:
440:                WeblogManager mgr = RollerFactory.getRoller()
441:                        .getWeblogManager();
442:
443:                // setup some test entries to use
444:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
445:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
446:                entry.addTag("testTag");
447:                entry.addTag("testTag2");
448:                String id = entry.getId();
449:                mgr.saveWeblogEntry(entry);
450:                TestUtils.endSession(true);
451:
452:                entry = mgr.getWeblogEntry(id);
453:                assertEquals(2, entry.getTags().size());
454:                TestUtils.endSession(true);
455:
456:                entry = mgr.getWeblogEntry(id);
457:                entry.removeTag("testtag");
458:                entry.removeTag("testtag2");
459:                mgr.saveWeblogEntry(entry);
460:                TestUtils.endSession(true);
461:
462:                entry = mgr.getWeblogEntry(id);
463:                assertEquals(0, entry.getTags().size());
464:                TestUtils.endSession(true);
465:
466:                // teardown our test entry
467:                TestUtils.teardownWeblogEntry(id);
468:                TestUtils.endSession(true);
469:            }
470:
471:            public void testTagsExist() throws Exception {
472:
473:                WeblogManager mgr = RollerFactory.getRoller()
474:                        .getWeblogManager();
475:
476:                WebsiteData weblog = TestUtils.setupWeblog("tagsExistWeblog1",
477:                        testUser);
478:                String wid = weblog.getId();
479:
480:                // setup some test entries to use
481:                WeblogEntryData entry = TestUtils.setupWeblogEntry(
482:                        "tagsExistEntry1", testWeblog.getDefaultCategory(),
483:                        testWeblog, testUser);
484:                String id1 = entry.getId();
485:                entry.addTag("blahTag");
486:                entry.addTag("fooTag");
487:                mgr.saveWeblogEntry(entry);
488:
489:                WeblogEntryData entry2 = TestUtils.setupWeblogEntry(
490:                        "tagsExistEntry2", weblog.getDefaultCategory(), weblog,
491:                        testUser);
492:                String id2 = entry2.getId();
493:                entry2.addTag("aaaTag");
494:                entry2.addTag("bbbTag");
495:                mgr.saveWeblogEntry(entry2);
496:                TestUtils.endSession(true);
497:
498:                // we'll need these
499:                List tags1 = new ArrayList();
500:                tags1.add("nonExistTag");
501:
502:                List tags2 = new ArrayList();
503:                tags2.add("blahtag");
504:
505:                // test site-wide
506:                this .assertTrue(mgr.getTagComboExists(tags2, null));
507:                this .assertFalse(mgr.getTagComboExists(tags1, null));
508:
509:                // test weblog specific
510:                this .assertTrue(mgr.getTagComboExists(tags2, testWeblog));
511:                this .assertFalse(mgr.getTagComboExists(tags1, testWeblog));
512:                this .assertFalse(mgr.getTagComboExists(tags2, weblog));
513:
514:                // teardown our test data
515:                TestUtils.teardownWeblogEntry(id1);
516:                TestUtils.teardownWeblogEntry(id2);
517:                TestUtils.teardownWeblog(wid);
518:                TestUtils.endSession(true);
519:            }
520:
521:            public void testGetEntriesByTag() throws Exception {
522:
523:                WeblogManager mgr = RollerFactory.getRoller()
524:                        .getWeblogManager();
525:
526:                // setup some test entries to use
527:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
528:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
529:                entry.addTag("testTag");
530:                String id = entry.getId();
531:                mgr.saveWeblogEntry(entry);
532:                TestUtils.endSession(true);
533:
534:                List results = mgr.getWeblogEntries(testWeblog, null, null,
535:                        null, null, Arrays.asList(new String[] { "testtag" }),
536:                        null, null, null, 0, -1);
537:                assertEquals(1, results.size());
538:                WeblogEntryData testEntry = (WeblogEntryData) results
539:                        .iterator().next();
540:                assertEquals(entry, testEntry);
541:
542:                // teardown our test entry
543:                TestUtils.teardownWeblogEntry(id);
544:                TestUtils.endSession(true);
545:            }
546:
547:            public void testRemoveEntryTagCascading() throws Exception {
548:
549:                WeblogManager mgr = RollerFactory.getRoller()
550:                        .getWeblogManager();
551:
552:                // setup some test entries to use
553:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
554:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
555:                entry.addTag("testTag");
556:                String id = entry.getId();
557:                mgr.saveWeblogEntry(entry);
558:                TestUtils.endSession(true);
559:
560:                List results = mgr.getWeblogEntries(testWeblog, null, null,
561:                        null, null, Arrays.asList(new String[] { "testtag" }),
562:                        null, null, null, 0, -1);
563:                assertEquals(1, results.size());
564:                WeblogEntryData testEntry = (WeblogEntryData) results
565:                        .iterator().next();
566:                assertEquals(entry, testEntry);
567:
568:                // teardown our test entry
569:                TestUtils.teardownWeblogEntry(id);
570:                TestUtils.endSession(true);
571:
572:                results = mgr.getWeblogEntries(testWeblog, null, null, null,
573:                        null, Arrays.asList(new String[] { "testtag" }), null,
574:                        null, null, 0, -1);
575:                assertEquals(0, results.size());
576:
577:                // terminate
578:                TestUtils.endSession(true);
579:            }
580:
581:            public void testUpdateTags() throws Exception {
582:
583:                WeblogManager mgr = RollerFactory.getRoller()
584:                        .getWeblogManager();
585:
586:                // setup some test entries to use
587:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
588:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
589:                entry.addTag("testWillStayTag");
590:                entry.addTag("testTagWillBeRemoved");
591:                String id = entry.getId();
592:                mgr.saveWeblogEntry(entry);
593:                TestUtils.endSession(true);
594:
595:                entry = mgr.getWeblogEntry(id);
596:                assertEquals(2, entry.getTags().size());
597:
598:                List updateTags = new ArrayList();
599:                updateTags.add("testwillstaytag");
600:                updateTags.add("testnewtag");
601:                updateTags.add("testnewtag3");
602:                entry.updateTags(updateTags);
603:                mgr.saveWeblogEntry(entry);
604:                TestUtils.endSession(true);
605:
606:                entry = mgr.getWeblogEntry(id);
607:                HashSet tagNames = new HashSet();
608:                for (Iterator it = entry.getTags().iterator(); it.hasNext();) {
609:                    WeblogEntryTagData tagData = (WeblogEntryTagData) it.next();
610:                    tagNames.add(tagData.getName());
611:                }
612:
613:                assertEquals(3, entry.getTags().size());
614:                assertEquals(3, tagNames.size());
615:                assertEquals(true, tagNames.contains("testwillstaytag"));
616:                assertEquals(true, tagNames.contains("testnewtag"));
617:                assertEquals(true, tagNames.contains("testnewtag3"));
618:
619:                // teardown our test entry
620:                TestUtils.teardownWeblogEntry(id);
621:                TestUtils.endSession(true);
622:            }
623:
624:            /**
625:             * We want to make sure that the first time placed on the tag remains
626:             * through consequent updates.
627:             * 
628:             * @throws Exception
629:             */
630:            public void testUpdateTagTime() throws Exception {
631:
632:                WeblogManager mgr = RollerFactory.getRoller()
633:                        .getWeblogManager();
634:
635:                // setup some test entries to use
636:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
637:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
638:                String id = entry.getId();
639:
640:                entry.addTag("testWillStayTag");
641:                entry.addTag("testTagWillBeRemoved");
642:                mgr.saveWeblogEntry(entry);
643:                TestUtils.endSession(true);
644:
645:                entry = mgr.getWeblogEntry(id);
646:                assertEquals(2, entry.getTags().size());
647:
648:                Timestamp original = null;
649:
650:                for (Iterator it = entry.getTags().iterator(); it.hasNext();) {
651:                    WeblogEntryTagData tagData = (WeblogEntryTagData) it.next();
652:                    if (tagData.getName().equals("testwillstaytag"))
653:                        original = tagData.getTime();
654:                }
655:
656:                List updateTags = new ArrayList();
657:                updateTags.add("testwillstaytag");
658:                updateTags.add("testnewtag");
659:                updateTags.add("testnewtag3");
660:                entry.updateTags(updateTags);
661:                mgr.saveWeblogEntry(entry);
662:                TestUtils.endSession(true);
663:
664:                entry = mgr.getWeblogEntry(id);
665:                HashSet tagNames = new HashSet();
666:                for (Iterator it = entry.getTags().iterator(); it.hasNext();) {
667:                    WeblogEntryTagData tagData = (WeblogEntryTagData) it.next();
668:                    tagNames.add(tagData.getName());
669:                    if (tagData.getName().equals("testwillstaytag"))
670:                        assertEquals(original, tagData.getTime());
671:                }
672:
673:                assertEquals(3, entry.getTags().size());
674:                assertEquals(3, tagNames.size());
675:                assertEquals(true, tagNames.contains("testwillstaytag"));
676:                assertEquals(true, tagNames.contains("testnewtag"));
677:                assertEquals(true, tagNames.contains("testnewtag3"));
678:
679:                // teardown our test entry
680:                TestUtils.teardownWeblogEntry(id);
681:                TestUtils.endSession(true);
682:            }
683:
684:            public void testTagAggregates() throws Exception {
685:
686:                WebsiteData testWeblog2 = TestUtils.setupWeblog(
687:                        "entryTestWeblog2", testUser);
688:
689:                WeblogManager mgr = RollerFactory.getRoller()
690:                        .getWeblogManager();
691:
692:                // let's make sure we are starting from scratch
693:
694:                // site-wide
695:                List tags = mgr.getTags(null, null, null, -1);
696:                assertEquals(0, tags.size());
697:
698:                // first weblog
699:                tags = mgr.getTags(testWeblog, null, null, -1);
700:                assertEquals(0, tags.size());
701:
702:                // second weblog
703:                tags = mgr.getTags(testWeblog2, null, null, -1);
704:                assertEquals(0, tags.size());
705:
706:                // setup some test entries to use
707:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
708:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
709:                entry.addTag("one");
710:                entry.addTag("two");
711:                mgr.saveWeblogEntry(entry);
712:
713:                entry = TestUtils.setupWeblogEntry("entry2", testWeblog
714:                        .getDefaultCategory(), testWeblog, testUser);
715:                entry.addTag("one");
716:                entry.addTag("two");
717:                entry.addTag("three");
718:                mgr.saveWeblogEntry(entry);
719:
720:                TestUtils.endSession(true);
721:
722:                tags = mgr.getTags(testWeblog, null, null, -1);
723:                assertEquals(3, tags.size());
724:
725:                HashMap expectedWeblogTags = new HashMap();
726:                expectedWeblogTags.put("one", new Integer(2));
727:                expectedWeblogTags.put("two", new Integer(2));
728:                expectedWeblogTags.put("three", new Integer(1));
729:
730:                for (Iterator it = tags.iterator(); it.hasNext();) {
731:                    TagStat stat = (TagStat) it.next();
732:                    if (!expectedWeblogTags.containsKey(stat.getName()))
733:                        fail("Unexpected tagName.");
734:
735:                    Integer expectedCount = (Integer) expectedWeblogTags
736:                            .get(stat.getName());
737:                    assertEquals(expectedCount.intValue(), stat.getCount());
738:                }
739:
740:                // now add another entry in another blog
741:                entry = TestUtils.setupWeblogEntry("entry3", testWeblog2
742:                        .getDefaultCategory(), testWeblog2, testUser);
743:                entry.addTag("one");
744:                entry.addTag("three");
745:                entry.addTag("four");
746:                mgr.saveWeblogEntry(entry);
747:
748:                // let's fetch "site" tags now
749:                tags = mgr.getTags(null, null, null, -1);
750:                assertEquals(4, tags.size());
751:
752:                HashMap expectedSiteTags = new HashMap();
753:                expectedSiteTags.put("one", new Integer(3));
754:                expectedSiteTags.put("two", new Integer(2));
755:                expectedSiteTags.put("three", new Integer(2));
756:                expectedSiteTags.put("four", new Integer(1));
757:
758:                for (Iterator it = tags.iterator(); it.hasNext();) {
759:                    TagStat stat = (TagStat) it.next();
760:                    if (!expectedSiteTags.containsKey(stat.getName()))
761:                        fail("Unexpected tagName.");
762:
763:                    Integer expectedCount = (Integer) expectedSiteTags.get(stat
764:                            .getName());
765:                    assertEquals(expectedCount.intValue(), stat.getCount());
766:                }
767:
768:                TestUtils.endSession(true);
769:
770:                entry = mgr.getWeblogEntryByAnchor(testWeblog, "entry2");
771:                List updateTags = new ArrayList();
772:                updateTags.add("one");
773:                updateTags.add("three");
774:                updateTags.add("five");
775:                entry.updateTags(updateTags);
776:                mgr.saveWeblogEntry(entry);
777:
778:                TestUtils.endSession(true);
779:
780:                tags = mgr.getTags(testWeblog, null, null, -1);
781:                assertEquals(4, tags.size());
782:
783:                expectedWeblogTags = new HashMap();
784:                expectedWeblogTags.put("one", new Integer(2));
785:                expectedWeblogTags.put("two", new Integer(1));
786:                expectedWeblogTags.put("three", new Integer(1));
787:                expectedWeblogTags.put("five", new Integer(1));
788:
789:                for (Iterator it = tags.iterator(); it.hasNext();) {
790:                    TagStat stat = (TagStat) it.next();
791:                    if (!expectedWeblogTags.containsKey(stat.getName()))
792:                        fail("Unexpected tagName.");
793:
794:                    Integer expectedCount = (Integer) expectedWeblogTags
795:                            .get(stat.getName());
796:                    assertEquals(stat.getName(), expectedCount.intValue(), stat
797:                            .getCount());
798:                }
799:
800:                tags = mgr.getTags(null, null, null, -1);
801:                assertEquals(5, tags.size());
802:
803:                expectedSiteTags = new HashMap();
804:                expectedSiteTags.put("one", new Integer(3));
805:                expectedSiteTags.put("two", new Integer(1));
806:                expectedSiteTags.put("three", new Integer(2));
807:                expectedSiteTags.put("four", new Integer(1));
808:                expectedSiteTags.put("five", new Integer(1));
809:
810:                for (Iterator it = tags.iterator(); it.hasNext();) {
811:                    TagStat stat = (TagStat) it.next();
812:                    if (!expectedSiteTags.containsKey(stat.getName()))
813:                        fail("Unexpected tagName.");
814:
815:                    Integer expectedCount = (Integer) expectedSiteTags.get(stat
816:                            .getName());
817:                    assertEquals(stat.getName(), expectedCount.intValue(), stat
818:                            .getCount());
819:                }
820:
821:                // teardown our test blog 2
822:                TestUtils.teardownWeblog(testWeblog2.getId());
823:                TestUtils.endSession(true);
824:            }
825:
826:            public void testTagAggregatesCaseSensitivity() throws Exception {
827:
828:                WebsiteData testWeblog2 = TestUtils.setupWeblog(
829:                        "entryTestWeblog2", testUser);
830:
831:                WeblogManager mgr = RollerFactory.getRoller()
832:                        .getWeblogManager();
833:
834:                // let's make sure we are starting from scratch
835:
836:                // site-wide
837:                List tags = mgr.getTags(null, null, null, -1);
838:                assertEquals(0, tags.size());
839:
840:                // first weblog
841:                tags = mgr.getTags(testWeblog, null, null, -1);
842:                assertEquals(0, tags.size());
843:
844:                // second weblog
845:                tags = mgr.getTags(testWeblog2, null, null, -1);
846:                assertEquals(0, tags.size());
847:
848:                // setup some test entries to use
849:                WeblogEntryData entry = TestUtils.setupWeblogEntry("entry1",
850:                        testWeblog.getDefaultCategory(), testWeblog, testUser);
851:                entry.addTag("one");
852:                entry.addTag("two");
853:                entry.addTag("ONE");
854:                mgr.saveWeblogEntry(entry);
855:
856:                TestUtils.endSession(true);
857:
858:                tags = mgr.getTags(testWeblog, null, null, -1);
859:                assertEquals(2, tags.size());
860:
861:                HashMap expectedWeblogTags = new HashMap();
862:                expectedWeblogTags.put("one", new Integer(1));
863:                expectedWeblogTags.put("two", new Integer(1));
864:
865:                for (Iterator it = tags.iterator(); it.hasNext();) {
866:                    TagStat stat = (TagStat) it.next();
867:                    if (!expectedWeblogTags.containsKey(stat.getName()))
868:                        fail("Unexpected tagName.");
869:
870:                    Integer expectedCount = (Integer) expectedWeblogTags
871:                            .get(stat.getName());
872:                    assertEquals(expectedCount.intValue(), stat.getCount());
873:                }
874:
875:                // now add another entry in another blog
876:                entry = TestUtils.setupWeblogEntry("entry3", testWeblog2
877:                        .getDefaultCategory(), testWeblog2, testUser);
878:                entry.addTag("ONE");
879:                entry.addTag("three");
880:                mgr.saveWeblogEntry(entry);
881:
882:                // let's fetch "site" tags now
883:                tags = mgr.getTags(null, null, null, -1);
884:                assertEquals(3, tags.size());
885:
886:                HashMap expectedSiteTags = new HashMap();
887:                expectedSiteTags.put("one", new Integer(2));
888:                expectedSiteTags.put("two", new Integer(1));
889:                expectedSiteTags.put("three", new Integer(1));
890:
891:                for (Iterator it = tags.iterator(); it.hasNext();) {
892:                    TagStat stat = (TagStat) it.next();
893:                    if (!expectedSiteTags.containsKey(stat.getName()))
894:                        fail("Unexpected tagName.");
895:
896:                    Integer expectedCount = (Integer) expectedSiteTags.get(stat
897:                            .getName());
898:                    assertEquals(expectedCount.intValue(), stat.getCount());
899:                }
900:
901:                TestUtils.endSession(true);
902:
903:                // teardown our test blog 2
904:                TestUtils.teardownWeblog(testWeblog2.getId());
905:                TestUtils.endSession(true);
906:            }
907:
908:            /**
909:             * Test that we can add and remove entry attributes for an entry.
910:             */
911:            public void testEntryAttributeCRUD() throws Exception {
912:
913:                // TODO: implement entry attribute test
914:            }
915:
916:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.