@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) {
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) {
@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
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
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) =
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
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
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
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
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 {
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
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")
@Test
fun `get method does not redirect`() {
- page.handleRequest(freenetRequest, templateContext)
+ verifyNoRedirect { }
}
@Test
@Test
fun `get request does not redirect`() {
- page.handleRequest(freenetRequest, templateContext)
+ verifyNoRedirect { }
}
@Test
@Test
fun `get request does not redirect`() {
- page.handleRequest(freenetRequest, templateContext)
+ verifyNoRedirect { }
}
@Test
@Test
fun `get request does not redirect`() {
- page.handleRequest(freenetRequest, templateContext)
+ verifyNoRedirect { }
}
@Test
@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
@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
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
@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
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
@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
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 {
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
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 {
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