Use verifyNoRedirect instead of calling the request handler directly
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 24 May 2017 19:25:46 +0000 (21:25 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 24 May 2017 19:25:46 +0000 (21:25 +0200)
src/test/kotlin/net/pterodactylus/sone/web/pages/OptionsPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/RescuePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/SearchPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/TrustPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/UnbookmarkPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/UnfollowSonePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/UnlikePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/UntrustPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/UploadImagePageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/ViewPostPageTest.kt
src/test/kotlin/net/pterodactylus/sone/web/pages/ViewSonePageTest.kt

index 7146f2e..a4df75d 100644 (file)
@@ -54,38 +54,40 @@ class OptionsPageTest : WebPageTest() {
 
        @Test
        fun `get request stores all preferences in the template context`() {
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["auto-follow"], equalTo<Any>(true))
-               assertThat(templateContext["show-notification-new-sones"], equalTo<Any>(true))
-               assertThat(templateContext["show-notification-new-posts"], equalTo<Any>(true))
-               assertThat(templateContext["show-notification-new-replies"], equalTo<Any>(true))
-               assertThat(templateContext["enable-sone-insert-notifications"], equalTo<Any>(true))
-               assertThat(templateContext["load-linked-images"], equalTo<Any>("FOLLOWED"))
-               assertThat(templateContext["show-custom-avatars"], equalTo<Any>("FOLLOWED"))
-               assertThat(templateContext["insertion-delay"], equalTo<Any>(1))
-               assertThat(templateContext["characters-per-post"], equalTo<Any>(50))
-               assertThat(templateContext["fcp-full-access-required"], equalTo<Any>(1))
-               assertThat(templateContext["images-per-page"], equalTo<Any>(4))
-               assertThat(templateContext["fcp-interface-active"], equalTo<Any>(true))
-               assertThat(templateContext["require-full-access"], equalTo<Any>(true))
-               assertThat(templateContext["negative-trust"], equalTo<Any>(7))
-               assertThat(templateContext["positive-trust"], equalTo<Any>(8))
-               assertThat(templateContext["post-cut-off-length"], equalTo<Any>(51))
-               assertThat(templateContext["posts-per-page"], equalTo<Any>(10))
-               assertThat(templateContext["trust-comment"], equalTo<Any>("11"))
+               verifyNoRedirect {
+                       assertThat(templateContext["auto-follow"], equalTo<Any>(true))
+                       assertThat(templateContext["show-notification-new-sones"], equalTo<Any>(true))
+                       assertThat(templateContext["show-notification-new-posts"], equalTo<Any>(true))
+                       assertThat(templateContext["show-notification-new-replies"], equalTo<Any>(true))
+                       assertThat(templateContext["enable-sone-insert-notifications"], equalTo<Any>(true))
+                       assertThat(templateContext["load-linked-images"], equalTo<Any>("FOLLOWED"))
+                       assertThat(templateContext["show-custom-avatars"], equalTo<Any>("FOLLOWED"))
+                       assertThat(templateContext["insertion-delay"], equalTo<Any>(1))
+                       assertThat(templateContext["characters-per-post"], equalTo<Any>(50))
+                       assertThat(templateContext["fcp-full-access-required"], equalTo<Any>(1))
+                       assertThat(templateContext["images-per-page"], equalTo<Any>(4))
+                       assertThat(templateContext["fcp-interface-active"], equalTo<Any>(true))
+                       assertThat(templateContext["require-full-access"], equalTo<Any>(true))
+                       assertThat(templateContext["negative-trust"], equalTo<Any>(7))
+                       assertThat(templateContext["positive-trust"], equalTo<Any>(8))
+                       assertThat(templateContext["post-cut-off-length"], equalTo<Any>(51))
+                       assertThat(templateContext["posts-per-page"], equalTo<Any>(10))
+                       assertThat(templateContext["trust-comment"], equalTo<Any>("11"))
+               }
        }
 
        @Test
        fun `get request without sone does not store sone-specific preferences in the template context`() {
                unsetCurrentSone()
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["auto-follow"], nullValue())
-               assertThat(templateContext["show-notification-new-sones"], nullValue())
-               assertThat(templateContext["show-notification-new-posts"], nullValue())
-               assertThat(templateContext["show-notification-new-replies"], nullValue())
-               assertThat(templateContext["enable-sone-insert-notifications"], nullValue())
-               assertThat(templateContext["load-linked-images"], nullValue())
-               assertThat(templateContext["show-custom-avatars"], nullValue())
+               verifyNoRedirect {
+                       assertThat(templateContext["auto-follow"], nullValue())
+                       assertThat(templateContext["show-notification-new-sones"], nullValue())
+                       assertThat(templateContext["show-notification-new-posts"], nullValue())
+                       assertThat(templateContext["show-notification-new-replies"], nullValue())
+                       assertThat(templateContext["enable-sone-insert-notifications"], nullValue())
+                       assertThat(templateContext["load-linked-images"], nullValue())
+                       assertThat(templateContext["show-custom-avatars"], nullValue())
+               }
        }
 
        private fun <T> verifyThatOptionCanBeSet(option: String, setValue: Any?, expectedValue: T, getter: () -> T) {
@@ -137,8 +139,9 @@ class OptionsPageTest : WebPageTest() {
                unsetCurrentSone()
                setMethod(POST)
                addHttpRequestPart(name, value)
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name))
+               verifyNoRedirect {
+                       assertThat(templateContext["fieldErrors"] as Iterable<*>, hasItem(name))
+               }
        }
 
        private fun <T> verifyThatPreferencesCanBeSet(name: String, setValue: String?, expectedValue: T, getter: () -> T) {
index 547c580..303a23c 100644 (file)
@@ -30,8 +30,9 @@ class RescuePageTest : WebPageTest() {
 
        @Test
        fun `get request sets rescuer in template context`() {
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["soneRescuer"], equalTo<Any>(soneRescuer))
+               verifyNoRedirect {
+                       assertThat(templateContext["soneRescuer"], equalTo<Any>(soneRescuer))
+               }
        }
 
        @Test
index 8790283..106b350 100644 (file)
@@ -140,8 +140,9 @@ class SearchPageTest : WebPageTest() {
                addSone("sone-with-match", soneWithMatch)
                addSone("sone-without-match", soneWithoutMatch)
                addHttpRequestParameter("query", "word")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithMatch))
