1 package net.pterodactylus.sone.web;
3 import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
4 import static org.mockito.Matchers.anyInt;
5 import static org.mockito.Matchers.eq;
6 import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
10 import java.util.Collections;
12 import net.pterodactylus.sone.data.PostReply;
13 import net.pterodactylus.sone.data.Sone;
14 import net.pterodactylus.sone.web.page.FreenetRequest;
15 import net.pterodactylus.util.notify.Notification;
16 import net.pterodactylus.util.template.Template;
17 import net.pterodactylus.util.template.TemplateContext;
18 import net.pterodactylus.util.web.Method;
20 import freenet.support.api.HTTPRequest;
22 import com.google.common.base.Optional;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.rules.ExpectedException;
27 import org.mockito.Matchers;
30 * Unit test for {@link DeleteReplyPage}.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class DeleteReplyPageTest {
37 public final ExpectedException expectedException = ExpectedException.none();
39 private final Template template = new Template();
40 private final WebInterface webInterface = mock(WebInterface.class, RETURNS_DEEP_STUBS);
41 private final DeleteReplyPage page = new DeleteReplyPage(template, webInterface);
42 private final TemplateContext templateContext = new TemplateContext();
43 private final FreenetRequest freenetRequest = mock(FreenetRequest.class);
44 private final HTTPRequest httpRequest = mock(HTTPRequest.class);
47 public void setupWebInterface() {
48 when(webInterface.getNotifications(Matchers.any(Sone.class))).thenReturn(Collections.<Notification>emptyList());
52 public void setupHttpRequest() {
53 when(freenetRequest.getHttpRequest()).thenReturn(httpRequest);
57 public void tryingToDeleteAReplyWithAnInvalidIdResultsInNoPermissionPage() throws Exception {
58 when(freenetRequest.getMethod()).thenReturn(Method.POST);
59 when(httpRequest.getPartAsStringFailsafe(eq("reply"), anyInt())).thenReturn("id");
60 when(webInterface.getCore().getPostReply("id")).thenReturn(Optional.<PostReply>absent());
61 expectedException.expect(redirectsTo("noPermission.html"));
62 page.processTemplate(freenetRequest, templateContext);