Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
130   258   4   32,5
0   168   0,03   4
4     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  RelatedPostsDecoratorTest       Line # 48 130 0% 4 0 100% 1.0
 
  (6)
 
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.decorator;
33   
34    import java.util.Date;
35    import net.sourceforge.pebble.domain.Blog;
36    import net.sourceforge.pebble.domain.BlogService;
37    import net.sourceforge.pebble.domain.BlogEntry;
38    import net.sourceforge.pebble.domain.Category;
39    import net.sourceforge.pebble.domain.SingleBlogTestCase;
40    import net.sourceforge.pebble.api.decorator.ContentDecorator;
41    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
42   
43    /**
44    * Tests for the SocialBookmarksDecorator class.
45    *
46    * @author Alexander Zagniotov
47    */
 
48    public class RelatedPostsDecoratorTest extends SingleBlogTestCase {
49   
50    private ContentDecorator decorator;
51    private BlogEntry blogEntryOne;
52    private BlogEntry blogEntryTwo;
53    private BlogEntry blogEntryThree;
54    private BlogEntry blogEntryFour;
55    private BlogEntry blogEntryFive;
56    private BlogEntry blogEntrySix;
57    private BlogEntry blogEntrySeven;
58    private BlogEntry blogEntryEight;
59    private BlogService service;
60    private ContentDecoratorContext context;
61   
 
62  6 toggle protected void setUp() throws Exception {
63  6 super.setUp();
64   
65    // default for RelatedPostsDecorator.MAX_POSTS is 5
66  6 blog.getPluginProperties().setProperty(RelatedPostsDecorator.MAX_POSTS, "6");
67   
68  6 blogEntryOne = new BlogEntry(blog);
69  6 blogEntryTwo = new BlogEntry(blog);
70  6 blogEntryThree = new BlogEntry(blog);
71  6 blogEntryFour = new BlogEntry(blog);
72  6 blogEntryFive = new BlogEntry(blog);
73  6 blogEntrySix = new BlogEntry(blog);
74  6 blogEntrySeven = new BlogEntry(blog);
75  6 blogEntryEight = new BlogEntry(blog);
76   
77  6 service = new BlogService();
78   
79  6 decorator = new RelatedPostsDecorator();
80  6 context = new ContentDecoratorContext();
81    }
82   
83    /**
84    * Tests that a blog entry has no related posts when output to a HTML page.
85    */
 
86  2 toggle public void testBlogEntryNoRelatedPostsAndMediaIsHtml() throws Exception {
87   
88  2 context.setMedia(ContentDecoratorContext.HTML_PAGE);
89   
90  2 blogEntryOne.setTitle("Title - title one");
91  2 blogEntryOne.setExcerpt("Excerpt - except one");
92  2 blogEntryOne.setBody("Body - body one");
93  2 blogEntryOne.setTags("one two");
94  2 service.putBlogEntry(blogEntryOne);
95   
96  2 blogEntryTwo.setTitle("Title - title two");
97  2 blogEntryTwo.setExcerpt("Excerpt - except two");
98  2 blogEntryTwo.setBody("Body - body two");
99  2 blogEntryTwo.setTags("one two");
100  2 service.putBlogEntry(blogEntryTwo);
101   
102  2 blogEntryThree.setTitle("Title - title three");
103  2 blogEntryThree.setExcerpt("Excerpt - except three");
104  2 blogEntryThree.setBody("Body - body three");
105  2 blogEntryThree.setTags("three");
106  2 service.putBlogEntry(blogEntryThree);
107   
108  2 decorator.decorate(context, blogEntryThree);
109   
110  2 StringBuffer relatedPosts = new StringBuffer();
111  2 relatedPosts.append("<p><b>Related Posts</b><br />");
112  2 relatedPosts.append("<i>There are no related posts for this blog entry</i>");
113  2 relatedPosts.append("</p><br />");
114   
115  2 assertEquals("Body - body three" + relatedPosts, blogEntryThree.getBody());
116    }
117   
118    /**
119    * Tests that a blog entry has several related posts when output to a HTML
120    * page.
121    */
 
122  2 toggle public void testBlogEntryWithRelatedPostsAndMediaIsHtml() throws Exception {
123   
124  2 context.setMedia(ContentDecoratorContext.HTML_PAGE);
125   
126  2 Date date = new Date();
127  2 long now = 1;
128  2 date.setTime(now);
129   
130  2 blogEntryOne.setDate(date);
131  2 blogEntryOne.setTitle("Title - title one");
132  2 blogEntryOne.setExcerpt("Excerpt - except one");
133  2 blogEntryOne.setBody("Body - body one");
134  2 blogEntryOne.setTags("one, two");
135  2 service.putBlogEntry(blogEntryOne);
136   
137  2 blogEntryTwo.setDate(date);
138  2 blogEntryTwo.setTitle("Title - title two");
139  2 blogEntryTwo.setExcerpt("Excerpt - except two");
140  2 blogEntryTwo.setBody("Body - body two");
141  2 blogEntryTwo.setTags("one, two");
142  2 service.putBlogEntry(blogEntryTwo);
143   
144  2 blogEntryThree.setDate(date);
145  2 blogEntryThree.setTitle("Title - title three");
146  2 blogEntryThree.setExcerpt("Excerpt - except three");
147  2 blogEntryThree.setBody("Body - body three");
148  2 blogEntryThree.setTags("two, three");
149  2 service.putBlogEntry(blogEntryThree);
150   
151  2 decorator.decorate(context, blogEntryThree);
152   
153  2 StringBuffer relatedPosts = new StringBuffer();
154  2 relatedPosts.append("<p><b>Related Posts</b><br />");
155  2 relatedPosts
156    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/2.html\" rel=\"bookmark\" title=\"Title - title two\">Title - title two</a><br />");
157  2 relatedPosts
158    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/1.html\" rel=\"bookmark\" title=\"Title - title one\">Title - title one</a><br />");
159  2 relatedPosts.append("</p><br />");
160   
161  2 assertEquals("Body - body three" + relatedPosts, blogEntryThree.getBody());
162   
163  2 service.removeBlogEntry(blogEntryOne);
164  2 service.removeBlogEntry(blogEntryTwo);
165  2 service.removeBlogEntry(blogEntryThree);
166   
167    }
168   
169    /**
170    * Tests that a blog entry has maximum of six (6) related posts when output to
171    * a HTML page.
172    */
 
