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;
17 import java.net.URISyntaxException;
19 import net.pterodactylus.sone.core.Core;
20 import net.pterodactylus.sone.data.Mocks;
21 import net.pterodactylus.sone.web.WebInterface;
22 import net.pterodactylus.sone.web.page.FreenetRequest;
24 import org.junit.Test;
27 * Tests for {@link BookmarkAjaxPage}.
29 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
31 public class BookmarkAjaxPageTest {
33 private final Mocks mocks = new Mocks();
34 private final Core core = mocks.core;
35 private final WebInterface webInterface = mocks.webInterface;
36 private final BookmarkAjaxPage bookmarkAjaxPage = new BookmarkAjaxPage(webInterface);
39 public void bookmarkingDoesNotRequireLogin() {
40 assertThat(bookmarkAjaxPage.requiresLogin(), is(false));
44 public void testBookmarkingExistingPost() throws URISyntaxException {
45 JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax?post=abc", bookmarkAjaxPage);
46 verifySuccessfulJsonResponse(jsonReturnObject);
47 verify(core, times(1)).bookmarkPost(eq("abc"));
51 public void testBookmarkingMissingPost() throws URISyntaxException {
52 JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax", bookmarkAjaxPage);
53 verifyJsonError(jsonReturnObject, "invalid-post-id");
54 verify(core, never()).bookmarkPost(anyString());
57 private JsonReturnObject performRequest(String path, BookmarkAjaxPage bookmarkAjaxPage) throws URISyntaxException {
58 FreenetRequest request = mocks.mockRequest(path);
59 return bookmarkAjaxPage.createJsonObject(request);