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.mockito.Matchers.anyString;
10 import static org.mockito.Matchers.eq;
11 import static org.mockito.Mockito.never;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
15 import java.net.URISyntaxException;
17 import net.pterodactylus.sone.core.Core;
18 import net.pterodactylus.sone.data.Mocks;
19 import net.pterodactylus.sone.web.WebInterface;
20 import net.pterodactylus.sone.web.page.FreenetRequest;
22 import org.junit.Test;
25 * Tests for {@link BookmarkAjaxPage}.
27 * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
29 public class BookmarkAjaxPageTest {
31 private final Mocks mocks = new Mocks();
32 private final Core core = mocks.core;
33 private final WebInterface webInterface = mocks.webInterface;
34 private final BookmarkAjaxPage bookmarkAjaxPage = new BookmarkAjaxPage(webInterface);
37 public void testBookmarkingExistingPost() throws URISyntaxException {
38 JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax?post=abc", bookmarkAjaxPage);
39 verifySuccessfulJsonResponse(jsonReturnObject);
40 verify(core, times(1)).bookmarkPost(eq("abc"));
44 public void testBookmarkingMissingPost() throws URISyntaxException {
45 JsonReturnObject jsonReturnObject = performRequest("/ajax/bookmark.ajax", bookmarkAjaxPage);
46 verifyJsonError(jsonReturnObject, "invalid-post-id");
47 verify(core, never()).bookmarkPost(anyString());
50 private JsonReturnObject performRequest(String path, BookmarkAjaxPage bookmarkAjaxPage) throws URISyntaxException {
51 FreenetRequest request = mocks.mockRequest(path);
52 return bookmarkAjaxPage.createJsonObject(request);