| 1 |
|
package net.sourceforge.pebble.web.action; |
| 2 |
|
|
| 3 |
|
import net.sourceforge.pebble.web.view.View; |
| 4 |
|
import net.sourceforge.pebble.web.view.NotFoundView; |
| 5 |
|
import net.sourceforge.pebble.web.view.impl.BlogEntryView; |
| 6 |
|
import net.sourceforge.pebble.Constants; |
| 7 |
|
import net.sourceforge.pebble.util.SecurityUtils; |
| 8 |
|
import net.sourceforge.pebble.domain.BlogEntry; |
| 9 |
|
import net.sourceforge.pebble.domain.BlogService; |
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
@author |
| 15 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (43) |
Complexity: 6 |
Complexity Density: 0,16 |
|
| 16 |
|
public class ViewBlogEntryActionTest extends SingleBlogActionTestCase { |
| 17 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
|
| 18 |
10
|
protected void setUp() throws Exception {... |
| 19 |
10
|
action = new ViewBlogEntryAction(); |
| 20 |
|
|
| 21 |
10
|
super.setUp(); |
| 22 |
|
} |
| 23 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0,5 |
1
PASS
|
|
| 24 |
2
|
public void testViewBlogEntryWithNullId() throws Exception {... |
| 25 |
2
|
View view = action.process(request, response); |
| 26 |
|
|
| 27 |
2
|
assertTrue(view instanceof NotFoundView); |
| 28 |
|
} |
| 29 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0,33 |
1
PASS
|
|
| 30 |
2
|
public void testViewNonExistentBlogEntry() throws Exception {... |
| 31 |
2
|
request.setParameter("entry", "1234567890123"); |
| 32 |
2
|
View view = action.process(request, response); |
| 33 |
|
|
| 34 |
2
|
assertTrue(view instanceof NotFoundView); |
| 35 |
|
} |
| 36 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 37 |
2
|
public void testPublishedViewBlogEntry() throws Exception {... |
| 38 |
2
|
BlogEntry blogEntry1 = new BlogEntry(blog); |
| 39 |
2
|
blogEntry1.setPublished(true); |
| 40 |
2
|
BlogService service = new BlogService(); |
| 41 |
2
|
service.putBlogEntry(blogEntry1); |
| 42 |
|
|
| 43 |
2
|
SecurityUtils.runAsUnauthenticated(); |
| 44 |
2
|
request.setParameter("entry", blogEntry1.getId()); |
| 45 |
2
|
View view = action.process(request, response); |
| 46 |
|
|
| 47 |
2
|
BlogEntry blogEntry2 = (BlogEntry)action.getModel().get(Constants.BLOG_ENTRY_KEY); |
| 48 |
2
|
assertEquals(blogEntry1.getId(), blogEntry2.getId()); |
| 49 |
2
|
assertTrue(view instanceof BlogEntryView); |
| 50 |
|
} |
| 51 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 52 |
2
|
public void testUnpublishedViewBlogEntryAsAnonymousUser() throws Exception {... |
| 53 |
2
|
BlogEntry blogEntry1 = new BlogEntry(blog); |
| 54 |
2
|
blogEntry1.setPublished(false); |
| 55 |
2
|
BlogService service = new BlogService(); |
| 56 |
2
|
service.putBlogEntry(blogEntry1); |
| 57 |
|
|
| 58 |
2
|
SecurityUtils.runAsAnonymous(); |
| 59 |
2
|
request.setParameter("entry", blogEntry1.getId()); |
| 60 |
2
|
View view = action.process(request, response); |
| 61 |
|
|
| 62 |
2
|
BlogEntry blogEntry2 = (BlogEntry)action.getModel().get(Constants.BLOG_ENTRY_KEY); |
| 63 |
2
|
assertNull(blogEntry2); |
| 64 |
2
|
assertTrue(view instanceof NotFoundView); |
| 65 |
|
} |
| 66 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 1 |
Complexity Density: 0,1 |
1
PASS
|
|
| 67 |
2
|
public void testUnpublishedViewBlogEntryAsUserThatIsAuthorisedForBlog() throws Exception {... |
| 68 |
2
|
BlogEntry blogEntry1 = new BlogEntry(blog); |
| 69 |
2
|
blogEntry1.setPublished(false); |
| 70 |
2
|
BlogService service = new BlogService(); |
| 71 |
2
|
service.putBlogEntry(blogEntry1); |
| 72 |
|
|
| 73 |
2
|
SecurityUtils.runAsBlogContributor(); |
| 74 |
2
|
request.setParameter("entry", blogEntry1.getId()); |
| 75 |
2
|
View view = action.process(request, response); |
| 76 |
|
|
| 77 |
2
|
BlogEntry blogEntry2 = (BlogEntry)action.getModel().get(Constants.BLOG_ENTRY_KEY); |
| 78 |
2
|
assertEquals(blogEntry1.getId(), blogEntry2.getId()); |
| 79 |
2
|
assertTrue(view instanceof BlogEntryView); |
| 80 |
|
} |
| 81 |
|
|
| 82 |
|
} |