| 1 |  |  | 
            
  
    | 2 |  |  | 
            
  
    | 3 |  |  | 
            
  
    | 4 |  |  | 
            
  
    | 5 |  |  | 
            
  
    | 6 |  |  | 
            
  
    | 7 |  |  | 
            
  
    | 8 |  |  | 
            
  
    | 9 |  |  | 
            
  
    | 10 |  |  | 
            
  
    | 11 |  |  | 
            
  
    | 12 |  |  | 
            
  
    | 13 |  |  | 
            
  
    | 14 |  |  | 
            
  
    | 15 |  |  | 
            
  
    | 16 |  |  | 
            
  
    | 17 |  |  | 
            
  
    | 18 |  |  | 
            
  
    | 19 |  |  | 
            
  
    | 20 |  |  | 
            
  
    | 21 |  |  | 
            
  
    | 22 |  |  | 
            
  
    | 23 |  |  | 
            
  
    | 24 |  |  | 
            
  
    | 25 |  |  | 
            
  
    | 26 |  |  | 
            
  
    | 27 |  |  | 
            
  
    | 28 |  |  | 
            
  
    | 29 |  |  | 
            
  
    | 30 |  |  | 
            
  
    | 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 |  |  | 
            
  
    | 44 |  |  | 
            
  
    | 45 |  | @author | 
            
  
    | 46 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (101) | Complexity: 6 | Complexity Density: 0,06 |  | 
  
  
    | 47 |  | public class SaveCommentActionTest extends SingleBlogActionTestCase { | 
            
  
    | 48 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (2) | Complexity: 1 | Complexity Density: 0,5 |  | 
  
  
    | 49 | 10 |  protected void setUp() throws Exception {... | 
            
  
    | 50 | 10 | action = new SaveCommentAction(); | 
            
  
    | 51 |  |  | 
            
  
    | 52 | 10 | super.setUp(); | 
            
  
    | 53 |  | } | 
            
  
    | 54 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (20) | Complexity: 1 | Complexity Density: 0,05 | 1
    PASS |  | 
  
  
    | 55 | 2 |  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 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (24) | Complexity: 1 | Complexity Density: 0,04 | 1
    PASS |  | 
  
  
    | 83 | 2 |  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 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (21) | Complexity: 1 | Complexity Density: 0,05 | 1
    PASS |  | 
  
  
    | 116 | 2 |  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 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (14) | Complexity: 1 | Complexity Density: 0,07 | 1
    PASS |  | 
  
  
    | 145 | 2 |  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 |  |  | 
               
        |  |  | 
           
           |  | 100% | Uncovered Elements: 0 (14) | Complexity: 1 | Complexity Density: 0,07 | 1
    PASS |  | 
  
  
    | 165 | 2 |  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 |  | } |