2 * © 2013 xplosion interactive
5 package net.pterodactylus.sone.web.ajax;
7 import static net.pterodactylus.sone.Verifiers.verifyJsonError;
8 import static net.pterodactylus.sone.Verifiers.verifySuccessfulJsonResponse;
9 import static org.hamcrest.MatcherAssert.assertThat;
10 import static org.hamcrest.Matchers.is;
11 import static org.mockito.Matchers.anyString;
12 import static org.mockito.Matchers.eq;
13 import static org.mockito.Mockito.never;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16 import static org.mockito.Mockito.when;
18 import java.net.URISyntaxException;
20 import net.pterodactylus.sone.core.Core;
21 import net.pterodactylus.sone.data.Mocks;
22 import net.pterodactylus.sone.web.WebInterface;
23 import net.pterodactylus.sone.web.page.FreenetRequest;
25 import org.junit.Test;
28 * Tests for {@link BookmarkAjaxPage}.
30 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
32 public class BookmarkAjaxPageTest {
34 private final Mocks mocks = new Mocks();
35 private final Core core = mocks.core;
36 private final WebInterface webInterface = mocks.webInterface;
37 private final BookmarkAjaxPage bookmarkAjaxPage = new BookmarkAjaxPage(webInterface);
40 public void bookmarkingDoesNotRequireLogin() {
41 assertThat(bookmarkAjaxPage.requiresLogin(), is(false));
45 public void testBookmarkingExistingPost() throws URISyntaxException {
46 JsonReturnObject jsonReturnObject = performRequest(bookmarkAjaxPage, "abc");
47 verifySuccessfulJsonResponse(jsonReturnObject);
48 verify(core, times(1)).bookmarkPost(eq("abc"));
52 public void testBookmarkingMissingPost() throws URISyntaxException {
53 JsonReturnObject jsonReturnObject = performRequest(bookmarkAjaxPage, null);
54 verifyJsonError(jsonReturnObject, "invalid-post-id");
55 verify(core, never()).bookmarkPost(anyString());
58 private JsonReturnObject performRequest(BookmarkAjaxPage bookmarkAjaxPage, String postId) throws URISyntaxException {
59 FreenetRequest request = mocks.mockRequest("");
60 when(request.getHttpRequest().getParam("post")).thenReturn(postId);
61 when(request.getHttpRequest().getParam("post", null)).thenReturn(postId);
62 return bookmarkAjaxPage.createJsonObject(request);