Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
533   992   53   10,06
0   649   0,1   53
53     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  BlogEntryTest       Line # 43 533 0% 53 0 100% 1.0
 
  (104)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble.domain;
33   
34    import java.beans.PropertyChangeEvent;
35    import java.text.DecimalFormat;
36    import java.util.*;
37   
38    /**
39    * Tests for the BlogEntry class.
40    *
41    * @author Simon Brown
42    */
 
43    public class BlogEntryTest extends SingleBlogTestCase {
44   
45    private BlogEntry blogEntry;
46   
 
47  104 toggle protected void setUp() throws Exception {
48  104 super.setUp();
49  104 blogEntry = new BlogEntry(blog);
50  104 blogEntry.setTitle("A title");
51  104 blogEntry.setBody("Some body");
52  104 blogEntry.setExcerpt("Some excerpt");
53  104 blogEntry.setAuthor("An author");
54  104 blogEntry.setDate(new Date());
55  104 blogEntry.setEventsEnabled(true);
56    }
57   
58    /**
59    * Tests the construction.
60    */
 
61  2 toggle public void testConstruction() {
62  2 assertNotNull(blogEntry.getId());
63  2 assertEquals("A title", blogEntry.getTitle());
64  2 assertEquals("Some body", blogEntry.getBody());
65   
66  2 assertNotNull(blogEntry.getCategories());
67  2 assertEquals(0, blogEntry.getCategories().size());
68  2 assertTrue(blogEntry.isCommentsEnabled());
69  2 assertNotNull(blogEntry.getComments());
70  2 assertEquals(0, blogEntry.getComments().size());
71  2 assertNotNull(blogEntry.getTrackBacks());
72  2 assertEquals(0, blogEntry.getTrackBacks().size());
73   
74  2 assertNotNull(blogEntry.getDate());
75  2 assertNotNull(blogEntry.getAuthor());
76  2 assertFalse(blogEntry.isAggregated());
77  2 assertNotNull(blogEntry.getTags());
78  2 assertEquals(0, blogEntry.getTagsAsList().size());
79    }
80   
81    /**
82    * Tests that the root blog is setup correctly.
83    */
 
84  2 toggle public void testGetRootBlog() {
85  2 assertEquals(blog, blogEntry.getBlog());
86    }
87   
88    /**
89    * Tests that the root is setup correctly.
90    */
 
91  2 toggle public void testDay() {
92    //assertEquals(dailyBlog, blogEntry.getDay());
93    }
94   
95    /**
96    * Tests for the id.
97    */
 
98  2 toggle public void testId() {
99  2 String id = "" + blogEntry.getDate().getTime();
100  2 assertEquals(id, blogEntry.getId());
101    }
102   
103    /**
104    * Tests for the title.
105    */
 
106  2 toggle public void testTitle() {
107  2 blogEntry.setTitle("A new title");
108  2 assertEquals("A new title", blogEntry.getTitle());
109    }
110   
111    /**
112    * Tests for the subtitle.
113    */
 
114  2 toggle public void testSubtitle() {
115  2 blogEntry.setSubtitle("A new subtitle");
116  2 assertEquals("A new subtitle", blogEntry.getSubtitle());
117    }
118   
119    /**
120    * Tests for the body.
121    */
 
122  2 toggle public void testBody() {
123  2 blogEntry.setBody("A new body");
124  2 assertEquals("A new body", blogEntry.getBody());
125    }
126   
127    /**
128    * Tests for the excerpt.
129    */
 
130  2 toggle public void testExcerpt() {
131  2 blogEntry.setExcerpt("An excerpt");
132  2 assertEquals("An excerpt", blogEntry.getExcerpt());
133    }
134   
135    /**
136    * Tests for the categories.
137    */
 
138  2 toggle public void testCategories() {
139  2 assertEquals(0, blogEntry.getCategories().size());
140   
141  2 Category category = new Category("1", "One");
142  2 blogEntry.addCategory(category);
143  2 assertEquals(1, blogEntry.getCategories().size());
144  2 assertTrue(blogEntry.getCategories().contains(category));
145   
146    // just check that we can't add null categories!
147  2 blogEntry.addCategory(null);
148  2 assertFalse(blogEntry.getCategories().contains(null));
149    }
150   
151    /**
152    * Tests for the "in category" check.
153    */
 
154  2 toggle public void testInCategory() {
155  2 CategoryBuilder builder = new CategoryBuilder(blog);
156  2 Category apple = new Category("/apple", "Apple");
157  2 Category java = new Category("/java", "Java");
158  2 Category junit = new Category("/java/junit", "JUnit");
159  2 builder.addCategory(apple);
160  2 builder.addCategory(java);
161  2 builder.addCategory(junit);
162   
163  2 blogEntry.addCategory(apple);
164  2 assertTrue(blogEntry.inCategory(apple));
165  2 assertFalse(blogEntry.inCategory(java));
166  2 assertFalse(blogEntry.inCategory(junit));
167  2 assertTrue(blogEntry.inCategory(null));
168   
169  2 blogEntry.addCategory(junit);
170  2 assertTrue(blogEntry.inCategory(apple));
171  2 assertTrue(blogEntry.inCategory(java));
172  2 assertTrue(blogEntry.inCategory(junit));
173    }
174   
175    /**
176    * Tests that all categories can be removed.
177    */
 
178  2 toggle public void testAllCategoriesCanBeRemoved() {
179  2 CategoryBuilder builder = new CategoryBuilder(blog);
180  2 Category apple = new Category("/apple", "Apple");
181  2 Category java = new Category("/java", "Java");
182  2 Category junit = new Category("/java/junit", "JUnit");
183  2 builder.addCategory(apple);
184  2 builder.addCategory(java);
185  2 builder.addCategory(junit);
186   
187  2 blogEntry.addCategory(apple);
188  2 blogEntry.addCategory(junit);
189   
190  2 blogEntry.removeAllCategories();
191  2 assertEquals(0, blogEntry.getCategories().size());
192    }
193   
194    /**
195    * Tests for the tags.
196    */
 
197  2 toggle public void testTagsSeparatedByCommas() {
198  2 blogEntry.setTags("some, tags");
199  2 assertEquals("some tags", blogEntry.getTags());
200  2 List tags = blogEntry.getTagsAsList();
201  2 assertEquals(2, tags.size());
202  2 assertEquals(blog.getTag("some"), tags.get(0));
203  2 assertEquals(blog.getTag("tags"), tags.get(1));
204    }
205   
206    /**
207    * Tests for the tags.
208    */
 
209  2 toggle public void testTagsSeparatedByWhitespace() {
210  2 blogEntry.setTags("some tags");
211  2 assertEquals("some tags", blogEntry.getTags());
212  2 List tags = blogEntry.getTagsAsList();
213  2 assertEquals(2, tags.size());
214  2 assertEquals(blog.getTag("some"), tags.get(0));
215  2 assertEquals(blog.getTag("tags"), tags.get(1));
216    }
217   
218    /**
219    * Tests for the date.
220    */
 
221  2 toggle public void testDate() {
222  2 assertNotNull(blogEntry.getDate());
223    }
224   
225    /**
226    * Tests for the author.
227    */
 
228  2 toggle public void testAuthor() {
229  2 blogEntry.setAuthor("A new author");
230  2 assertEquals("A new author", blogEntry.getAuthor());
231    }
232   
233    /**
234    * Tests the aggregated property.
235    */
 
236  2 toggle public void testAggregated() {
237  2 blogEntry.setOriginalPermalink("http://www.simongbrown.com/blog/2003/04/01.html#a123456789");
238  2 assertTrue(blogEntry.isAggregated());
239   
240  2 blogEntry.setOriginalPermalink(null);
241  2 assertFalse(blogEntry.isAggregated());
242   
243  2 blogEntry.setOriginalPermalink("");
244  2 assertFalse(blogEntry.isAggregated());
245    }
246   
247    /**
248    * Tests the comments enabled property.
249    */
 
250  2 toggle public void testCommentsEnabled() {
251  2 assertTrue(blogEntry.isCommentsEnabled());
252  2 blogEntry.setCommentsEnabled(false);
253  2 assertFalse(blogEntry.isCommentsEnabled());
254    }
255   
256    /**
257    * Tests the links that will refer to a blog entry and its comments.
258    */
 
259  2 toggle public void testLinks() {
260  2 DecimalFormat format = new DecimalFormat("00");
261  2 Calendar cal = blog.getCalendar();
262  2 cal.setTime(blogEntry.getDate());
263  2 int year = cal.get(Calendar.YEAR);
264  2 int month = cal.get(Calendar.MONTH) + 1;
265  2 int day = cal.get(Calendar.DAY_OF_MONTH);
266  2 assertEquals("http://www.yourdomain.com/blog/" +
267    year + "/" + format.format(month) + "/" + format.format(day) + "/" +
268    blogEntry.getId() + ".html", blogEntry.getPermalink());
269  2 assertEquals("http://www.yourdomain.com/blog/" +
270    year + "/" + format.format(month) + "/" + format.format(day) + "/" +
271    blogEntry.getId() + ".html", blogEntry.getLocalPermalink());
272  2 assertEquals(blogEntry.getLocalPermalink() + "#comments", blogEntry.getCommentsLink());
273  2 assertEquals(blogEntry.getLocalPermalink() + "#trackbacks" , blogEntry.getTrackBacksLink());
274    }
275   
276    /**
277    * Tests that a blog entry can correctly manage blog comments.
278    */
 
279  2 toggle public void testComments() {
280  2 Comment blogComment1, blogComment2;
281  2 Calendar cal1, cal2;
282  2 cal1 = blog.getCalendar();
283  2 cal1.set(Calendar.DAY_OF_MONTH, 1);
284  2 cal2 = blog.getCalendar();
285  2 cal2.set(Calendar.DAY_OF_MONTH, 2);
286   
287    // check that there are no comments to start with
288  2 assertEquals(0, blogEntry.getNumberOfComments());
289  2 assertEquals(0, blogEntry.getComments().size());
290   
291    // now create a new comment
292  2 blogComment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", cal1.getTime(), State.APPROVED);
293  2 assertNotNull(blogComment1);
294  2 assertEquals("Re: " + blogEntry.getTitle(), blogComment1.getTitle());
295  2 assertEquals("Body", blogComment1.getBody());
296  2 assertEquals("Author", blogComment1.getAuthor());
297  2 assertEquals("http://www.google.com", blogComment1.getWebsite());
298  2 assertNotNull(blogComment1.getDate());
299  2 assertEquals(blogEntry, blogComment1.getBlogEntry());
300   
301    // the comment hasn't been added yet
302  2 assertEquals(0, blogEntry.getNumberOfComments());
303  2 assertEquals(0, blogEntry.getComments().size());
304  2 assertFalse(blogEntry.getComments().contains(blogComment1));
305   
306    // let's now add the comment
307  2 blogEntry.addComment(blogComment1);
308  2 assertEquals(1, blogEntry.getNumberOfComments());
309  2 assertEquals(1, blogEntry.getComments().size());
310  2 assertTrue(blogEntry.getComments().contains(blogComment1));
311   
312    // and now add another comment
313  2 blogComment2 = blogEntry.createComment("Title 2", "Body 2", "Author 2", "me2@somedomain.com", "http://www.yahoo.com", "127.0.0.1", cal2.getTime(), State.APPROVED);
314  2 assertEquals("Title 2", blogComment2.getTitle());
315  2 assertEquals(1, blogEntry.getNumberOfComments());
316  2 assertTrue(blogEntry.getComments().contains(blogComment1));
317  2 assertFalse(blogEntry.getComments().contains(blogComment2));
318  2 blogEntry.addComment(blogComment2);
319  2 assertEquals(2, blogEntry.getNumberOfComments());
320  2 assertEquals(2, blogEntry.getComments().size());
321  2 assertTrue(blogEntry.getComments().contains(blogComment1));
322  2 assertTrue(blogEntry.getComments().contains(blogComment2));
323   
324    // check that we can't add the same comment more than once
325  2 blogEntry.addComment(blogComment2);
326  2 assertEquals(2, blogEntry.getNumberOfComments());
327   
328    // and now delete the comments
329  2 blogEntry.removeComment(blogComment1.getId());
330  2 assertFalse(blogEntry.getComments().contains(blogComment1));
331  2 assertTrue(blogEntry.getComments().contains(blogComment2));
332  2 assertEquals(1, blogEntry.getNumberOfComments());
333  2 blogEntry.removeComment(blogComment2.getId());
334  2 assertFalse(blogEntry.getComments().contains(blogComment1));
335  2 assertFalse(blogEntry.getComments().contains(blogComment2));
336  2 assertEquals(0, blogEntry.getNumberOfComments());
337    }
338   
339    /**
340    * Tests that a blog entry can correctly manage blog comments when two are
341    * added at the same time.
342    */
 
343  2 toggle public void testTwoCommentsAddedAtTheSameTime() {
344  2 Comment blogComment1, blogComment2;
345  2 blogComment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
346  2 blogComment2 = (Comment)blogComment1.clone();
347  2 assertEquals(blogComment1.getId(), blogComment2.getId());
348  2 blogEntry.addComment(blogComment1);
349  2 assertEquals(1, blogEntry.getNumberOfComments());
350  2 assertEquals(1, blogEntry.getComments().size());
351  2 assertTrue(blogEntry.getComments().contains(blogComment1));
352  2 blogEntry.addComment(blogComment2);
353  2 assertEquals(2, blogEntry.getNumberOfComments());
354  2 assertEquals(2, blogEntry.getComments().size());
355  2 assertTrue(blogEntry.getComments().contains(blogComment1));
356  2 assertTrue(blogEntry.getComments().contains(blogComment2));
357    }
358   
359    /**
360    * Tests that nested comments can be accessed.
361    */
 
362  2 toggle public void testNestedComments() {
363  2 Comment comment1, comment2;
364  2 Date date1 = new Date(0);
365  2 Date date2 = new Date(1000);
366   
367  2 comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED);
368  2 blogEntry.addComment(comment1);
369   
370  2 comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED);
371  2 comment2.setParent(comment1);
372  2 blogEntry.addComment(comment2);
373   
374  2 assertEquals(2, blogEntry.getComments().size());
375  2 assertEquals(comment1, blogEntry.getComments().get(0));
376  2 assertEquals(comment2, blogEntry.getComments().get(1));
377   
378  2 assertEquals(comment1, blogEntry.getComment(comment1.getId()));
379  2 assertEquals(comment2, blogEntry.getComment(comment2.getId()));
380    }
381   
382    /**
383    * Tests that the number of comments reported is correct when some of those
384    * comments are nested.
385    */
 
