Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
95   184   6   15,83
0   117   0,06   6
6     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  SaveCommentActionTest       Line # 47 95 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.domain.BlogEntry;
35    import net.sourceforge.pebble.domain.Comment;
36    import net.sourceforge.pebble.domain.BlogService;
37    import net.sourceforge.pebble.web.view.View;
38    import net.sourceforge.pebble.web.view.impl.CommentConfirmationView;
39    import net.sourceforge.pebble.web.view.impl.ConfirmCommentView;
40    import net.sourceforge.pebble.util.SecurityUtils;
41   
42    /**
43    * Tests for the SaveCommentAction class.
44    *
45    * @author Simon Brown
46    */
 
47    public class SaveCommentActionTest extends SingleBlogActionTestCase {
48   
 
49  10 toggle protected void setUp() throws Exception {
50  10 action = new SaveCommentAction();
51   
52  10 super.setUp();
53    }
54   
 
55  2 toggle public void testProcessAsBlogContributorWhenReplyingToBlogEntry() throws Exception {
56  2 BlogService service = new BlogService();
57  2 BlogEntry blogEntry = new BlogEntry(blog);
58  2 service.putBlogEntry(blogEntry);
59   
60  2 request.setParameter("entry", "" + blogEntry.getId());
61  2 request.setParameter("comment", "");
62  2 request.setParameter("title", "Test Title");
63  2 request.setParameter("commentBody", "Test Body");
64  2 request.setParameter("author", "Test Author");
65  2 request.setParameter("website", "http://www.somedomain.com");
66  2 request.setParameter("submit", "Add Comment");
67   
68  2 SecurityUtils.runAsBlogContributor();
69   
70  2 View view = action.process(request, response);
71  2 assertTrue(view instanceof CommentConfirmationView);
72   
73  2 blogEntry = service.getBlogEntry(blog, blogEntry.getId());
74  2 assertEquals(1, blogEntry.getComments().size());
75   
76  2 Comment comment = blogEntry.getComments().get(0);
77  2 assertEquals("Test Title", comment.getTitle());
78  2 assertEquals("Test Body", comment.getBody());
79  2 assertEquals("Test Author", comment.getAuthor());
80  2 assertEquals("http://www.somedomain.com", comment.getWebsite());
81    }
82   
 
83  2 toggle public void testProcessAsBlogContributorWhenReplyingToComment() throws Exception {
84  2 BlogService service = new BlogService();
85  2 BlogEntry blogEntry = new BlogEntry(blog);
86  2 service.putBlogEntry(blogEntry);
87   
88  2 Comment comment1 = blogEntry.createComment("Title", "Body", "Author", "me@somedomain.com", "http://www.google.com", "127.0.0.1");
89  2 blogEntry.addComment(comment1);
90  2 service.putBlogEntry(blogEntry);
91   
92  2 request.setParameter("entry", "" + blogEntry.getId());
93  2 request.setParameter("comment", "" + comment1.getId());
94  2 request.setParameter("title", "Test Title");
95  2 request.setParameter("commentBody", "Test Body");
96  2 request.setParameter("author", "Test Author");
97  2 request.setParameter("website", "http://www.somedomain.com");
98  2 request.setParameter("submit", "Add Comment");
99   
100  2 SecurityUtils.runAsBlogContributor();
101   
102  2 View view = action.process(request, response);
103  2 assertTrue(view instanceof CommentConfirmationView);
104   
105  2 blogEntry = service.getBlogEntry(blog, blogEntry.getId());
106  2 assertEquals(2, blogEntry.getComments().size());
107   
108  2 Comment comment2 = blogEntry.getComments().get(1);
109  2 assertEquals("Test Title", comment2.getTitle());
110  2 assertEquals("Test Body", comment2.getBody());
111  2 assertEquals("Test Author", comment2.getAuthor());
112  2 assertEquals("http://www.somedomain.com", comment2.getWebsite());
113  2 assertEquals(comment1.getId(), comment2.getParent().getId());
114    }
115   
 
116  2 toggle public void testProcessAsBlogContributorWhenReplyingToCommentThatDoesntExist() throws Exception {
117  2 BlogService service = new BlogService();
118  2 BlogEntry blogEntry = new BlogEntry(blog);
119  2 service.putBlogEntry(blogEntry);
120   
121  2 request.setParameter("entry", "" + blogEntry.getId());
122  2 request.setParameter("comment", "123456789");
123  2 request.setParameter("title", "Test Title");
124  2 request.setParameter("commentBody", "Test Body");
125  2 request.setParameter("author", "Test Author");
126  2 request.setParameter("website", "http://www.somedomain.com");
127  2 request.setParameter("submit", "Add Comment");
128   
129  2 SecurityUtils.runAsBlogContributor();
130   
131  2 View view = action.process(request, response);
132  2 assertTrue(view instanceof CommentConfirmationView);
133   
134  2 blogEntry = service.getBlogEntry(blog, blogEntry.getId());
135  2 assertEquals(1, blogEntry.getComments().size());
136   
137  2 Comment comment = blogEntry.getComments().get(0);
138  2 assertEquals("Test Title", comment.getTitle());
139  2 assertEquals("Test Body", comment.getBody());
140  2 assertEquals("Test Author", comment.getAuthor());
141  2 assertEquals("http://www.somedomain.com", comment.getWebsite());
142  2 assertNull(comment.getParent());
143    }
144   
 
145  2 toggle public void testProcessAsAnonymousUser() throws Exception {
146  2 BlogService service = new BlogService();
147  2 BlogEntry blogEntry = new BlogEntry(blog);
148  2 service.putBlogEntry(blogEntry);
149   
150  2 request.setParameter("entry", "" + blogEntry.getId());
151  2 request.setParameter("comment", "");
152  2 request.setParameter("title", "Test Title");
153  2 request.setParameter("commentBody", "Test Body");
154  2 request.setParameter("author", "Test Author");
155  2 request.setParameter("website", "http://www.somedomain.com");
156  2 request.setParameter("submit", "Add Comment");
157   
158  2 SecurityUtils.runAsAnonymous();
159   
160  2 View view = action.process(request, response);
161  2 assertTrue(view instanceof ConfirmCommentView);
162  2 assertEquals(0, blogEntry.getComments().size());
163    }
164   
 
165  2 toggle public void testProcessWhenCommentsDisabled() throws Exception {
166  2 BlogService service = new BlogService();
167  2 BlogEntry blogEntry = new BlogEntry(blog);
168  2 blogEntry.setCommentsEnabled(false);
169  2 service.putBlogEntry(blogEntry);
170   
171  2 request.setParameter("entry", "" + blogEntry.getId());
172  2 request.setParameter("comment", "");
173  2 request.setParameter("title", "Test Title");
174  2 request.setParameter("commentBody", "Test Body");
175  2 request.setParameter("author", "Test Author");
176  2 request.setParameter("website", "Test Website");
177  2 request.setParameter("submit", "Add Comment");
178   
179  2 View view = action.process(request, response);
180  2 assertTrue(view instanceof CommentConfirmationView);
181  2 assertEquals(0, blogEntry.getComments().size());
182    }
183   
184    }