| 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.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 |
|
|
| 46 |
|
|
| 47 |
|
@author |
| 48 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (73) |
Complexity: 6 |
Complexity Density: 0,09 |
|
| 49 |
|
public class PublishBlogEntryActionTest extends SecureActionTestCase { |
| 50 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 51 |
10
|
protected void setUp() throws Exception {... |
| 52 |
10
|
action = new PublishBlogEntryAction(); |
| 53 |
|
|
| 54 |
10
|
super.setUp(); |
| 55 |
|
} |
| 56 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0,08 |
1
PASS
|
|
| 57 |
2
|
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 |
|
|
| 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 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 1 |
Complexity Density: 0,05 |
1
PASS
|
|
| 76 |
2
|
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 |
|
|
| 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 |
|
|
| 102 |
2
|
assertTrue(blog.getResponseIndex().getApprovedResponses().contains(commentId)); |
| 103 |
|
} |
| 104 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 1 |
Complexity Density: 0,05 |
1
PASS
|
|
| 105 |
2
|
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 |
|
|
| 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 |
|
|
| 131 |
2
|
assertFalse(blog.getResponseIndex().getApprovedResponses().contains(commentId)); |
| 132 |
2
|
assertTrue(blog.getResponseIndex().getApprovedResponses().contains(blogEntry.getComments().get(0).getGuid())); |
| 133 |
|
} |
| 134 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 135 |
2
|
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 |
|
|
| 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 |
|
|
| 153 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1
PASS
|
|
| 154 |
2
|
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 |
|
} |