386  2 toggle public void testNumberOfCommentsCorrectWhenNestedCommentsPresent() {
387  2 Comment comment1, comment2;
388  2 Calendar cal1, cal2;
389  2 cal1 = blog.getCalendar();
390  2 cal1.set(Calendar.DAY_OF_MONTH, 1);
391  2 cal2 = blog.getCalendar();
392  2 cal2.set(Calendar.DAY_OF_MONTH, 2);
393   
394  2 comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", cal1.getTime(), State.APPROVED);
395  2 blogEntry.addComment(comment1);
396   
397  2 comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", cal2.getTime(), State.APPROVED);
398  2 comment2.setParent(comment1);
399  2 blogEntry.addComment(comment2);
400   
401  2 assertEquals(2, blogEntry.getNumberOfComments());
402    }
403   
404    /**
405    * Tests that removing a comment also removes all of its children.
406    */
 
407  2 toggle public void testRemovingCommentRemovesAllChildren() {
408  2 Comment comment1, comment2;
409  2 Date date1 = new Date(0);
410  2 Date date2 = new Date(1000);
411   
412  2 comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED);
413  2 blogEntry.addComment(comment1);
414   
415  2 comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED);
416  2 comment2.setParent(comment1);
417  2 blogEntry.addComment(comment2);
418   
419    // now remove the top-level comment, and hopefully all of its children
420  2 blogEntry.removeComment(comment1.getId());
421  2 assertEquals(0, blogEntry.getNumberOfComments());
422    }
423   
424    /**
425    * Tests that a nested comment can be removed.
426    */
 
