1 package net.pterodactylus.sone.web;
3 import static net.pterodactylus.util.web.Method.POST;
4 import static org.hamcrest.MatcherAssert.assertThat;
5 import static org.hamcrest.Matchers.is;
6 import static org.mockito.Mockito.mock;
7 import static org.mockito.Mockito.verify;
9 import net.pterodactylus.sone.data.Sone;
11 import com.google.common.base.Optional;
12 import org.junit.Test;
15 * Unit test for {@link CreatePostPage}.
17 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
19 public class CreatePostPageTest extends WebPageTest {
21 private final CreatePostPage page = new CreatePostPage(template, webInterface);
24 public void pageReturnsCorrectPath() {
25 assertThat(page.getPath(), is("createPost.html"));
29 public void returnPageIsSetInTemplateContext() throws Exception {
30 addHttpRequestParameter("returnPage", "returnPage.html");
31 page.processTemplate(freenetRequest, templateContext);
32 assertThat(templateContext.get("returnPage"), is((Object) "returnPage.html"));
36 public void postIsCreatedCorrectly() throws Exception {
37 addHttpRequestParameter("returnPage", "returnPage.html");
38 addHttpRequestParameter("text", "post text");
40 expectedException.expect(WebTestUtils.redirectsTo("returnPage.html"));
42 page.processTemplate(freenetRequest, templateContext);
44 verify(core).createPost(currentSone, Optional.<Sone>absent(), "post text");
49 public void creatingAnEmptyPostIsDenied() throws Exception {
50 addHttpRequestParameter("returnPage", "returnPage.html");
51 addHttpRequestParameter("text", " ");
53 page.processTemplate(freenetRequest, templateContext);
54 assertThat(templateContext.get("errorTextEmpty"), is((Object) true));
58 public void aSenderCanBeSelected() throws Exception {
59 addHttpRequestParameter("returnPage", "returnPage.html");
60 addHttpRequestParameter("text", "post text");
61 addHttpRequestParameter("sender", "sender-id");
62 Sone sender = mock(Sone.class);
63 addLocalSone("sender-id", sender);
65 expectedException.expect(WebTestUtils.redirectsTo("returnPage.html"));
67 page.processTemplate(freenetRequest, templateContext);
69 verify(core).createPost(sender, Optional.<Sone>absent(), "post text");
74 public void aRecipientCanBeSelected() throws Exception {
75 addHttpRequestParameter("returnPage", "returnPage.html");
76 addHttpRequestParameter("text", "post text");
77 addHttpRequestParameter("recipient", "recipient-id");
78 Sone recipient = mock(Sone.class);
79 addSone("recipient-id", recipient);
81 expectedException.expect(WebTestUtils.redirectsTo("returnPage.html"));
83 page.processTemplate(freenetRequest, templateContext);
85 verify(core).createPost(currentSone, Optional.of(recipient), "post text");