+               }
        }
 
        @Test
@@ -157,8 +158,9 @@ class SearchPageTest : WebPageTest() {
                addSone("sone-with-match", soneWithMatch)
                addSone("sone-without-match", soneWithoutMatch)
                addHttpRequestParameter("query", "word")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithMatch))
+               }
        }
 
        private fun createSoneWithPost(idPostfix: String, text: String, recipient: Sone? = null, sender: Sone? = null) =
@@ -171,8 +173,9 @@ class SearchPageTest : WebPageTest() {
                val postWithEarlyMatch = createSoneWithPost("with-early-match", "optional match")
                val postWithLaterMatch = createSoneWithPost("with-later-match", "match that is optional")
                addHttpRequestParameter("query", "optional ")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithEarlyMatch, postWithLaterMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithEarlyMatch, postWithLaterMatch))
+               }
        }
 
        @Test
@@ -180,8 +183,9 @@ class SearchPageTest : WebPageTest() {
                val postWithRequiredMatch = createSoneWithPost("with-required-match", "required match")
                createPost("without-required-match", "not a match")
                addHttpRequestParameter("query", "+required ")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithRequiredMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithRequiredMatch))
+               }
        }
 
        @Test
@@ -189,8 +193,9 @@ class SearchPageTest : WebPageTest() {
                createSoneWithPost("with-forbidden-match", "forbidden match")
                val postWithoutForbiddenMatch = createSoneWithPost("without-forbidden-match", "not a match")
                addHttpRequestParameter("query", "match -forbidden")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithoutForbiddenMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithoutForbiddenMatch))
+               }
        }
 
        @Test
@@ -198,8 +203,9 @@ class SearchPageTest : WebPageTest() {
                val postWithMatch = createSoneWithPost("with-match", "with + match")
                createSoneWithPost("without-match", "without match")
                addHttpRequestParameter("query", "+")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithMatch))
+               }
        }
 
        @Test
@@ -207,8 +213,9 @@ class SearchPageTest : WebPageTest() {
                val postWithMatch = createSoneWithPost("with-match", "with - match")
                createSoneWithPost("without-match", "without match")
                addHttpRequestParameter("query", "-")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithMatch))