427  2 toggle public void testNestedCommentCanBeRemoved() {
428  2 Comment comment1, comment2;
429  2 Date date1 = new Date(0);
430  2 Date date2 = new Date(1000);
431   
432  2 comment1 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date1, State.APPROVED);
433  2 blogEntry.addComment(comment1);
434   
435  2 comment2 = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", date2, State.APPROVED);
436  2 comment2.setParent(comment1);
437  2 blogEntry.addComment(comment2);
438   
439    // now remove the nested comment
440  2 blogEntry.removeComment(comment2.getId());
441  2 assertEquals(1, blogEntry.getNumberOfComments());
442  2 assertNull(blogEntry.getComment(comment2.getId()));
443    }
444   
445    /**
446    * Tests that the permalink for a comment is correctly set.
447    */
 
448  2 toggle public void testCommentPermalink() {
449  2 Comment blogComment;
450   
451  2 blogComment = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
452  2 blogEntry.addComment(blogComment);
453  2 assertEquals(blogEntry.getLocalPermalink() + "#comment" + blogComment.getId(), blogComment.getPermalink());
454    }
455   
456    /**
457    * Tests that a blog entry can correctly manage trackbacks.
458    */
 
459  2 toggle public void testTrackBacks() {
460    // check that there are no trackbacks to start with
461  2 assertEquals(0, blogEntry.getNumberOfTrackBacks());
462  2 assertEquals(0, blogEntry.getTrackBacks().size());
463    }
464   
465    /**
466    * Tests that a blog entry is cloneable.
467    */
 
