Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
67   160   6   11,17
0   90   0,09   6
6     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PublishBlogEntryActionTest       Line # 49 67 0% 6 0 100% 1.0
 
  (10)
 
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.web.action;
33   
34    import net.sourceforge.pebble.Constants;
35    import net.sourceforge.pebble.event.response.IpAddressListener;
36    import net.sourceforge.pebble.web.view.View;
37    import net.sourceforge.pebble.web.view.RedirectView;
38    import net.sourceforge.pebble.domain.BlogEntry;
39    import net.sourceforge.pebble.domain.BlogService;
40    import net.sourceforge.pebble.domain.Comment;
41   
42    import java.util.Date;
43   
44    /**
45    * Tests for the PublishBlogEntryAction class.
46    *
47    * @author Simon Brown
48    */
 
49    public class PublishBlogEntryActionTest extends SecureActionTestCase {
50   
 
51  10 toggle protected void setUp() throws Exception {
52  10 action = new PublishBlogEntryAction();
53   
54  10 super.setUp();
55    }
56   
 
57  2 toggle public void testPublishBlogEntryNow() throws Exception {
58  2 BlogService service = new BlogService();
59  2 BlogEntry blogEntry = new BlogEntry(blog);
60  2 blogEntry.setDate(new Date(100000));
61  2 blogEntry.setPublished(false);
62  2 service.putBlogEntry(blogEntry);
63   
64    // now execute the action
65  2 request.setParameter("entry", blogEntry.getId());
66  2 request.setParameter("publishDate", "now");
67  2 request.setParameter("submit", "Publish");
68  2 View view = action.process(request, response);
69   
70  2 blogEntry = (BlogEntry)blog.getRecentBlogEntries(1).get(0);
71  2 assertTrue(blogEntry.isPublished());
72  2 assertEquals(new Date().getTime(), blogEntry.getDate().getTime(), 1000);
73  2 assertTrue(view instanceof RedirectView);
74    }
75   
 
76  2 toggle public void testPublishBlogEntryAsIsAndCheckCommentsStaysIndexed() throws Exception {
77  2 blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1");
78  2 BlogService service = new BlogService();
79  2 BlogEntry blogEntry = new BlogEntry(blog);
80  2 blogEntry.setDate(new Date(100000));
81  2 blogEntry.setPublished(false);
82  2 service.putBlogEntry(blogEntry);
83   
84  2 Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
85  2 blogEntry.addComment(comment);
86  2 service.putBlogEntry(blogEntry);
87   
88  2 String commentId = comment.getGuid();
89  2 assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId));
90   
91    // now execute the action
92  2 request.setParameter("entry", blogEntry.getId());
93  2 request.setParameter("publishDate", "as-is");
94  2 request.setParameter("submit", "Publish");
95  2 View view = action.process(request, response);
96   
97  2 blogEntry = service.getBlogEntry(blog, blogEntry.getId());
98  2 assertTrue(blogEntry.isPublished());
99  2 assertEquals(new Date(100000), blogEntry.getDate());
100   
101    // check that the original comment remains intact
102  2 assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId));
103    }
104   
 
105  2 toggle public void testPublishBlogEntryNowAndCheckCommentsReindexed() throws Exception {
106  2 blog.getPluginProperties().setProperty(IpAddressListener.WHITELIST_KEY, "127.0.0.1");
107  2 BlogService service = new BlogService();
108  2 BlogEntry blogEntry = new BlogEntry(blog);
109  2 blogEntry.setDate(new Date(100000));
110  2 blogEntry.setPublished(false);
111  2 service.putBlogEntry(blogEntry);
112   
113  2 Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
114  2 blogEntry.addComment(comment);
115  2 service.putBlogEntry(blogEntry);
116   
117  2 String commentId = comment.getGuid();
118  2 assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId));
119   
120    // now execute the action
121  2 request.setParameter("entry", blogEntry.getId());
122  2 request.setParameter("publishDate", "now");
123  2 request.setParameter("submit", "Publish");
124  2 View view = action.process(request, response);
125   
126  2 blogEntry = (BlogEntry)blog.getRecentBlogEntries(1).get(0);
127  2 assertTrue(blogEntry.isPublished());
128  2 assertEquals(new Date().getTime(), blogEntry.getDate().getTime(), 1000);
129   
130    // check that the original comment has been unindexed
131  2 assertFalse(blog.getResponseIndex().getApprovedResponses().contains(commentId));
132  2 assertTrue(blog.getResponseIndex().getApprovedResponses().contains(blogEntry.getComments().get(0).getGuid()));
133    }
134   
 
135  2 toggle public void testUnpublishBlogEntry() throws Exception {
136  2 BlogService service = new BlogService();
137  2 BlogEntry blogEntry = new BlogEntry(blog);
138  2 blogEntry.setPublished(true);
139  2 service.putBlogEntry(blogEntry);
140   
141    // now execute the action
142  2 request.setParameter("entry", blogEntry.getId());
143  2 request.setParameter("submit", "Unpublish");
144  2 View view = action.process(request, response);
145   
146  2 blogEntry = service.getBlogEntry(blog, blogEntry.getId());
147  2 assertTrue(blogEntry.isUnpublished());
148  2 assertTrue(view instanceof RedirectView);
149    }
150   
151    /**
152    * Test that only blog owners can approve comments.
153    */
 
154  2 toggle public void testDefaultRoleIsBlogPublisher() {
155  2 String roles[] = action.getRoles(request);
156  2 assertEquals(1, roles.length);
157  2 assertEquals(Constants.BLOG_PUBLISHER_ROLE, roles[0]);
158    }
159   
160    }