+               }
        }
 
        private fun createPost(id: String, text: String, recipient: Sone?) = mock<Post>().apply {
@@ -235,8 +242,9 @@ class SearchPageTest : WebPageTest() {
                val postWithMatch = createSoneWithPost("with-match", "test", recipient)
                createSoneWithPost("without-match", "no match")
                addHttpRequestParameter("query", "recipient")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["postHits"], contains<Post>(postWithMatch))
+               verifyNoRedirect {
+                       assertThat(this["postHits"], contains<Post>(postWithMatch))
+               }
        }
 
        @Test
@@ -246,8 +254,9 @@ class SearchPageTest : WebPageTest() {
                createSoneWithPost("with-match", "test", sender = soneWithProfileField)
                createSoneWithPost("without-match", "no match")
                addHttpRequestParameter("query", "value")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(this["soneHits"], contains(soneWithProfileField))
+               verifyNoRedirect {
+                       assertThat(this["soneHits"], contains(soneWithProfileField))
+               }
        }
 
        @Suppress("UNCHECKED_CAST")
index cc4b1dc..90a87c6 100644 (file)
@@ -20,7 +20,7 @@ class TrustPageTest : WebPageTest() {
 
        @Test
        fun `get method does not redirect`() {
-               page.handleRequest(freenetRequest, templateContext)
+               verifyNoRedirect { }
        }
 
        @Test
index c6c37a5..a637b40 100644 (file)
@@ -20,7 +20,7 @@ class UnbookmarkPageTest : WebPageTest() {
 
        @Test
        fun `get request does not redirect`() {
-               page.handleRequest(freenetRequest, templateContext)
+               verifyNoRedirect { }
        }
 
        @Test
index ad5216e..7e19a26 100644 (file)
@@ -15,7 +15,7 @@ class UnfollowSonePageTest : WebPageTest() {
 
        @Test
        fun `get request does not redirect`() {
-               page.handleRequest(freenetRequest, templateContext)
+               verifyNoRedirect { }
        }
 
        @Test
index f1050d2..3fa84fd 100644 (file)
@@ -17,7 +17,7 @@ class UnlikePageTest : WebPageTest() {
 
        @Test
        fun `get request does not redirect`() {
-               page.handleRequest(freenetRequest, templateContext)
+               verifyNoRedirect { }
        }
 
        @Test
index f83190f..5848c49 100644 (file)
@@ -20,8 +20,9 @@ class UntrustPageTest : WebPageTest() {
 
        @Test
        fun `get request does not redirect`() {
-               page.handleRequest(freenetRequest, templateContext)
-               verify(core, never()).untrustSone(eq(currentSone), any())
+               verifyNoRedirect {
+                       verify(core, never()).untrustSone(eq(currentSone), any())
+               }
        }
 
        @Test
index 8bea89e..dfb9aca 100644 (file)
@@ -31,9 +31,10 @@ class UploadImagePageTest : WebPageTest() {
 
        @Test
        fun `get request does not redirect or upload anything`() {
-               page.handleRequest(freenetRequest, templateContext)
-               verify(core, never()).createTemporaryImage(any(), any())
-               verify(core, never()).createImage(any(), any(), any())
+               verifyNoRedirect {
+                       verify(core, never()).createTemporaryImage(any(), any())
+                       verify(core, never()).createImage(any(), any(), any())
+               }
        }
 
        @Test
@@ -67,9 +68,10 @@ class UploadImagePageTest : WebPageTest() {
                addHttpRequestPart("parent", "parent-id")
                addHttpRequestPart("title", "title")
                addUploadedFile("image", "image.png", "image/png", "no-image.png")
-               page.handleRequest(freenetRequest, templateContext)
-               verify(core, never()).createTemporaryImage(any(), any())
-               assertThat(templateContext["messages"] as String?, equalTo<String>("Page.UploadImage.Error.InvalidImage"))
+               verifyNoRedirect {
+                       verify(core, never()).createTemporaryImage(any(), any())
+                       assertThat(templateContext["messages"] as String?, equalTo<String>("Page.UploadImage.Error.InvalidImage"))
+               }
        }
 
        @Test
index 1b20bfc..88ca34a 100644 (file)
@@ -26,26 +26,29 @@ class ViewPostPageTest : WebPageTest() {
 
        @Test
        fun `get request without parameters stores null in template context`() {
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["post"], nullValue())
-               assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               verifyNoRedirect {
+                       assertThat(templateContext["post"], nullValue())
+                       assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               }
        }
 
        @Test
        fun `get request with invalid post id stores null in template context`() {
                addHttpRequestParameter("post", "invalid-post-id")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["post"], nullValue())
-               assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               verifyNoRedirect {
+                       assertThat(templateContext["post"], nullValue())
+                       assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               }
        }
 
        @Test
        fun `get request with valid post id stores post in template context`() {
                addPost("post-id", post)
                addHttpRequestParameter("post", "post-id")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["post"], equalTo<Any>(post))
-               assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               verifyNoRedirect {
+                       assertThat(templateContext["post"], equalTo<Any>(post))
+                       assertThat(templateContext["raw"] as? Boolean, equalTo(false))
+               }
        }
 
        @Test
@@ -53,9 +56,10 @@ class ViewPostPageTest : WebPageTest() {
                addPost("post-id", post)
                addHttpRequestParameter("post", "post-id")
                addHttpRequestParameter("raw", "true")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["post"], equalTo<Any>(post))
-               assertThat(templateContext["raw"] as? Boolean, equalTo(true))
+               verifyNoRedirect {
+                       assertThat(templateContext["post"], equalTo<Any>(post))
+                       assertThat(templateContext["raw"] as? Boolean, equalTo(true))
+               }
        }
 
        @Test
index 335d839..7161684 100644 (file)
@@ -42,17 +42,19 @@ class ViewSonePageTest : WebPageTest() {
 
        @Test
        fun `get request without sone parameter stores null in template context`() {
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["sone"], nullValue())
-               assertThat(templateContext["soneId"], equalTo<Any>(""))
+               verifyNoRedirect {
+                       assertThat(templateContext["sone"], nullValue())
+                       assertThat(templateContext["soneId"], equalTo<Any>(""))
+               }
        }
 
        @Test
        fun `get request with invalid sone parameter stores null in template context`() {
                addHttpRequestParameter("sone", "invalid-sone-id")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["sone"], nullValue())
-               assertThat(templateContext["soneId"], equalTo<Any>("invalid-sone-id"))
+               verifyNoRedirect {
+                       assertThat(templateContext["sone"], nullValue())
+                       assertThat(templateContext["soneId"], equalTo<Any>("invalid-sone-id"))
+               }
        }
 
        @Test
@@ -61,9 +63,10 @@ class ViewSonePageTest : WebPageTest() {
                whenever(core.getDirectedPosts("sone-id")).thenReturn(emptyList())
                addHttpRequestParameter("sone", "sone-id")
                addSone("sone-id", currentSone)
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["sone"], equalTo<Any>(currentSone))
-               assertThat(templateContext["soneId"], equalTo<Any>("sone-id"))
+               verifyNoRedirect {
+                       assertThat(templateContext["sone"], equalTo<Any>(currentSone))
+                       assertThat(templateContext["soneId"], equalTo<Any>("sone-id"))
+               }
        }
 
        private fun createPost(id: String, text: String, time: Long, sender: Sone? = null, recipient: Sone? = null) = mock<Post>().apply {
@@ -81,8 +84,9 @@ class ViewSonePageTest : WebPageTest() {
        fun `request with valid sone stores posts and directed posts in template context`() {
                addSone("sone-id", currentSone)
                addHttpRequestParameter("sone", "sone-id")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["posts"] as Iterable<Post>, contains(directed2, post2))
+               verifyNoRedirect {
+                       assertThat(templateContext["posts"] as Iterable<Post>, contains(directed2, post2))
+               }
        }
 
        @Test
@@ -91,8 +95,9 @@ class ViewSonePageTest : WebPageTest() {
                addSone("sone-id", currentSone)
                addHttpRequestParameter("sone", "sone-id")
                addHttpRequestParameter("postPage", "1")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["posts"] as Iterable<Post>, contains(directed1, post1))
+               verifyNoRedirect {
+                       assertThat(templateContext["posts"] as Iterable<Post>, contains(directed1, post1))
+               }
        }
 
        private fun createReply(text: String, time: Long, post: Post?) = mock<PostReply>().apply {
@@ -120,8 +125,9 @@ class ViewSonePageTest : WebPageTest() {
                whenever(core.getReplies("post3")).thenReturn(listOf(reply6))
                addSone("sone-id", currentSone)
                addHttpRequestParameter("sone", "sone-id")
-               page.handleRequest(freenetRequest, templateContext)
-               assertThat(templateContext["repliedPosts"] as Iterable<Post>, contains(foreignPost2,  foreignPost1))
+               verifyNoRedirect {
+                       assertThat(templateContext["repliedPosts"] as Iterable<Post>, contains(foreignPost2,  foreignPost1))
+               }
        }
 
        @Test