468  2 toggle public void testCloneableNormalBlogEntry() {
469  2 blogEntry.setTitle("An old title");
470  2 blogEntry.setSubtitle("An old subtitle");
471  2 blogEntry.setBody("An old body");
472  2 blogEntry.setAuthor("An old author");
473  2 blogEntry.setPersistent(true);
474  2 blogEntry.setCommentsEnabled(false);
475  2 blogEntry.setTrackBacksEnabled(false);
476  2 blogEntry.setTimeZoneId("Europe/Paris");
477   
478  2 Category category1 = blog.getCategory("/testCategory1");
479  2 Category category2 = blog.getCategory("/testCategory2");
480  2 Category category3 = blog.getCategory("/testCategory3");
481  2 blogEntry.addCategory(category1);
482  2 blogEntry.addCategory(category2);
483  2 blogEntry.setTags("some+tag");
484   
485  2 BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone();
486   
487  2 assertEquals(blogEntry.getTitle(), clonedBlogEntry.getTitle());
488  2 assertEquals(blogEntry.getSubtitle(), clonedBlogEntry.getSubtitle());
489  2 assertEquals(blogEntry.getBody(), clonedBlogEntry.getBody());
490  2 assertEquals(blogEntry.getAuthor(), clonedBlogEntry.getAuthor());
491  2 assertEquals(blogEntry.getPermalink(), clonedBlogEntry.getPermalink());
492  2 assertEquals(blogEntry.inCategory(category1), clonedBlogEntry.inCategory(category1));
493  2 assertEquals(blogEntry.inCategory(category2), clonedBlogEntry.inCategory(category2));
494  2 assertEquals(blogEntry.inCategory(category3), clonedBlogEntry.inCategory(category3));
495  2 assertEquals("some+tag", clonedBlogEntry.getTags());
496  2 assertEquals(blogEntry.isPersistent(), clonedBlogEntry.isPersistent());
497  2 assertFalse(clonedBlogEntry.isCommentsEnabled());
498  2 assertFalse(clonedBlogEntry.isTrackBacksEnabled());
499  2 assertNull(clonedBlogEntry.getAttachment());
500  2 assertEquals(blogEntry.getTimeZoneId(), clonedBlogEntry.getTimeZoneId());
501    }
502   
503    /**
504    * Tests that a blog entry is cloneable.
505    */
 
506  2 toggle public void testCloneableAggregatedBlogEntry() {
507  2 blogEntry.setTitle("An old title");
508  2 blogEntry.setBody("An old body");
509  2 blogEntry.setAuthor("An old author");
510  2 blogEntry.setOriginalPermalink("An old alternative permalink");
511   
512  2 Category category1 = blog.getCategory("/testCategory1");
513  2 Category category2 = blog.getCategory("/testCategory2");
514  2 Category category3 = blog.getCategory("/testCategory3");
515  2 blogEntry.addCategory(category1);
516  2 blogEntry.addCategory(category2);
517   
518  2 BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone();
519   
520  2 assertEquals(blogEntry.getTitle(), clonedBlogEntry.getTitle());
521  2 assertEquals(blogEntry.getBody(), clonedBlogEntry.getBody());
522  2 assertEquals(blogEntry.getAuthor(), clonedBlogEntry.getAuthor());
523  2 assertEquals(blogEntry.getOriginalPermalink(), clonedBlogEntry.getOriginalPermalink());
524  2 assertEquals(blogEntry.inCategory(category1), clonedBlogEntry.inCategory(category1));
525  2 assertEquals(blogEntry.inCategory(category2), clonedBlogEntry.inCategory(category2));
526  2 assertEquals(blogEntry.inCategory(category3), clonedBlogEntry.inCategory(category3));
527  2 assertNull(clonedBlogEntry.getAttachment());
528    }
529   
 
