1 package net.pterodactylus.sone.web;
3 import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo;
4 import static org.mockito.Matchers.any;
5 import static org.mockito.Matchers.anyInt;
6 import static org.mockito.Matchers.eq;
7 import static org.mockito.Mockito.mock;
8 import static org.mockito.Mockito.when;
12 import net.pterodactylus.sone.core.Core;
13 import net.pterodactylus.sone.core.UpdateChecker;
14 import net.pterodactylus.sone.data.Album;
15 import net.pterodactylus.sone.data.Sone;
16 import net.pterodactylus.sone.web.page.FreenetRequest;
17 import net.pterodactylus.util.template.Template;
18 import net.pterodactylus.util.template.TemplateContext;
19 import net.pterodactylus.util.web.Method;
21 import freenet.clients.http.ToadletContext;
22 import freenet.support.api.HTTPRequest;
24 import org.junit.Before;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
30 * Unit test for {@link UploadImagePageTest}.
32 * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
34 public class UploadImagePageTest {
37 public final ExpectedException expectedException = ExpectedException.none();
39 private final Template template = new Template();
40 private final WebInterface webInterface = mock(WebInterface.class);
41 private final UploadImagePage uploadImagePage = new UploadImagePage(template, webInterface);
43 private final TemplateContext templateContext = new TemplateContext();
44 private final HTTPRequest httpRequest = mock(HTTPRequest.class);
45 private final ToadletContext toadletContext = mock(ToadletContext.class);
46 private final Core core = mock(Core.class);
47 private final Sone currentSone = mock(Sone.class);
48 private final Album parentAlbum = mock(Album.class);
51 public void setupWebInterface() {
52 UpdateChecker updateChecker = mock(UpdateChecker.class);
53 when(core.getUpdateChecker()).thenReturn(updateChecker);
54 when(webInterface.getCore()).thenReturn(core);
55 when(webInterface.getCurrentSone(any(ToadletContext.class))).thenReturn(currentSone);
59 public void setupParentAlbum() {
60 when(core.getAlbum("parent-id")).thenReturn(parentAlbum);
61 when(parentAlbum.getSone()).thenReturn(currentSone);
65 public void uploadingAnImageWithoutTitleRedirectsToEmptyImageTitlePage() throws Exception {
66 FreenetRequest request = new FreenetRequest(new URI(""), Method.POST, httpRequest, toadletContext);
67 when(httpRequest.getPartAsStringFailsafe(eq("parent"), anyInt())).thenReturn("parent-id");
68 when(httpRequest.getPartAsStringFailsafe(eq("title"), anyInt())).thenReturn(" ");
69 expectedException.expect(redirectsTo("emptyImageTitle.html"));
70 uploadImagePage.processTemplate(request, templateContext);