173  2 toggle public void testBlogEntryMaximumSixRelatedPostsAndMediaIsHtml() throws Exception {
174   
175  2 context.setMedia(ContentDecoratorContext.HTML_PAGE);
176   
177  2 Date date = new Date();
178  2 long now = 1;
179  2 date.setTime(now);
180   
181  2 blogEntryOne.setDate(date);
182  2 blogEntryOne.setTitle("Title - title one");
183  2 blogEntryOne.setExcerpt("Excerpt - except one");
184  2 blogEntryOne.setBody("Body - body one");
185  2 blogEntryOne.setTags("one");
186  2 service.putBlogEntry(blogEntryOne);
187   
188  2 blogEntryTwo.setDate(date);
189  2 blogEntryTwo.setTitle("Title - title two");
190  2 blogEntryTwo.setExcerpt("Excerpt - except two");
191  2 blogEntryTwo.setBody("Body - body two");
192  2 blogEntryTwo.setTags("one, two");
193  2 service.putBlogEntry(blogEntryTwo);
194   
195  2 blogEntryThree.setDate(date);
196  2 blogEntryThree.setTitle("Title - title three");
197  2 blogEntryThree.setExcerpt("Excerpt - except three");
198  2 blogEntryThree.setBody("Body - body three");
199  2 blogEntryThree.setTags("one, two, three");
200  2 service.putBlogEntry(blogEntryThree);
201   
202  2 blogEntryFour.setDate(date);
203  2 blogEntryFour.setTitle("Title - title four");
204  2 blogEntryFour.setExcerpt("Excerpt - except four");
205  2 blogEntryFour.setBody("Body - body four");
206  2 blogEntryFour.setTags("one, two, three, four");
207  2 service.putBlogEntry(blogEntryFour);
208   
209  2 blogEntryFive.setDate(date);
210  2 blogEntryFive.setTitle("Title - title five");
211  2 blogEntryFive.setExcerpt("Excerpt - except five");
212  2 blogEntryFive.setBody("Body - body five");
213  2 blogEntryFive.setTags("one, two, three, four, five");
214  2 service.putBlogEntry(blogEntryFive);
215   
216  2 blogEntrySix.setDate(date);
217  2 blogEntrySix.setTitle("Title - title six");
218  2 blogEntrySix.setExcerpt("Excerpt - except six");
219  2 blogEntrySix.setBody("Body - body six");
220  2 blogEntrySix.setTags("one, two, three, four, five, six");
221  2 service.putBlogEntry(blogEntrySix);
222   
223  2 blogEntrySeven.setDate(date);
224  2 blogEntrySeven.setTitle("Title - title seven");
225  2 blogEntrySeven.setExcerpt("Excerpt - except seven");
226  2 blogEntrySeven.setBody("Body - body seven");
227  2 blogEntrySeven.setTags("one, two, three, four, five, six, seven");
228  2 service.putBlogEntry(blogEntrySeven);
229   
230  2 blogEntryEight.setDate(date);
231  2 blogEntryEight.setTitle("Title - title eight");
232  2 blogEntryEight.setExcerpt("Excerpt - except eight");
233  2 blogEntryEight.setBody("Body - body eight");
234  2 blogEntryEight.setTags("one, two, three, four, five, six, seven, eight");
235  2 service.putBlogEntry(blogEntryEight);
236   
237  2 decorator.decorate(context, blogEntryOne);
238   
239  2 StringBuffer relatedPosts = new StringBuffer();
240  2 relatedPosts.append("<p><b>Related Posts</b><br />");
241  2 relatedPosts
242    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/8.html\" rel=\"bookmark\" title=\"Title - title eight\">Title - title eight</a><br />");
243  2 relatedPosts
244    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/7.html\" rel=\"bookmark\" title=\"Title - title seven\">Title - title seven</a><br />");
245  2 relatedPosts
246    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/6.html\" rel=\"bookmark\" title=\"Title - title six\">Title - title six</a><br />");
247  2 relatedPosts
248    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/5.html\" rel=\"bookmark\" title=\"Title - title five\">Title - title five</a><br />");
249  2 relatedPosts
250    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/4.html\" rel=\"bookmark\" title=\"Title - title four\">Title - title four</a><br />");
251  2 relatedPosts
252    .append("<a href=\"http://www.yourdomain.com/blog/1970/01/01/3.html\" rel=\"bookmark\" title=\"Title - title three\">Title - title three</a><br />");
253  2 relatedPosts.append("</p><br />");
254   
255  2 assertEquals("Body - body one" + relatedPosts, blogEntryOne.getBody());
256    }
257   
258    }