530  2 toggle public void testTopLevelCommentsClonedProperly() {
531  2 Comment comment = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
532  2 blogEntry.addComment(comment);
533   
534  2 BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone();
535  2 Comment clonedComment = clonedBlogEntry.getComments().get(0);
536  2 assertSame(clonedBlogEntry, clonedComment.getBlogEntry());
537   
538    }
539   
 
540  2 toggle public void testNestedCommentsClonedProperly() {
541  2 Comment comment1 = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
542  2 blogEntry.addComment(comment1);
543  2 Comment comment2 = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
544  2 comment2.setParent(comment1);
545  2 blogEntry.addComment(comment2);
546   
547  2 BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone();
548  2 Comment clonedComment1 = clonedBlogEntry.getComments().get(0);
549  2 Comment clonedComment2 = clonedBlogEntry.getComments().get(1);
550  2 assertSame(clonedComment1, clonedComment2.getParent());
551  2 assertSame(clonedBlogEntry, clonedComment1.getBlogEntry());
552  2 assertSame(clonedBlogEntry, clonedComment2.getBlogEntry());
553    }
554   
555    // todo
556    // public void testValidationForStaticPage() {
557    // blogEntry.setType(BlogEntry.STATIC_PAGE);
558    //
559    // ValidationContext context = new ValidationContext();
560    // blogEntry.validate(context);
561    // assertTrue("Name shouldn't be empty", context.hasErrors());
562    //
563    // context = new ValidationContext();
564    // blogEntry.setStaticName("someStoryName");
565    // blogEntry.validate(context);
566    // assertFalse(context.hasErrors());
567    //
568    // context = new ValidationContext();
569    // blogEntry.setStaticName("2004/someStoryName");
570    // blogEntry.validate(context);
571    // assertFalse(context.hasErrors());
572    //
573    // context = new ValidationContext();
574    // blogEntry.setStaticName("some-story-name");
575    // blogEntry.validate(context);
576    // assertFalse(context.hasErrors());
577    //
578    // context = new ValidationContext();
579    // blogEntry.setStaticName("someStoryName.html");
580    // blogEntry.validate(context);
581    // assertTrue("Name shouldn't contain punctuation", context.hasErrors());
582    // }
583   
584    /**
585    * Tests that the next blog entry can be accessed.
586    */
 
587  2 toggle public void testGetNextBlogEntry() throws Exception {
588  2 BlogService service = new BlogService();
589  2 Day today = blog.getBlogForToday();
590  2 Day oneDayAgo = today.getPreviousDay();
591  2 Day twoDaysAgo = today.getPreviousDay().getPreviousDay();
592   
593  2 BlogEntry b1 = new BlogEntry(blog);
594  2 b1.setDate(twoDaysAgo.getDate());
595  2 b1.setPublished(true);
596   
597  2 BlogEntry b2 = new BlogEntry(blog);
598  2 b2.setDate(oneDayAgo.getDate());
599  2 b2.setPublished(true);
600   
601  2 BlogEntry b3 = new BlogEntry(blog);
602  2 b3.setDate(today.getDate());
603  2 b3.setPublished(true);
604   
605  2 service.putBlogEntry(b1);
606  2 service.putBlogEntry(b2);
607  2 service.putBlogEntry(b3);
608   
609  2 assertNull(b3.getNextBlogEntry());
610  2 assertEquals(b3, b2.getNextBlogEntry());
611  2 assertEquals(b2, b1.getNextBlogEntry());
612    }
613   
614    /**
615    * Tests that the previous blog entry can be accessed.
616    */
 
617  2 toggle public void testGetPreviousBlogEntry() throws Exception {
618  2 BlogService service = new BlogService();
619  2 Day today = blog.getBlogForToday();
620  2 Day oneDayAgo = today.getPreviousDay();
621  2 Day twoDaysAgo = today.getPreviousDay().getPreviousDay();
622   
623  2 BlogEntry b1 = new BlogEntry(blog);
624  2 b1.setDate(twoDaysAgo.getDate());
625  2 b1.setPublished(true);
626   
627  2 BlogEntry b2 = new BlogEntry(blog);
628  2 b2.setDate(oneDayAgo.getDate());
629  2 b2.setPublished(true);
630   
631  2 BlogEntry b3 = new BlogEntry(blog);
632  2 b3.setDate(today.getDate());
633  2 b3.setPublished(true);
634   
635  2 service.putBlogEntry(b1);
636  2 service.putBlogEntry(b2);
637  2 service.putBlogEntry(b3);
638   
639  2 assertNull(b1.getPreviousBlogEntry());
640  2 assertEquals(b1, b2.getPreviousBlogEntry());
641  2 assertEquals(b2, b3.getPreviousBlogEntry());
642    }
643   
644    /**
645    * Tests for a blog entry attachment.
646    */
 
647  2 toggle public void testAttachment() {
648  2 Attachment a = new Attachment("url", 1024, "image/jpeg");
649  2 blogEntry.setAttachment(a);
650  2 assertEquals(a, blogEntry.getAttachment());
651   
652  2 BlogEntry clonedBlogEntry = (BlogEntry)blogEntry.clone();
653  2 assertEquals(a, clonedBlogEntry.getAttachment());
654    }
655   
656    // todo
657    // public void testPermalinkForStaticPage() {
658    // blogEntry.setType(BlogEntry.STATIC_PAGE);
659    // blogEntry.setStaticName("SomePage");
660    // assertEquals("http://www.yourdomain.com/blog/pages/SomePage.html", blogEntry.getPermalink());
661    // }
662   
663    /**
664    * Tests that listeners are not fired when a comment is added/removed on a clone.
665    */
 
