Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
61   150   5   12,2
0   79   0,08   5
5     1  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  HideUnapprovedResponsesDecoratorTest       Line # 44 61 0% 5 0 100% 1.0
 
  (8)
 
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 net.sourceforge.pebble.domain.*;
35    import net.sourceforge.pebble.util.SecurityUtils;
36    import net.sourceforge.pebble.api.decorator.ContentDecorator;
37    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
38   
39    /**
40    * Tests for the HideUnapprovedResponsesDecorator class.
41    *
42    * @author Simon Brown
43    */
 
44    public class HideUnapprovedResponsesDecoratorTest extends SingleBlogTestCase {
45   
46    private ContentDecorator decorator;
47   
 
48  8 toggle protected void setUp() throws Exception {
49  8 super.setUp();
50   
51  8 decorator = new HideUnapprovedResponsesDecorator();
52    }
53   
54    /**
55    * Tests that unapproved comments and TrackBacks are removed.
56    */
 
57  2 toggle public void testUnapprovedResponsesRemovedWhenNotLoggedIn() throws Exception {
58  2 BlogEntry blogEntry = new BlogEntry(blog);
59  2 Comment comment1 = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
60  2 comment1.setPending();
61  2 blogEntry.addComment(comment1);
62  2 Comment comment2 = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
63  2 comment2.setApproved();
64  2 blogEntry.addComment(comment2);
65   
66  2 TrackBack trackBack1 = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1");
67  2 trackBack1.setPending();
68  2 blogEntry.addTrackBack(trackBack1);
69  2 TrackBack trackBack2 = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1");
70  2 trackBack2.setApproved();
71  2 blogEntry.addTrackBack(trackBack2);
72   
73  2 SecurityUtils.runAsAnonymous();
74   
75  2 ContentDecoratorContext context = new ContentDecoratorContext();
76  2 decorator.decorate(context, blogEntry);
77  2 assertEquals(1, blogEntry.getComments().size());
78  2 assertEquals(1, blogEntry.getTrackBacks().size());
79   
80  2 assertSame(comment2, blogEntry.getComments().get(0));
81  2 assertSame(trackBack2, blogEntry.getTrackBacks().get(0));
82    }
83   
84    /**
85    * Tests that unapproved comments and TrackBacks are removed when logged in,
86    * but not a blog contributor.
87    */
 
88  2 toggle public void testUnapprovedResponsesRemovedWhenLoggedIn() throws Exception {
89  2 BlogEntry blogEntry = new BlogEntry(blog);
90  2 Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
91  2 comment.setPending();
92  2 blogEntry.addComment(comment);
93   
94  2 TrackBack trackBack = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1");
95  2 trackBack.setPending();
96  2 blogEntry.addTrackBack(trackBack);
97   
98  2 SecurityUtils.runAsBlogContributor();
99  2 blog.setProperty(Blog.BLOG_CONTRIBUTORS_KEY, "some_contributor");
100   
101  2 ContentDecoratorContext context = new ContentDecoratorContext();
102  2 decorator.decorate(context, blogEntry);
103  2 assertEquals(0, blogEntry.getComments().size());
104  2 assertEquals(0, blogEntry.getTrackBacks().size());
105    }
106   
107    /**
108    * Tests that unapproved comments and TrackBacks are not removed.
109    */
 
110  2 toggle public void testUnapprovedResponsesNotRemovedWhenLoggedIn() throws Exception {
111  2 BlogEntry blogEntry = new BlogEntry(blog);
112  2 Comment comment = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
113  2 comment.setPending();
114  2 blogEntry.addComment(comment);
115   
116  2 TrackBack trackBack = blogEntry.createTrackBack("title", "excerpt", "url", "blogName", "127.0.0.1");
117  2 trackBack.setPending();
118  2 blogEntry.addTrackBack(trackBack);
119   
120  2 ContentDecoratorContext context = new ContentDecoratorContext();
121   
122  2 SecurityUtils.runAsBlogContributor();
123   
124  2 decorator.decorate(context, blogEntry);
125  2 assertEquals(1, blogEntry.getComments().size());
126  2 assertEquals(1, blogEntry.getTrackBacks().size());
127    }
128   
 
129  2 toggle public void testUnapprovedNestedResponsesRemovedWhenNotLoggedIn() throws Exception {
130  2 BlogEntry blogEntry = new BlogEntry(blog);
131  2 Comment comment1 = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
132  2 comment1.setPending();
133  2 blogEntry.addComment(comment1);
134   
135  2 Comment comment2 = blogEntry.createComment("title", "body", "author", "email", "website", "127.0.0.1");
136  2 comment2.setPending();
137  2 comment2.setParent(comment1);
138  2 blogEntry.addComment(comment2);
139   
140  2 SecurityUtils.runAsAnonymous();
141   
142  2 blogEntry = (BlogEntry)blogEntry.clone();
143   
144  2 ContentDecoratorContext context = new ContentDecoratorContext();
145  2 decorator.decorate(context, blogEntry);
146  2 assertEquals(0, blogEntry.getComments().size());
147  2 assertEquals(0, blogEntry.getTrackBacks().size());
148    }
149   
150    }