From: David ‘Bombe’ Roden Date: Wed, 24 May 2017 18:25:31 +0000 (+0200) Subject: Set URI and request method separately in tests X-Git-Tag: 0.9.7^2~201 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=6b29b49714912ff5e3e410d2484699cdf8041b90;p=Sone.git Set URI and request method separately in tests --- diff --git a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java index c785e36..9774915 100644 --- a/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java +++ b/src/test/java/net/pterodactylus/sone/web/pages/WebPageTest.java @@ -2,6 +2,7 @@ package net.pterodactylus.sone.web.pages; import static net.pterodactylus.sone.test.GuiceKt.supply; import static net.pterodactylus.sone.web.WebTestUtils.redirectsTo; +import static net.pterodactylus.util.web.Method.GET; import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.anyBoolean; import static org.mockito.ArgumentMatchers.anyInt; @@ -126,6 +127,7 @@ public abstract class WebPageTest { @Before public final void setupFreenetRequest() throws SizeLimitExceededException { + setMethod(GET); when(freenetRequest.getToadletContext()).thenReturn(toadletContext); when(freenetRequest.getHttpRequest()).thenReturn(httpRequest); when(httpRequest.getMultipleParam(anyString())).thenAnswer(new Answer() { @@ -314,15 +316,13 @@ public abstract class WebPageTest { when(httpRequest.getMethod()).thenReturn(method.name()); } - protected void request(String uri, Method method) { + protected void request(String uri) { try { when(httpRequest.getPath()).thenReturn(uri); when(freenetRequest.getUri()).thenReturn(new URI(uri)); } catch (URISyntaxException e) { throw new RuntimeException(e); } - when(freenetRequest.getMethod()).thenReturn(method); - when(httpRequest.getMethod()).thenReturn(method.name()); } protected void addHttpRequestHeader(@Nonnull String name, String value) { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt index 411d051..9300085 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/BookmarkPageTest.kt @@ -32,7 +32,7 @@ class BookmarkPageTest : WebPageTest() { } private fun setupBookmarkRequest() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return-page.html") addHttpRequestPart("post", "post-id") } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt index 9851530..c7bdce3 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt @@ -45,7 +45,7 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `missing name results in attribute being set in template context`() { - request("", POST) + setMethod(POST) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["nameMissing"], equalTo(true)) } @@ -60,7 +60,7 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `title and description are set correctly on the album`() { - request("", POST) + setMethod(POST) addAlbum("parent-id", parentAlbum) addHttpRequestPart("name", "new name") addHttpRequestPart("description", "new description") @@ -76,7 +76,7 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `root album is used if no parent is specified`() { - request("", POST) + setMethod(POST) addHttpRequestPart("name", "new name") addHttpRequestPart("description", "new description") verifyRedirect("imageBrowser.html?album=album-id") @@ -84,7 +84,7 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `empty album title redirects to error page`() { - request("", POST) + setMethod(POST) whenever(newAlbum.modify().update()).thenThrow(AlbumTitleMustNotBeEmpty::class.java) addHttpRequestPart("name", "new name") addHttpRequestPart("description", "new description") @@ -93,7 +93,7 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `album description is filtered`() { - request("", POST) + setMethod(POST) addHttpRequestPart("name", "new name") addHttpRequestPart("description", "new http://localhost:12345/KSK@foo description") addHttpRequestHeader("Host", "localhost:12345") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt index 14f4fa3..e337973 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreatePostPageTest.kt @@ -40,7 +40,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `post is created correctly`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", "post text") verifyRedirect("return.html") { @@ -50,7 +50,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `creating an empty post is denied`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", " ") page.processTemplate(freenetRequest, templateContext) @@ -59,7 +59,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `a sender can be selected`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", "post text") addHttpRequestPart("sender", "sender-id") @@ -72,7 +72,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `a recipient can be selected`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", "post text") addHttpRequestPart("recipient", "recipient-id") @@ -85,7 +85,7 @@ class CreatePostPageTest: WebPageTest() { @Test fun `text is filtered correctly`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("text", "post http://localhost:12345/KSK@foo text") addHttpRequestHeader("Host", "localhost:12345") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt index 01f3361..7a545c5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateReplyPageTest.kt @@ -31,7 +31,7 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created correctly`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("post", "post-id") addHttpRequestPart("text", "new text") @@ -43,7 +43,7 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is filtered`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("post", "post-id") addHttpRequestPart("text", "new http://localhost:12345/KSK@foo text") @@ -56,7 +56,7 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `reply is created with correct sender`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("post", "post-id") addHttpRequestPart("text", "new text") @@ -70,7 +70,7 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `empty text sets parameters in template contexty`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("post", "post-id") addHttpRequestPart("text", " ") @@ -83,7 +83,7 @@ class CreateReplyPageTest: WebPageTest() { @Test fun `user is redirected to no permissions page if post does not exist`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("post", "post-id") addHttpRequestPart("text", "new text") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt index 04ed0aa..a01a6a7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateSonePageTest.kt @@ -85,7 +85,7 @@ class CreateSonePageTest: WebPageTest() { @Test fun `sone is created and logged in`() { addExistingOwnIdentities() - request("", POST) + setMethod(POST) addHttpRequestPart("identity", "own-id-3") val newSone = mock() whenever(core.createSone(ownIdentities_[2])).thenReturn(newSone) @@ -96,7 +96,7 @@ class CreateSonePageTest: WebPageTest() { @Test fun `on invalid identity id a flag is set in the template context`() { - request("", POST) + setMethod(POST) addHttpRequestParameter("identity", "own-id-3") page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["errorNoIdentity"], equalTo(true)) @@ -105,7 +105,7 @@ class CreateSonePageTest: WebPageTest() { @Test fun `if sone is not created user is still redirected to index`() { addExistingOwnIdentities() - request("", POST) + setMethod(POST) addHttpRequestPart("identity", "own-id-3") whenever(core.createSone(ownIdentities_[2])).thenReturn(null) verifyRedirect("index.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt index 3a1c504..a32e513 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteAlbumPageTest.kt @@ -6,7 +6,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeleteAlbumPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -52,14 +51,12 @@ class DeleteAlbumPageTest: WebPageTest() { @Test fun `get request with invalid album ID results in redirect to invalid page`() { - request("", GET) whenever(core.getAlbum(anyString())).thenReturn(null) verifyRedirect("invalid.html") } @Test fun `get request with valid album ID sets album in template context`() { - request("", GET) val album = mock() addAlbum("album-id", album) addHttpRequestParameter("album", "album-id") @@ -69,13 +66,13 @@ class DeleteAlbumPageTest: WebPageTest() { @Test fun `post request redirects to invalid page if album is invalid`() { - request("", POST) + setMethod(POST) verifyRedirect("invalid.html") } @Test fun `post request redirects to no permissions page if album is not local`() { - request("", POST) + setMethod(POST) whenever(sone.isLocal).thenReturn(false) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") @@ -84,7 +81,7 @@ class DeleteAlbumPageTest: WebPageTest() { @Test fun `post request with abort delete parameter set redirects to album browser`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") addHttpRequestPart("abortDelete", "true") @@ -93,7 +90,7 @@ class DeleteAlbumPageTest: WebPageTest() { @Test fun `album is deleted and page redirects to sone if parent album is root album`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") verifyRedirect("imageBrowser.html?sone=sone-id") { @@ -103,7 +100,7 @@ class DeleteAlbumPageTest: WebPageTest() { @Test fun `album is deleted and page redirects to album if parent album is not root album`() { - request("", POST) + setMethod(POST) whenever(parentAlbum.isRoot).thenReturn(false) whenever(sone.rootAlbum).thenReturn(mock()) addAlbum("album-id", album) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt index 89e2879..c773976 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteImagePageTest.kt @@ -7,7 +7,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeleteImagePage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -48,13 +47,11 @@ class DeleteImagePageTest: WebPageTest() { @Test fun `get request with invalid image redirects to invalid page`() { - request("", GET) verifyRedirect("invalid.html") } @Test fun `get request with image from non-local sone redirects to no permissions page`() { - request("", GET) whenever(sone.isLocal).thenReturn(false) addImage("image-id", image) addHttpRequestParameter("image", "image-id") @@ -63,7 +60,6 @@ class DeleteImagePageTest: WebPageTest() { @Test fun `get request with image from local sone sets image in template context`() { - request("", GET) addImage("image-id", image) addHttpRequestParameter("image", "image-id") page.processTemplate(freenetRequest, templateContext) @@ -72,7 +68,7 @@ class DeleteImagePageTest: WebPageTest() { @Test fun `post request with abort delete flag set redirects to image browser`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("abortDelete", "true") @@ -81,7 +77,7 @@ class DeleteImagePageTest: WebPageTest() { @Test fun `post request deletes image and redirects to image browser`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") verifyRedirect("imageBrowser.html?album=album-id") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt index c55f1a5..0dbcc43 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeletePostPageTest.kt @@ -6,7 +6,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeletePostPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -45,13 +44,11 @@ class DeletePostPageTest : WebPageTest() { @Test fun `get request with invalid post redirects to no permission page`() { - request("", GET) verifyRedirect("noPermission.html") } @Test fun `get request with valid post sets post and return page in template context`() { - request("", GET) addPost("post-id", post) addHttpRequestParameter("post", "post-id") addHttpRequestParameter("returnPage", "return.html") @@ -62,13 +59,13 @@ class DeletePostPageTest : WebPageTest() { @Test fun `post request with invalid post redirects to no permission page`() { - request("", POST) + setMethod(POST) verifyRedirect("noPermission.html") } @Test fun `post request with post from non-local sone redirects to no permission page`() { - request("", POST) + setMethod(POST) whenever(sone.isLocal).thenReturn(false) addPost("post-id", post) addHttpRequestPart("post", "post-id") @@ -78,7 +75,7 @@ class DeletePostPageTest : WebPageTest() { @Test fun `post request with confirmation deletes post and redirects to return page`() { - request("", POST) + setMethod(POST) addPost("post-id", post) addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") @@ -90,7 +87,7 @@ class DeletePostPageTest : WebPageTest() { @Test fun `post request with abort delete does not delete post and redirects to return page`() { - request("", POST) + setMethod(POST) addPost("post-id", post) addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") @@ -102,7 +99,7 @@ class DeletePostPageTest : WebPageTest() { @Test fun `post request without delete or abort sets post in template context`() { - request("", POST) + setMethod(POST) addPost("post-id", post) addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt index 39bd8af..56bdfe1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteProfileFieldPageTest.kt @@ -4,7 +4,6 @@ import net.pterodactylus.sone.data.Profile import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeleteProfileFieldPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -45,20 +44,18 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `get request with invalid field name redirects to invalid page`() { - request("", GET) verifyRedirect("invalid.html") } @Test fun `post request with invalid field name redirects to invalid page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", "wrong-id") verifyRedirect("invalid.html") } @Test fun `get request with valid field name sets field in template context`() { - request("", GET) addHttpRequestParameter("field", field.id) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["field"], equalTo(field)) @@ -66,7 +63,7 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `post request without confirm redirects to edit profile page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", field.id) verifyRedirect("editProfile.html#profile-fields") { verify(currentSone, never()).profile = any() @@ -75,7 +72,7 @@ class DeleteProfileFieldPageTest: WebPageTest() { @Test fun `post request with confirm removes field and redirects to edit profile page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", field.id) addHttpRequestPart("confirm", "true") verifyRedirect("editProfile.html#profile-fields") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt index 7944321..eb2d184 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteReplyPageTest.kt @@ -6,7 +6,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeleteReplyPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -45,7 +44,6 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `get request sets reply ID and return page in template context`() { - request("", GET) addHttpRequestParameter("reply", "reply-id") addHttpRequestParameter("returnPage", "return.html") page.processTemplate(freenetRequest, templateContext) @@ -55,7 +53,7 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `post request without any action sets reply ID and return page in template context`() { - request("", POST) + setMethod(POST) addPostReply("reply-id", reply) addHttpRequestPart("reply", "reply-id") addHttpRequestPart("returnPage", "return.html") @@ -66,13 +64,13 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `trying to delete a reply with an invalid ID results in no permission page`() { - request("", POST) + setMethod(POST) verifyRedirect("noPermission.html") } @Test fun `trying to delete a reply from a non-local sone results in no permission page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("reply", "reply-id") whenever(sone.isLocal).thenReturn(false) addPostReply("reply-id", reply) @@ -81,7 +79,7 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `confirming deletion of reply deletes the reply and redirects to return page`() { - request("", POST) + setMethod(POST) addPostReply("reply-id", reply) addHttpRequestPart("reply", "reply-id") addHttpRequestPart("returnPage", "return.html") @@ -93,7 +91,7 @@ class DeleteReplyPageTest : WebPageTest() { @Test fun `aborting deletion of reply redirects to return page`() { - request("", POST) + setMethod(POST) addPostReply("reply-id", reply) addHttpRequestPart("reply", "reply-id") addHttpRequestPart("returnPage", "return.html") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt index 8b04261..0ca5149 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DeleteSonePageTest.kt @@ -3,7 +3,6 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DeleteSonePage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -41,13 +40,12 @@ class DeleteSonePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) } @Test fun `post request without delete confirmation redirects to index`() { - request("", POST) + setMethod(POST) verifyRedirect("index.html") { verify(core, never()).deleteSone(any()) } @@ -55,7 +53,7 @@ class DeleteSonePageTest : WebPageTest() { @Test fun `post request with delete confirmation deletes sone and redirects to index`() { - request("", POST) + setMethod(POST) addHttpRequestPart("deleteSone", "true") verifyRedirect("index.html") { verify(core).deleteSone(currentSone) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt index 1b482ce..570780c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DismissNotificationPageTest.kt @@ -41,14 +41,14 @@ class DismissNotificationPageTest: WebPageTest() { @Test fun `get request with invalid notification ID redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") } @Test fun `get request with non-dismissible notification never dismisses the notification but redirects to return page`() { - request("", POST) + setMethod(POST) addNotification("notification-id", notification) addHttpRequestPart("notification", "notification-id") addHttpRequestPart("returnPage", "return.html") @@ -59,7 +59,7 @@ class DismissNotificationPageTest: WebPageTest() { @Test fun `post request with dismissible notification dismisses the notification and redirects to return page`() { - request("", POST) + setMethod(POST) whenever(notification.isDismissable).thenReturn(true) addNotification("notification-id", notification) addHttpRequestPart("notification", "notification-id") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt index e5e672f..d5279f1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/DistrustPageTest.kt @@ -5,7 +5,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.DistrustPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -39,20 +38,19 @@ class DistrustPageTest: WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) } @Test fun `post request with invalid sone redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") } @Test fun `post request with valid sone distrusts sone and redirects to return page`() { - request("", POST) + setMethod(POST) val remoteSone = mock() addSone("remote-sone-id", remoteSone) addHttpRequestPart("returnPage", "return.html") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt index 3583762..06a2508 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditAlbumPageTest.kt @@ -9,7 +9,6 @@ import net.pterodactylus.sone.test.mockBuilder import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.EditAlbumPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -61,19 +60,18 @@ class EditAlbumPageTest: WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) } @Test fun `post request with invalid album redirects to invalid page`() { - request("", POST) + setMethod(POST) verifyRedirect("invalid.html") } @Test fun `post request with album of non-local sone redirects to no permissions page`() { - request("", POST) + setMethod(POST) whenever(sone.isLocal).thenReturn(false) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") @@ -82,7 +80,7 @@ class EditAlbumPageTest: WebPageTest() { @Test fun `post request with move left requested moves album to the left and redirects to album browser`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") addHttpRequestPart("moveLeft", "true") @@ -94,7 +92,7 @@ class EditAlbumPageTest: WebPageTest() { @Test fun `post request with move right requested moves album to the left and redirects to album browser`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") addHttpRequestPart("moveRight", "true") @@ -106,7 +104,7 @@ class EditAlbumPageTest: WebPageTest() { @Test fun `post request with empty album title redirects to empty album title page`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty()) @@ -115,7 +113,7 @@ class EditAlbumPageTest: WebPageTest() { @Test fun `post request with non-empty album title and description redirects to album browser`() { - request("", POST) + setMethod(POST) addAlbum("album-id", album) addHttpRequestPart("album", "album-id") addHttpRequestPart("title", "title") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt index ac710d5..e763a75 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditImagePageTest.kt @@ -9,7 +9,6 @@ import net.pterodactylus.sone.test.doThrow import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.mockBuilder import net.pterodactylus.sone.test.whenever -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -60,19 +59,18 @@ class EditImagePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) } @Test fun `post request with invalid image redirects to invalid page`() { - request("", POST) + setMethod(POST) verifyRedirect("invalid.html") } @Test fun `post request with valid image from non-local sone redirects to no permission page`() { - request("", POST) + setMethod(POST) whenever(sone.isLocal).thenReturn(false) addImage("image-id", image) addHttpRequestPart("image", "image-id") @@ -81,7 +79,7 @@ class EditImagePageTest : WebPageTest() { @Test fun `post request with valid image and move left requested moves image left and redirects to return page`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("returnPage", "return.html") @@ -94,7 +92,7 @@ class EditImagePageTest : WebPageTest() { @Test fun `post request with valid image and move right requested moves image right and redirects to return page`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("returnPage", "return.html") @@ -107,7 +105,7 @@ class EditImagePageTest : WebPageTest() { @Test fun `post request with valid image but only whitespace in the title redirects to empty image title page`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("returnPage", "return.html") @@ -120,7 +118,7 @@ class EditImagePageTest : WebPageTest() { @Test fun `post request with valid image title and description modifies image and redirects to reutrn page`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("returnPage", "return.html") @@ -136,7 +134,7 @@ class EditImagePageTest : WebPageTest() { @Test fun `post request with image title and description modifies image with filtered description and redirects to return page`() { - request("", POST) + setMethod(POST) addImage("image-id", image) addHttpRequestPart("image", "image-id") addHttpRequestPart("returnPage", "return.html") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt index 78b27b7..350dc7e 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfileFieldPageTest.kt @@ -4,7 +4,6 @@ import net.pterodactylus.sone.data.Profile import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.EditProfileFieldPage import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -48,13 +47,11 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `get request with invalid field redirects to invalid page`() { - request("", GET) verifyRedirect("invalid.html") } @Test fun `get request with valid field stores field in template context`() { - request("", GET) addHttpRequestParameter("field", field.id) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["field"], equalTo(field)) @@ -62,7 +59,7 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with cancel set redirects to profile edit page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", field.id) addHttpRequestPart("cancel", "true") verifyRedirect("editProfile.html#profile-fields") @@ -70,7 +67,7 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with new name renames field and redirects to profile edit page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", field.id) addHttpRequestPart("name", "New Name") verifyRedirect("editProfile.html#profile-fields") { @@ -81,7 +78,7 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with same name does not modify field and redirects to profile edit page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("field", field.id) addHttpRequestPart("name", "Name") verifyRedirect("editProfile.html#profile-fields") { @@ -92,7 +89,7 @@ class EditProfileFieldPageTest : WebPageTest() { @Test fun `post request with same name as different field sets error condition in template`() { - request("", POST) + setMethod(POST) profile.addField("New Name") addHttpRequestPart("field", field.id) addHttpRequestPart("name", "New Name") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt index 274f0fe..fd03d0a 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/EditProfilePageTest.kt @@ -6,7 +6,6 @@ import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.EditProfilePage import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains @@ -63,7 +62,6 @@ class EditProfilePageTest : WebPageTest() { @Test fun `get request stores fields of current sone’s profile in template context`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["firstName"], equalTo("First")) assertThat(templateContext["middleName"], equalTo("Middle")) @@ -77,7 +75,7 @@ class EditProfilePageTest : WebPageTest() { @Test fun `post request without any command stores fields of current sone’s profile in template context`() { - request("", POST) + setMethod(POST) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["firstName"], equalTo("First")) assertThat(templateContext["middleName"], equalTo("Middle")) @@ -90,7 +88,7 @@ class EditProfilePageTest : WebPageTest() { } private fun verifySingleFieldCanBeChanged(fieldName: String, newValue: T, expectedValue: T = newValue, fieldAccessor: () -> T) { - request("", POST) + setMethod(POST) addHttpRequestPart("save-profile", "true") addHttpRequestPart(fieldName, newValue.toString()) verifyRedirect("editProfile.html") { @@ -155,7 +153,7 @@ class EditProfilePageTest : WebPageTest() { @Test fun `adding a field with a duplicate name sets error in template context`() { - request("", POST) + setMethod(POST) profile.addField("new-field") addHttpRequestPart("add-field", "true") addHttpRequestPart("field-name", "new-field") @@ -167,7 +165,7 @@ class EditProfilePageTest : WebPageTest() { @Test fun `adding a field with a new name sets adds field to profile and redirects to profile edit page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("add-field", "true") addHttpRequestPart("field-name", "new-field") verifyRedirect("editProfile.html#profile-fields") { @@ -179,14 +177,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `deleting a field redirects to delete field page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("delete-field-${firstField.id}", "true") verifyRedirect("deleteProfileField.html?field=${firstField.id}") } @Test fun `moving a field up moves the field up and redirects to the edit profile page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("move-up-field-${secondField.id}", "true") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) @@ -196,14 +194,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `moving an invalid field up does not redirect`() { - request("", POST) + setMethod(POST) addHttpRequestPart("move-up-field-foo", "true") page.processTemplate(freenetRequest, templateContext) } @Test fun `moving a field down moves the field down and redirects to the edit profile page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("move-down-field-${firstField.id}", "true") verifyRedirect("editProfile.html#profile-fields") { assertThat(profile.fields, contains(secondField, firstField)) @@ -213,14 +211,14 @@ class EditProfilePageTest : WebPageTest() { @Test fun `moving an invalid field down does not redirect`() { - request("", POST) + setMethod(POST) addHttpRequestPart("move-down-field-foo", "true") page.processTemplate(freenetRequest, templateContext) } @Test fun `editing a field redirects to the edit profile page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("edit-field-${firstField.id}", "true") verifyRedirect("editProfileField.html?field=${firstField.id}") } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt index a95e34c..581390c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/FollowSonePageTest.kt @@ -3,7 +3,6 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -41,13 +40,12 @@ class FollowSonePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) } @Test fun `a single sone can be followed`() { - request("", POST) + setMethod(POST) val sone = mock() addSone("sone-id", sone) addHttpRequestPart("sone", "sone-id") @@ -60,7 +58,7 @@ class FollowSonePageTest : WebPageTest() { @Test fun `multiple sones can be followed`() { - request("", POST) + setMethod(POST) val firstSone = mock() addSone("sone-id1", firstSone) val secondSone = mock() @@ -77,7 +75,7 @@ class FollowSonePageTest : WebPageTest() { @Test fun `a non-existing sone is not followed`() { - request("", POST) + setMethod(POST) addHttpRequestPart("sone", "sone-id") addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt index 063a588..d64e475 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ImageBrowserPageTest.kt @@ -5,7 +5,6 @@ import net.pterodactylus.sone.data.Image import net.pterodactylus.sone.data.Sone import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever -import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.equalTo @@ -36,7 +35,6 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `get request with album sets album and page in template context`() { - request("", GET) val album = mock() addAlbum("album-id", album) addHttpRequestParameter("album", "album-id") @@ -49,7 +47,6 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `get request with image sets image in template context`() { - request("", GET) val image = mock() addImage("image-id", image) addHttpRequestParameter("image", "image-id") @@ -60,7 +57,6 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `get request with sone sets sone in template context`() { - request("", GET) val sone = mock() addSone("sone-id", sone) addHttpRequestParameter("sone", "sone-id") @@ -71,7 +67,6 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `get request with mode of gallery sets albums and page in template context`() { - request("", GET) val firstSone = createSone("first album", "second album") addSone("sone1", firstSone) val secondSone = createSone("third album", "fourth album") @@ -106,7 +101,6 @@ class ImageBrowserPageTest : WebPageTest() { @Test fun `requesting nothing will show the albums of the current sone`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["soneRequested"], equalTo(true)) assertThat(templateContext["sone"], equalTo(currentSone)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt index 6d87f3a..d544912 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/IndexPageTest.kt @@ -8,7 +8,6 @@ import net.pterodactylus.sone.notify.PostVisibilityFilter import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.Pagination -import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.emptyIterable @@ -65,7 +64,6 @@ class IndexPageTest : WebPageTest() { fun `index page shows all posts of current sone`() { val posts = listOf(createPost(3000), createPost(2000), createPost(1000)) whenever(currentSone.posts).thenReturn(posts) - request("", GET) page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") assertThat(templateContext["posts"] as Iterable, contains(*posts.toTypedArray())) @@ -79,7 +77,6 @@ class IndexPageTest : WebPageTest() { val notFollowedPosts = listOf(createPost(2500, true), createPost(1500)) whenever(notFollowedSone.posts).thenReturn(notFollowedPosts) addSone("notfollowed1", notFollowedSone) - request("", GET) whenever(core.getDirectedPosts("current")).thenReturn(listOf(notFollowedPosts[0])) page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") @@ -97,7 +94,6 @@ class IndexPageTest : WebPageTest() { whenever(followedSone.posts).thenReturn(followedPosts) whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2")) addSone("followed1", followedSone) - request("", GET) page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") assertThat(templateContext["posts"] as Iterable, contains( @@ -115,7 +111,6 @@ class IndexPageTest : WebPageTest() { whenever(currentSone.friends).thenReturn(listOf("followed1", "followed2")) whenever(postVisibilityFilter.isVisible(ArgumentMatchers.eq(currentSone))).thenReturn(Predicate { (it?.time ?: 10000) < 2500 }) addSone("followed1", followedSone) - request("", GET) page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") assertThat(templateContext["posts"] as Iterable, contains( @@ -127,7 +122,6 @@ class IndexPageTest : WebPageTest() { fun `index page sets pagination correctly`() { val posts = listOf(createPost(3000), createPost(2000), createPost(1000)) whenever(currentSone.posts).thenReturn(posts) - request("", GET) page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") assertThat((templateContext["pagination"] as Pagination).items, contains( @@ -139,7 +133,6 @@ class IndexPageTest : WebPageTest() { fun `index page sets page correctly`() { val posts = listOf(createPost(3000), createPost(2000), createPost(1000)) whenever(currentSone.posts).thenReturn(posts) - request("", GET) core.preferences.postsPerPage = 1 addHttpRequestParameter("page", "2") page.processTemplate(freenetRequest, templateContext) @@ -149,7 +142,6 @@ class IndexPageTest : WebPageTest() { @Test fun `index page without posts sets correct pagination`() { - request("", GET) core.preferences.postsPerPage = 1 page.processTemplate(freenetRequest, templateContext) @Suppress("UNCHECKED_CAST") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPageTest.kt index 42dd33b..a2bdcc5 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/KnownSonesPageTest.kt @@ -11,7 +11,6 @@ import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.Pagination -import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.equalTo @@ -40,11 +39,6 @@ class KnownSonesPageTest: WebPageTest() { addSone("sone4", sones[3]) } - @Before - fun setupGetRequests() { - setMethod(GET) - } - private fun createSone(time: Long, posts: Int, replies: Int, images: Int, name: String, local: Boolean, new: Boolean) = mock().apply { whenever(identity).thenReturn(if (local) mock() else mock()) whenever(this.isLocal).thenReturn(local) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt index 588717e..5b18d4c 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LikePageTest.kt @@ -1,6 +1,5 @@ package net.pterodactylus.sone.web.pages -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -35,13 +34,12 @@ class LikePageTest : WebPageTest() { @Test fun `get request does not redirect`() { - request("", GET) verifyNoRedirect {} } @Test fun `post request with post id likes post and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("type", "post") addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") @@ -52,7 +50,7 @@ class LikePageTest : WebPageTest() { @Test fun `post request with reply id likes post and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("type", "reply") addHttpRequestPart("reply", "reply-id") addHttpRequestPart("returnPage", "return.html") @@ -63,7 +61,7 @@ class LikePageTest : WebPageTest() { @Test fun `post request with invalid likes redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("type", "foo") addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt index 7832f68..c4049f7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/LoginPageTest.kt @@ -8,7 +8,6 @@ import net.pterodactylus.sone.test.thenReturnMock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.WebPageTest import net.pterodactylus.sone.web.pages.LoginPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains @@ -63,7 +62,6 @@ class LoginPageTest : WebPageTest() { @Test @Suppress("UNCHECKED_CAST") fun `get request stores sones in template context`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["sones"] as Iterable, containsInAnyOrder(sones[0], sones[1], sones[2])) } @@ -71,7 +69,6 @@ class LoginPageTest : WebPageTest() { @Test @Suppress("UNCHECKED_CAST") fun `get request stores identities without sones in template context`() { - request("", GET) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["identitiesWithoutSone"] as Iterable, contains(sones[1].identity)) } @@ -79,7 +76,7 @@ class LoginPageTest : WebPageTest() { @Test @Suppress("UNCHECKED_CAST") fun `post request with invalid sone sets sones and identities without sone in template context`() { - request("", POST) + setMethod(POST) page.processTemplate(freenetRequest, templateContext) assertThat(templateContext["sones"] as Iterable, containsInAnyOrder(sones[0], sones[1], sones[2])) assertThat(templateContext["identitiesWithoutSone"] as Iterable, contains(sones[1].identity)) @@ -87,7 +84,7 @@ class LoginPageTest : WebPageTest() { @Test fun `post request with valid sone logs in the sone and redirects to index page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("sone-id", "sone2") verifyRedirect("index.html") { verify(webInterface).setCurrentSone(toadletContext, sones[1]) @@ -96,7 +93,7 @@ class LoginPageTest : WebPageTest() { @Test fun `post request with valid sone and target redirects to target page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("sone-id", "sone2") addHttpRequestParameter("target", "foo.html") verifyRedirect("foo.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt index 2420e5b..d47560b 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/NewPageTest.kt @@ -6,7 +6,6 @@ import net.pterodactylus.sone.test.asOptional import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.utils.Pagination -import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.contains import org.hamcrest.Matchers.containsInAnyOrder @@ -47,7 +46,6 @@ class NewPageTest: WebPageTest() { @Test fun `posts are not duplicated when they come from both new posts and new replies notifications`() { - setMethod(GET) val extraPost = mock().withTime(2000) val posts = asList(mock().withTime(1000), mock().withTime(3000)) val postReplies = asList(mock(), mock()) @@ -67,7 +65,6 @@ class NewPageTest: WebPageTest() { @Test @Suppress("UNCHECKED_CAST") fun `posts are paginated properly`() { - setMethod(GET) webInterface.core.preferences.postsPerPage = 2 val posts = listOf(mock().withTime(2000), mock().withTime(3000), mock().withTime(1000)) whenever(webInterface.getNewPosts(currentSone)).thenReturn(posts) @@ -79,7 +76,6 @@ class NewPageTest: WebPageTest() { @Test @Suppress("UNCHECKED_CAST") fun `posts are paginated properly on second page`() { - setMethod(GET) webInterface.core.preferences.postsPerPage = 2 addHttpRequestParameter("page", "1") val posts = listOf(mock().withTime(2000), mock().withTime(3000), mock().withTime(1000)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt index f239e3e..6c31ea8 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt @@ -9,7 +9,6 @@ import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.NO import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.OptionsPage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -57,7 +56,6 @@ class OptionsPageTest : WebPageTest() { @Test fun `get request stores all preferences in the template context`() { - request("", GET) page.handleRequest(freenetRequest, templateContext) assertThat(templateContext["auto-follow"], equalTo(true)) assertThat(templateContext["show-notification-new-sones"], equalTo(true)) @@ -81,7 +79,6 @@ class OptionsPageTest : WebPageTest() { @Test fun `get request without sone does not store sone-specific preferences in the template context`() { - request("", GET) unsetCurrentSone() page.handleRequest(freenetRequest, templateContext) assertThat(templateContext["auto-follow"], nullValue()) @@ -94,7 +91,7 @@ class OptionsPageTest : WebPageTest() { } private fun verifyThatOptionCanBeSet(option: String, setValue: Any?, expectedValue: T, getter: () -> T) { - request("", POST) + setMethod(POST) addHttpRequestPart("show-custom-avatars", "ALWAYS") addHttpRequestPart("load-linked-images", "ALWAYS") addHttpRequestPart(option, setValue.toString()) @@ -140,7 +137,7 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatWrongValueForPreferenceIsDetected(name: String, value: String) { unsetCurrentSone() - request("", POST) + setMethod(POST) addHttpRequestPart(name, value) page.handleRequest(freenetRequest, templateContext) assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name)) @@ -148,7 +145,7 @@ class OptionsPageTest : WebPageTest() { private fun verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) { unsetCurrentSone() - request("", POST) + setMethod(POST) addHttpRequestPart(name, setValue) verifyRedirect("options.html") { assertThat(getter(), equalTo(expectedValue)) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt index 2d44010..274dba8 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/ReloadingPageTest.kt @@ -2,7 +2,6 @@ package net.pterodactylus.sone.web.pages import net.pterodactylus.sone.web.pages.ReloadingPage import net.pterodactylus.sone.web.page.FreenetRequest -import net.pterodactylus.util.web.Method.GET import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo import org.junit.Rule @@ -33,7 +32,7 @@ class ReloadingPageTest : WebPageTest() { @Test fun `requesting invalid file results in 404`() { - request("/prefix/path/file.txt", GET) + request("/prefix/path/file.txt") page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(404)) } @@ -41,7 +40,7 @@ class ReloadingPageTest : WebPageTest() { @Test fun `requesting valid file results in 200 and delivers file`() { Files.write(Paths.get(folder.path, "file.txt"), listOf("Hello", "World"), UTF_8) - request("/prefix/path/file.txt", GET) + request("/prefix/path/file.txt") page.handleRequest(freenetRequest, response) assertThat(response.statusCode, equalTo(200)) assertThat(response.contentType, equalTo("text/plain")) diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt index cbc8968..ad162bf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt @@ -4,7 +4,6 @@ import net.pterodactylus.sone.core.SoneRescuer import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever import net.pterodactylus.sone.web.pages.RescuePage -import net.pterodactylus.util.web.Method.GET import net.pterodactylus.util.web.Method.POST import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.equalTo @@ -32,20 +31,19 @@ class RescuePageTest : WebPageTest() { @Test fun `get request sets rescuer in template context`() { - request("", GET) page.handleRequest(freenetRequest, templateContext) assertThat(templateContext["soneRescuer"], equalTo(soneRescuer)) } @Test fun `post request redirects to rescue page`() { - request("", POST) + setMethod(POST) verifyRedirect("rescue.html") } @Test fun `post request with fetch and invalid edition starts next fetch`() { - request("", POST) + setMethod(POST) addHttpRequestPart("fetch", "true") verifyRedirect("rescue.html") { verify(soneRescuer, never()).setEdition(anyLong()) @@ -55,7 +53,7 @@ class RescuePageTest : WebPageTest() { @Test fun `post request with fetch and valid edition sets edition and starts next fetch`() { - request("", POST) + setMethod(POST) addHttpRequestPart("fetch", "true") addHttpRequestPart("edition", "123") verifyRedirect("rescue.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt index 2eb77e2..4cef5b0 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/SoneTemplatePageTest.kt @@ -8,7 +8,6 @@ import net.pterodactylus.sone.web.page.FreenetRequest import net.pterodactylus.util.notify.Notification import net.pterodactylus.util.template.TemplateContext import net.pterodactylus.util.version.Version -import net.pterodactylus.util.web.Method.GET import org.hamcrest.Matcher import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.Matchers.anyOf @@ -207,14 +206,14 @@ class SoneTemplatePageTest : WebPageTest() { @Test fun `redirect does happen if sone is not logged in`() { unsetCurrentSone() - request("index.html", GET) + request("index.html") assertThat(page.getRedirectTarget(freenetRequest), equalTo("login.html?target=index.html")) } @Test fun `redirect does happen with parameters encoded correctly if sone is not logged in`() { unsetCurrentSone() - request("index.html", GET) + request("index.html") addHttpRequestParameter("foo", "b=r") addHttpRequestParameter("baz", "q&o") assertThat(page.getRedirectTarget(freenetRequest), anyOf( diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt index 3aa6ba2..c5e34ea 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt @@ -26,7 +26,7 @@ class TrustPageTest : WebPageTest() { @Test fun `post request with missing sone redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "sone-id") verifyRedirect("return.html") { @@ -36,7 +36,7 @@ class TrustPageTest : WebPageTest() { @Test fun `post request with existing sone trusts the identity and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "sone-id") val sone = mock() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt index be451b5..4be4a79 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt @@ -42,7 +42,7 @@ class UnbookmarkPageTest : WebPageTest() { @Test fun `post request does not unbookmark not-present post but redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { @@ -52,7 +52,7 @@ class UnbookmarkPageTest : WebPageTest() { @Test fun `post request unbookmarks present post and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("post", "post-id") addHttpRequestPart("returnPage", "return.html") val post = mock().apply { whenever(isLoaded).thenReturn(true) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt index e7e6786..03fec7f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt @@ -21,7 +21,7 @@ class UnfollowSonePageTest : WebPageTest() { @Test fun `post request unfollows a single sone and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "sone-id") verifyRedirect("return.html") { @@ -31,7 +31,7 @@ class UnfollowSonePageTest : WebPageTest() { @Test fun `post request unfollows two sones and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "sone-id1, sone-id2") verifyRedirect("return.html") { diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt index 7059057..3cd7d99 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt @@ -26,7 +26,7 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request does not remove any likes but redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(currentSone, never()).removeLikedPostId(any()) @@ -36,7 +36,7 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request removes post like and redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("type", "post") addHttpRequestPart("id", "post-id") @@ -48,7 +48,7 @@ class UnlikePageTest : WebPageTest() { @Test fun `post request removes reply like and redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("type", "reply") addHttpRequestPart("id", "reply-id") diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt index a29b372..5e32d84 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UnlockSonePageTest.kt @@ -21,7 +21,7 @@ class UnlockSonePageTest : WebPageTest() { @Test fun `post request without sone redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).unlockSone(any()) @@ -30,7 +30,7 @@ class UnlockSonePageTest : WebPageTest() { @Test fun `post request without invalid local sone does not unlock any sone and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "invalid-sone") verifyRedirect("return.html") { @@ -40,7 +40,7 @@ class UnlockSonePageTest : WebPageTest() { @Test fun `post request without remote sone does not unlock any sone and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "remote-sone") addSone("remote-sone", mock()) @@ -51,7 +51,7 @@ class UnlockSonePageTest : WebPageTest() { @Test fun `post request with local sone unlocks sone and redirects to return page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "local-sone") val sone = mock().apply { whenever(isLocal).thenReturn(true) } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt index c6d0c55..b20bbdf 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt @@ -27,7 +27,7 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request without sone parameter does not untrust but redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") verifyRedirect("return.html") { verify(core, never()).untrustSone(eq(currentSone), any()) @@ -36,7 +36,7 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request with invalid sone parameter does not untrust but redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "no-sone") verifyRedirect("return.html") { @@ -46,7 +46,7 @@ class UntrustPageTest : WebPageTest() { @Test fun `post request with valid sone parameter untrusts and redirects`() { - request("", POST) + setMethod(POST) addHttpRequestPart("returnPage", "return.html") addHttpRequestPart("sone", "sone-id") val sone = mock() diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt index 38c5fe1..1f7a0c1 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt @@ -39,13 +39,13 @@ class UploadImagePageTest : WebPageTest() { @Test fun `post request without parent results in no permission error page`() { - request("", POST) + setMethod(POST) verifyRedirect("noPermission.html") } @Test fun `post request with parent that is not the current sone results in no permission error page`() { - request("", POST) + setMethod(POST) addHttpRequestPart("parent", "parent-id") whenever(parentAlbum.sone).thenReturn(mock()) addAlbum("parent-id", parentAlbum) @@ -54,7 +54,7 @@ class UploadImagePageTest : WebPageTest() { @Test fun `post request with empty name redirects to error page`() { - request("", POST) + setMethod(POST) addAlbum("parent-id", parentAlbum) addHttpRequestPart("parent", "parent-id") addHttpRequestPart("title", " ") @@ -63,7 +63,7 @@ class UploadImagePageTest : WebPageTest() { @Test fun `uploading an invalid image results in no redirect and message set in template context`() { - request("", POST) + setMethod(POST) addAlbum("parent-id", parentAlbum) addHttpRequestPart("parent", "parent-id") addHttpRequestPart("title", "title") @@ -75,7 +75,7 @@ class UploadImagePageTest : WebPageTest() { @Test fun `uploading a valid image uploads image and redirects to album browser`() { - request("", POST) + setMethod(POST) addAlbum("parent-id", parentAlbum) addHttpRequestPart("parent", "parent-id") addHttpRequestPart("title", "Title")