666  2 toggle public void testCommentListenersNotFiredFromClone() {
667  2 final Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
668  2 blogEntry = (BlogEntry)blogEntry.clone();
669  2 blogEntry.addComment(comment);
670  2 assertTrue(blogEntry.getEvents().isEmpty());
671    }
672   
673    /**
674    * Tests that listeners are not fired when a TrackBack is added/removed on a clone.
675    */
 
676  2 toggle public void testTrackBackListenersNotFiredFromClone() {
677  2 final TrackBack trackBack = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1");
678  2 blogEntry = (BlogEntry)blogEntry.clone();
679  2 blogEntry.addTrackBack(trackBack);
680  2 blogEntry.removeTrackBack(trackBack.getId());
681  2 assertTrue(blogEntry.getEvents().isEmpty());
682    }
683   
 
684  2 toggle public void testPropertyChangedEventsNotFiredWhenEventsDisabled() {
685  2 assertFalse(blogEntry.isDirty());
686  2 blogEntry.setEventsEnabled(false);
687  2 blogEntry.setBody("New body");
688  2 assertFalse(blogEntry.isDirty());
689    }
690   
 
691  2 toggle public void testPropertyChangedEventsFiredForBodyProperty() {
692  2 assertFalse(blogEntry.isDirty());
693   
694  2 blogEntry.setBody(blogEntry.getBody());
695  2 assertFalse(blogEntry.isDirty());
696   
697  2 blogEntry.setBody("New body");
698  2 assertTrue(blogEntry.isDirty());
699  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
700  2 assertEquals(blogEntry, event.getSource());
701  2 assertEquals(BlogEntry.BODY_PROPERTY, event.getPropertyName());
702  2 assertEquals("Some body", event.getOldValue());
703  2 assertEquals("New body", event.getNewValue());
704    }
705   
 
706  2 toggle public void testPropertyChangedEventsFiredForExcerptProperty() {
707  2 assertFalse(blogEntry.isDirty());
708   
709  2 blogEntry.setExcerpt(blogEntry.getExcerpt());
710  2 assertFalse(blogEntry.isDirty());
711   
712  2 blogEntry.setExcerpt("New excerpt");
713  2 assertTrue(blogEntry.isDirty());
714  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
715  2 assertEquals(blogEntry, event.getSource());
716  2 assertEquals(BlogEntry.EXCERPT_PROPERTY, event.getPropertyName());
717  2 assertEquals("Some excerpt", event.getOldValue());
718  2 assertEquals("New excerpt", event.getNewValue());
719    }
720   
 
721  2 toggle public void testPropertyChangedEventsFiredForTitleProperty() {
722  2 assertFalse(blogEntry.isDirty());
723   
724  2 blogEntry.setTitle(blogEntry.getTitle());
725  2 assertFalse(blogEntry.isDirty());
726   
727  2 blogEntry.setTitle("New title");
728  2 assertTrue(blogEntry.isDirty());
729  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
730  2 assertEquals(blogEntry, event.getSource());
731  2 assertEquals(BlogEntry.TITLE_PROPERTY, event.getPropertyName());
732  2 assertEquals("A title", event.getOldValue());
733  2 assertEquals("New title", event.getNewValue());
734    }
735   
 
736  2 toggle public void testPropertyChangedEventsNotFiredForAuthorProperty() {
737  2 assertFalse(blogEntry.isDirty());
738   
739  2 blogEntry.setAuthor(blogEntry.getAuthor());
740  2 assertFalse(blogEntry.isDirty());
741   
742  2 blogEntry.setAuthor("New author");
743  2 assertFalse(blogEntry.isDirty());
744    //PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
745    //assertEquals(blogEntry, event.getSource());
746    //assertEquals(BlogEntry.AUTHOR_PROPERTY, event.getPropertyName());
747    //assertEquals("An author", event.getOldValue());
748    //assertEquals("New author", event.getNewValue());
749    }
750   
 
751  2 toggle public void testPropertyChangedEventsFiredForOriginalPermalinkProperty() {
752  2 assertFalse(blogEntry.isDirty());
753   
754  2 blogEntry.setOriginalPermalink(null);
755  2 assertFalse(blogEntry.isDirty());
756   
757  2 blogEntry.setOriginalPermalink("New permalink");
758  2 assertTrue(blogEntry.isDirty());
759  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
760  2 assertEquals(blogEntry, event.getSource());
761  2 assertEquals(BlogEntry.ORIGINAL_PERMALINK_PROPERTY, event.getPropertyName());
762  2 assertNull(event.getOldValue());
763  2 assertEquals("New permalink", event.getNewValue());
764   
765  2 blogEntry.clearPropertyChangeEvents();
766  2 blogEntry.setOriginalPermalink(blogEntry.getOriginalPermalink());
767  2 assertFalse(blogEntry.isDirty());
768    }
769   
 
770  2 toggle public void testPropertyChangedEventsFiredForAttachmentProperty() {
771  2 assertFalse(blogEntry.isDirty());
772   
773  2 blogEntry.setAttachment(null);
774  2 assertFalse(blogEntry.isDirty());
775   
776  2 Attachment newAttachment = new Attachment("url", 1234, "image/jpeg");
777  2 blogEntry.setAttachment(newAttachment);
778  2 assertTrue(blogEntry.isDirty());
779  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
780  2 assertEquals(blogEntry, event.getSource());
781  2 assertEquals(BlogEntry.ATTACHMENT_PROPERTY, event.getPropertyName());
782  2 assertNull(event.getOldValue());
783  2 assertEquals(newAttachment, event.getNewValue());
784   
785  2 blogEntry.clearPropertyChangeEvents();
786  2 blogEntry.setAttachment(newAttachment);
787  2 assertFalse(blogEntry.isDirty());
788    }
789   
 
790  2 toggle public void testPropertyChangedEventsFiredForCommentsEnabledProperty() {
791  2 assertFalse(blogEntry.isDirty());
792   
793  2 blogEntry.setCommentsEnabled(true);
794  2 assertFalse(blogEntry.isDirty());
795   
796  2 blogEntry.setCommentsEnabled(false);
797  2 assertTrue(blogEntry.isDirty());
798  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
799  2 assertEquals(blogEntry, event.getSource());
800  2 assertEquals(BlogEntry.COMMENTS_ENABLED_PROPERTY, event.getPropertyName());
801  2 assertEquals(Boolean.TRUE, event.getOldValue());
802  2 assertEquals(Boolean.FALSE, event.getNewValue());
803    }
804   
 
805  2 toggle public void testPropertyChangedEventsFiredForTrackBacksEnabledProperty() {
806  2 assertFalse(blogEntry.isDirty());
807   
808  2 blogEntry.setTrackBacksEnabled(true);
809  2 assertFalse(blogEntry.isDirty());
810   
811  2 blogEntry.setTrackBacksEnabled(false);
812  2 assertTrue(blogEntry.isDirty());
813  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
814  2 assertEquals(blogEntry, event.getSource());
815  2 assertEquals(BlogEntry.TRACKBACKS_ENABLED_PROPERTY, event.getPropertyName());
816  2 assertEquals(Boolean.TRUE, event.getOldValue());
817  2 assertEquals(Boolean.FALSE, event.getNewValue());
818    }
819   
 
820  2 toggle public void testPropertyChangedEventsFiredForCategoriesProperty() {
821  2 assertFalse(blogEntry.isDirty());
822   
823  2 blogEntry.removeAllCategories();
824  2 assertFalse(blogEntry.isDirty());
825   
826  2 Category c1 = new Category("/c1", "Category 1");
827  2 blog.addCategory(c1);
828  2 Category c2 = new Category("/c2", "Category 2");
829  2 blog.addCategory(c1);
830  2 blogEntry.addCategory(c1);
831  2 assertTrue(blogEntry.isDirty());
832  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
833  2 assertEquals(blogEntry, event.getSource());
834  2 assertEquals(BlogEntry.CATEGORIES_PROPERTY, event.getPropertyName());
835  2 assertTrue(((Set)event.getOldValue()).isEmpty());
836  2 assertTrue(((Set)event.getNewValue()).contains(c1));
837   
838  2 blogEntry.clearPropertyChangeEvents();
839  2 blogEntry.addCategory(c2);
840  2 assertTrue(blogEntry.isDirty());
841  2 event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
842  2 assertEquals(blogEntry, event.getSource());
843  2 assertEquals(BlogEntry.CATEGORIES_PROPERTY, event.getPropertyName());
844  2 assertTrue(((Set)event.getOldValue()).contains(c1));
845  2 assertTrue(((Set)event.getNewValue()).contains(c1));
846  2 assertTrue(((Set)event.getNewValue()).contains(c2));
847   
848  2 blogEntry.removeAllCategories();
849  2 blogEntry.clearPropertyChangeEvents();
850  2 Set categories = new HashSet();
851  2 categories.add(c1);
852  2 categories.add(c2);
853  2 blogEntry.setCategories(categories);
854  2 assertTrue(blogEntry.isDirty());
855  2 event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
856  2 assertEquals(blogEntry, event.getSource());
857  2 assertEquals(BlogEntry.CATEGORIES_PROPERTY, event.getPropertyName());
858  2 assertTrue(((Set)event.getOldValue()).isEmpty());
859  2 assertTrue(((Set)event.getNewValue()).contains(c1));
860  2 assertTrue(((Set)event.getNewValue()).contains(c2));
861   
862  2 blogEntry.clearPropertyChangeEvents();
863  2 categories = new HashSet();
864  2 categories.add(c2);
865  2 blogEntry.setCategories(categories);
866  2 assertTrue(blogEntry.isDirty());
867  2 event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
868  2 assertEquals(blogEntry, event.getSource());
869  2 assertEquals(BlogEntry.CATEGORIES_PROPERTY, event.getPropertyName());
870  2 assertTrue(((Set)event.getOldValue()).contains(c1));
871  2 assertTrue(((Set)event.getOldValue()).contains(c2));
872  2 assertTrue(((Set)event.getNewValue()).contains(c2));
873    }
874   
 
875  2 toggle public void testPropertyChangedEventsFiredForTagsProperty() {
876  2 assertFalse(blogEntry.isDirty());
877   
878  2 blogEntry.setTags(blogEntry.getTags());
879  2 assertFalse(blogEntry.isDirty());
880   
881  2 blogEntry.setTags("some tags");
882  2 assertTrue(blogEntry.isDirty());
883  2 PropertyChangeEvent event = (PropertyChangeEvent)blogEntry.getPropertyChangeEvents().get(0);
884  2 assertEquals(blogEntry, event.getSource());
885  2 assertEquals(BlogEntry.TAGS_PROPERTY, event.getPropertyName());
886  2 assertEquals("", event.getOldValue());
887  2 assertEquals("some tags", event.getNewValue());
888    }
889   
890    /**
891    * Tests that all tags can be retrieved.
892    */
 
893  2 toggle public void testGetAllTags() {
894  2 CategoryBuilder builder = new CategoryBuilder(blog);
895  2 Category apple = new Category("/apple", "Apple");
896  2 Category java = new Category("/java", "Java");
897  2 Category junit = new Category("/java/junit", "JUnit");
898  2 builder.getRootCategory().setTags("myblog");
899  2 builder.addCategory(apple);
900  2 apple.setTags("apple");
901  2 builder.addCategory(java);
902  2 java.setTags("java");
903  2 builder.addCategory(junit);
904  2 junit.setTags("junit automated+testing");
905   
906  2 blogEntry.addCategory(apple);
907  2 blogEntry.addCategory(junit);
908  2 blogEntry.setTags("entry+specific+tag");
909   
910  2 List tags = blogEntry.getAllTags();
911  2 assertTrue(tags.contains(blog.getTag("entry+specific+tag")));
912  2 assertTrue(tags.contains(blog.getTag("junit")));
913  2 assertTrue(tags.contains(blog.getTag("automated+testing")));
914  2 assertTrue(tags.contains(blog.getTag("java")));
915  2 assertTrue(tags.contains(blog.getTag("apple")));
916  2 assertTrue(tags.contains(blog.getTag("myblog")));
917    }
918   
919    /**
920    * Tests that all tags can be retrieved, even when the blog entry
921    * hasn't been associated with any categories.
922    */
 
923  2 toggle public void testGetAllTagsWhenNotAssociatedWithACategory() {
924  2 CategoryBuilder builder = new CategoryBuilder(blog);
925  2 builder.getRootCategory().setTags("myblog");
926  2 blog.setRootCategory(builder.getRootCategory());
927   
928  2 List tags = blogEntry.getAllTags();
929  2 assertEquals(blog.getTag("myblog"), tags.get(0));
930    }
931   
932    /**
933    * Tests the hasTag() method.
934    */
 
935  2 toggle public void testHasTag() {
936  2 CategoryBuilder builder = new CategoryBuilder(blog);
937  2 Category apple = new Category("/apple", "Apple");
938  2 Category java = new Category("/java", "Java");
939  2 Category junit = new Category("/java/junit", "JUnit");
940  2 builder.getRootCategory().setTags("myblog");
941  2 builder.addCategory(apple);
942  2 apple.setTags("apple");
943  2 builder.addCategory(java);
944  2 java.setTags("java");
945  2 builder.addCategory(junit);
946  2 junit.setTags("junit automated+testing");
947   
948  2 assertFalse(blogEntry.hasTag(null));
949  2 assertFalse(blogEntry.hasTag(""));
950  2 assertFalse(blogEntry.hasTag("java"));
951   
952  2 blogEntry.setTags("entryspecifictag");
953  2 assertTrue(blogEntry.hasTag("entryspecifictag"));
954   
955  2 blogEntry.addCategory(apple);
956  2 assertTrue(blogEntry.hasTag("apple"));
957  2 blogEntry.addCategory(junit);
958  2 assertTrue(blogEntry.hasTag("junit"));
959    }
960   
 
961  2 toggle public void testLastModifiedDate() {
962  2 blogEntry.setDate(new Date(100));
963  2 blogEntry.addComment(blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", new Date(123), State.APPROVED));
964  2 blogEntry.addComment(blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", new Date(456), State.APPROVED));
965  2 blogEntry.addComment(blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", new Date(789), State.APPROVED));
966   
967  2 assertEquals(new Date(789), blogEntry.getLastModified());
968   
969  2 blogEntry.addTrackBack(blogEntry.createTrackBack("Title", "Excerpt", "http://www.somedomain.com", "Some blog", "127.0.0.1", new Date(123), State.APPROVED));
970  2 blogEntry.addTrackBack(blogEntry.createTrackBack("Title", "Excerpt", "http://www.somedomain.com", "Some blog", "127.0.0.1", new Date(543), State.APPROVED));
971  2 blogEntry.addTrackBack(blogEntry.createTrackBack("Title", "Excerpt", "http://www.somedomain.com", "Some blog", "127.0.0.1", new Date(987), State.APPROVED));
972   
973  2 assertEquals(new Date(987), blogEntry.getLastModified());
974    }
975   
 
976  2 toggle public void testRemoveCommentViaRemoveResponse() {
977  2 Comment comment = blogEntry.createComment("", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1", new Date(123), State.APPROVED);
978  2 blogEntry.addComment(comment);
979  2 assertEquals(1, blogEntry.getNumberOfComments());
980  2 blogEntry.removeResponse(comment);
981  2 assertEquals(0, blogEntry.getNumberOfComments());
982    }
983   
 
984  2 toggle public void testRemoveTrackBackViaRemoveResponse() {
985  2 TrackBack trackBack = blogEntry.createTrackBack("Title", "Excerpt", "http://www.somedomain.com", "Some blog", "127.0.0.1", new Date(123), State.APPROVED);
986  2 blogEntry.addTrackBack(trackBack);
987  2 assertEquals(1, blogEntry.getNumberOfTrackBacks());
988  2 blogEntry.removeResponse(trackBack);
989  2 assertEquals(0, blogEntry.getNumberOfTrackBacks());
990    }
991   
992    }