import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
private val album = mock<Album>()
private val parentAlbum = mock<Album>()
+ override fun getPage() = page
+
@Before
fun setupAlbums() {
whenever(sone.id).thenReturn("sone-id")
fun `get request with invalid album ID results in redirect to invalid page`() {
request("", GET)
whenever(core.getAlbum(anyString())).thenReturn(null)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
@Test
fun `post request redirects to invalid page if album is invalid`() {
request("", POST)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
whenever(sone.isLocal).thenReturn(false)
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
- expectedException.expect(redirectsTo("noPermission.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
addHttpRequestParameter("abortDelete", "true")
- expectedException.expect(redirectsTo("imageBrowser.html?album=album-id"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("imageBrowser.html?album=album-id")
}
@Test
request("", POST)
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
- expectedException.expect(redirectsTo("imageBrowser.html?sone=sone-id"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("imageBrowser.html?sone=sone-id") {
verify(core).deleteAlbum(album)
}
}
whenever(sone.rootAlbum).thenReturn(mock<Album>())
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
- expectedException.expect(redirectsTo("imageBrowser.html?album=parent-id"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("imageBrowser.html?album=parent-id") {
verify(core).deleteAlbum(album)
}
}
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.verify
-import kotlin.test.fail
/**
* Unit test for [DeleteImagePage].
private val image = mock<Image>()
private val sone = mock<Sone>()
+ override fun getPage() = page
+
@Before
fun setupImage() {
val album = mock<Album>()
@Test
fun `get request with invalid image redirects to invalid page`() {
request("", GET)
- expectedException.expect(redirectsTo("invalid.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
whenever(sone.isLocal).thenReturn(false)
addImage("image-id", image)
addHttpRequestParameter("image", "image-id")
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addImage("image-id", image)
addHttpRequestParameter("image", "image-id")
addHttpRequestParameter("abortDelete", "true")
- expectedException.expect(redirectsTo("imageBrowser.html?image=image-id"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("imageBrowser.html?image=image-id")
}
@Test
request("", POST)
addImage("image-id", image)
addHttpRequestParameter("image", "image-id")
- expectedException.expect(redirectsTo("imageBrowser.html?album=album-id"))
- try {
- page.processTemplate(freenetRequest, templateContext)
- fail()
- } catch (e: Exception) {
+ verifyRedirect("imageBrowser.html?album=album-id") {
verify(webInterface.core).deleteImage(image)
- throw e
}
}
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Test
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
-import kotlin.test.fail
/**
* Unit test for [DeletePostPage].
private val post = mock<Post>()
private val sone = mock<Sone>()
+ override fun getPage() = page
+
@Before
fun setupPost() {
whenever(post.sone).thenReturn(sone)
@Test
fun `get request with invalid post redirects to no permission page`() {
request("", GET)
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
@Test
fun `post request with invalid post redirects to no permission page`() {
request("", POST)
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addPost("post-id", post)
addHttpRequestParameter("post", "post-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addHttpRequestParameter("post", "post-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("confirmDelete", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.processTemplate(freenetRequest, templateContext)
- fail()
- } catch (e: Exception) {
+ verifyRedirect("return.html") {
verify(core).deletePost(post)
- throw e
}
}
addHttpRequestParameter("post", "post-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("abortDelete", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.processTemplate(freenetRequest, templateContext)
- fail()
- } catch (e: Exception) {
+ verifyRedirect("return.html") {
verify(core, never()).deletePost(post)
- throw e
}
}
import net.pterodactylus.sone.data.Profile
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito.verify
-import kotlin.test.fail
/**
* Unit test for [DeleteProfileFieldPage].
private val profile = Profile(currentSone)
private val field = profile.addField("name")
+ override fun getPage() = page
+
@Before
fun setupProfile() {
whenever(currentSone.profile).thenReturn(profile)
@Test
fun `get request with invalid field name redirects to invalid page`() {
request("", GET)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
fun `post request with invalid field name redirects to invalid page`() {
request("", POST)
addHttpRequestParameter("field", "wrong-id")
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
fun `post request without confirm redirects to edit profile page`() {
request("", POST)
addHttpRequestParameter("field", field.id)
- expectedException.expect(redirectsTo("editProfile.html#profile-fields"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("editProfile.html#profile-fields")
}
@Test
request("", POST)
addHttpRequestParameter("field", field.id)
addHttpRequestParameter("confirm", "true")
- expectedException.expect(redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- fail()
- } catch (e: Exception) {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(profile.getFieldById(field.id), nullValue())
verify(currentSone).profile = profile
- throw e
}
}
package net.pterodactylus.sone.web
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
-import net.pterodactylus.util.web.Method.POST
-import org.mockito.ArgumentMatchers.anyInt
-import org.mockito.ArgumentMatchers.eq
-import org.mockito.Mockito.`when`
-
import net.pterodactylus.sone.data.PostReply
-
-import com.google.common.base.Optional
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
+import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Before
private val sone = mock<Sone>()
private val reply = mock<PostReply>()
+ override fun getPage() = page
+
@Before
fun setupReply() {
whenever(sone.isLocal).thenReturn(true)
@Test
fun `trying to delete a reply with an invalid ID results in no permission page`() {
request("", POST)
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addHttpRequestParameter("reply", "reply-id")
whenever(sone.isLocal).thenReturn(false)
addPostReply("reply-id", reply)
- expectedException.expect(redirectsTo("noPermission.html"))
- page.processTemplate(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addHttpRequestParameter("reply", "reply-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("confirmDelete", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.processTemplate(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).deleteReply(reply)
}
}
addHttpRequestParameter("reply", "reply-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("abortDelete", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.processTemplate(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core, never()).deleteReply(reply)
}
}
package net.pterodactylus.sone.web
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.junit.Test
import org.mockito.Mockito.verify
-import kotlin.test.fail
/**
* Unit test for [DeleteSonePage].
private val page = DeleteSonePage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `get request does not redirect`() {
request("", GET)
@Test
fun `post request without delete confirmation redirects to index`() {
request("", POST)
- expectedException.expect(redirectsTo("index.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("index.html")
}
@Test
fun `post request with delete confirmation deletes sone and redirects to index`() {
request("", POST)
addHttpRequestParameter("deleteSone", "true")
- expectedException.expect(redirectsTo("index.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- fail()
- } finally {
+ verifyRedirect("index.html") {
verify(core).deleteSone(currentSone)
}
}
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.web.Method.GET
import org.junit.Test
import org.mockito.Mockito.never
import org.mockito.Mockito.verify
-import kotlin.test.fail
/**
* Unit test for [DismissNotificationPage].
private val page = DismissNotificationPage(template, webInterface)
private val notification = mock<Notification>()
+ override fun getPage() = page
+
@Test
fun `get request with invalid notification ID redirects to return page`() {
request("", GET)
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("return.html")
}
@Test
addNotification("notification-id", notification)
addHttpRequestParameter("notification", "notification-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- fail()
- } finally {
+ verifyRedirect("return.html") {
verify(notification, never()).dismiss()
}
}
addNotification("notification-id", notification)
addHttpRequestParameter("notification", "notification-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- fail()
- } finally {
+ verifyRedirect("return.html") {
verify(notification).dismiss()
}
}
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
-import net.pterodactylus.util.web.Method
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.junit.Test
-import org.mockito.Mockito
import org.mockito.Mockito.verify
/**
private val page = DistrustPage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `get request does not redirect`() {
request("", GET)
fun `post request with invalid sone redirects to return page`() {
request("", POST)
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("return.html")
}
@Test
addSone("remote-sone-id", remoteSone)
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("sone", "remote-sone-id")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).distrustSone(currentSone, remoteSone)
}
}
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.mockBuilder
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.junit.Before
private val modifier = mockBuilder<Album.Modifier>()
private val sone = mock<Sone>()
+ override fun getPage() = page
+
@Before
fun setup() {
whenever(album.id).thenReturn("album-id")
@Test
fun `post request with invalid album redirects to invalid page`() {
request("", POST)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
whenever(sone.isLocal).thenReturn(false)
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
- expectedException.expect(redirectsTo("noPermission.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
addHttpRequestParameter("moveLeft", "true")
- expectedException.expect(redirectsTo("imageBrowser.html?album=parent-id"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("imageBrowser.html?album=parent-id") {
verify(parentAlbum).moveAlbumUp(album)
verify(core).touchConfiguration()
}
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
addHttpRequestParameter("moveRight", "true")
- expectedException.expect(redirectsTo("imageBrowser.html?album=parent-id"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("imageBrowser.html?album=parent-id") {
verify(parentAlbum).moveAlbumDown(album)
verify(core).touchConfiguration()
}
addAlbum("album-id", album)
addHttpRequestParameter("album", "album-id")
whenever(modifier.setTitle("")).thenThrow(AlbumTitleMustNotBeEmpty())
- expectedException.expect(redirectsTo("emptyAlbumTitle.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("emptyAlbumTitle.html")
}
@Test
addHttpRequestParameter("album", "album-id")
addHttpRequestParameter("title", "title")
addHttpRequestParameter("description", "description")
- expectedException.expect(redirectsTo("imageBrowser.html?album=album-id"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("imageBrowser.html?album=album-id") {
verify(modifier).setTitle("title")
verify(modifier).setDescription("description")
verify(modifier).update()
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.mockBuilder
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.junit.Before
private val sone = mock<Sone>()
private val album = mock<Album>()
+ override fun getPage() = page
+
@Before
fun setupImage() {
whenever(sone.isLocal).thenReturn(true)
@Test
fun `post request with invalid image redirects to invalid page`() {
request("", POST)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
whenever(sone.isLocal).thenReturn(false)
addImage("image-id", image)
addHttpRequestParameter("image", "image-id")
- expectedException.expect(redirectsTo("noPermission.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("noPermission.html")
}
@Test
addHttpRequestParameter("image", "image-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("moveLeft", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(album).moveImageUp(image)
verify(core).touchConfiguration()
}
addHttpRequestParameter("image", "image-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("moveRight", "true")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(album).moveImageDown(image)
verify(core).touchConfiguration()
}
addHttpRequestParameter("image", "image-id")
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("title", " ")
- expectedException.expect(redirectsTo("emptyImageTitle.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("emptyImageTitle.html") {
verify(core, never()).touchConfiguration()
}
}
addHttpRequestParameter("returnPage", "return.html")
addHttpRequestParameter("title", "Title")
addHttpRequestParameter("description", "Description")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(modifier).setTitle("Title")
verify(modifier).setDescription("Description")
verify(modifier).update()
addHttpRequestParameter("title", "Title")
addHttpRequestHeader("Host", "www.te.st")
addHttpRequestParameter("description", "Get http://www.te.st/KSK@GPL.txt")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(modifier).setTitle("Title")
verify(modifier).setDescription("Get KSK@GPL.txt")
verify(modifier).update()
import net.pterodactylus.sone.data.Profile
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
private val profile = Profile(currentSone)
private val field = profile.addField("Name")
+ override fun getPage() = page
+
@Before
fun setupProfile() {
whenever(currentSone.profile).thenReturn(profile)
@Test
fun `get request with invalid field redirects to invalid page`() {
request("", GET)
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
request("", POST)
addHttpRequestParameter("field", field.id)
addHttpRequestParameter("cancel", "true")
- expectedException.expect(redirectsTo("editProfile.html#profile-fields"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("editProfile.html#profile-fields")
}
@Test
request("", POST)
addHttpRequestParameter("field", field.id)
addHttpRequestParameter("name", "New Name")
- expectedException.expect(redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(field.name, equalTo("New Name"))
verify(currentSone).profile = profile
}
request("", POST)
addHttpRequestParameter("field", field.id)
addHttpRequestParameter("name", "Name")
- expectedException.expect(redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(field.name, equalTo("Name"))
verify(currentSone, never()).profile = profile
}
private val firstField = profile.addField("First Field")
private val secondField = profile.addField("Second Field")
+ override fun getPage() = page
+
@Before
fun setupProfile() {
val avatar = mock<Image>()
request("", POST)
addHttpRequestParameter("save-profile", "true")
addHttpRequestParameter(fieldName, newValue.toString())
- expectedException.expect(WebTestUtils.redirectsTo("editProfile.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html") {
verify(core).touchConfiguration()
assertThat(fieldAccessor(), equalTo(expectedValue))
}
request("", POST)
addHttpRequestParameter("add-field", "true")
addHttpRequestParameter("field-name", "new-field")
- expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(profile.getFieldByName("new-field"), notNullValue())
verify(currentSone).profile = profile
verify(core).touchConfiguration()
fun `deleting a field redirects to delete field page`() {
request("", POST)
addHttpRequestParameter("delete-field-${firstField.id}", "true")
- expectedException.expect(WebTestUtils.redirectsTo("deleteProfileField.html?field=${firstField.id}"))
- page.handleRequest(freenetRequest, templateContext)
+ 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)
addHttpRequestParameter("move-up-field-${secondField.id}", "true")
- expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(profile.fields, contains(secondField, firstField))
verify(currentSone).profile = profile
}
fun `moving an invalid field up redirects to the invalid page`() {
request("", POST)
addHttpRequestParameter("move-up-field-foo", "true")
- expectedException.expect(WebTestUtils.redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
fun `moving a field down moves the field down and redirects to the edit profile page`() {
request("", POST)
addHttpRequestParameter("move-down-field-${firstField.id}", "true")
- expectedException.expect(WebTestUtils.redirectsTo("editProfile.html#profile-fields"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("editProfile.html#profile-fields") {
assertThat(profile.fields, contains(secondField, firstField))
verify(currentSone).profile = profile
}
fun `moving an invalid field down redirects to the invalid page`() {
request("", POST)
addHttpRequestParameter("move-down-field-foo", "true")
- expectedException.expect(WebTestUtils.redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
@Test
fun `editing a field redirects to the edit profile page`() {
request("", POST)
addHttpRequestParameter("edit-field-${firstField.id}", "true")
- expectedException.expect(WebTestUtils.redirectsTo("editProfileField.html?field=${firstField.id}"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("editProfileField.html?field=${firstField.id}")
}
}
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.junit.Test
private val page = FollowSonePage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `get request does not redirect`() {
request("", GET)
addSone("sone-id", sone)
addHttpRequestParameter("sone", "sone-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).followSone(currentSone, "sone-id")
verify(core).markSoneKnown(sone)
}
addSone("sone-id2", secondSone)
addHttpRequestParameter("sone", "sone-id1,sone-id2")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).followSone(currentSone, "sone-id1")
verify(core).followSone(currentSone, "sone-id2")
verify(core).markSoneKnown(firstSone)
request("", POST)
addHttpRequestParameter("sone", "sone-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core, never()).followSone(ArgumentMatchers.eq(currentSone), anyString())
verify(core, never()).markSoneKnown(any<Sone>())
}
private val page = LikePage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `get request does not redirect`() {
request("", GET)
addHttpRequestParameter("type", "post")
addHttpRequestParameter("post", "post-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(WebTestUtils.redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(currentSone).addLikedPostId("post-id")
}
}
addHttpRequestParameter("type", "reply")
addHttpRequestParameter("reply", "reply-id")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(WebTestUtils.redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(currentSone).addLikedReplyId("reply-id")
}
}
request("", POST)
addHttpRequestParameter("type", "foo")
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(WebTestUtils.redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verifyNoMoreInteractions(currentSone)
}
}
private val page = LockSonePage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `locking an invalid local sone redirects to return page`() {
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(WebTestUtils.redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core, never()).lockSone(any<Sone>())
}
}
val sone = mock<Sone>()
addLocalSone("sone-id", sone)
addHttpRequestParameter("returnPage", "return.html")
- expectedException.expect(WebTestUtils.redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).lockSone(sone)
}
}
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.test.thenReturnMock
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
private val sones = listOf(createSone("Sone", "Test"), createSone("Test"), createSone("Sone"))
+ override fun getPage() = page
+
private fun createSone(vararg contexts: String) = mock<Sone>().apply {
whenever(id).thenReturn(hashCode().toString())
val identity = mock<OwnIdentity>().apply {
fun `post request with valid sone and redirects to index page`() {
request("", POST)
addHttpRequestParameter("sone-id", "sone2")
- expectedException.expect(redirectsTo("index.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("index.html") {
verify(webInterface).setCurrentSone(toadletContext, sones[1])
}
}
request("", POST)
addHttpRequestParameter("sone-id", "sone2")
addHttpRequestParameter("target", "foo.html")
- expectedException.expect(redirectsTo("foo.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("foo.html") {
verify(webInterface).setCurrentSone(toadletContext, sones[1])
}
}
package net.pterodactylus.sone.web
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import org.hamcrest.MatcherAssert.assertThat
import org.hamcrest.Matchers.equalTo
import org.junit.Test
private val page = LogoutPage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `page unsets current sone and redirects to index`() {
- expectedException.expect(redirectsTo("index.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("index.html") {
verify(webInterface).setCurrentSone(toadletContext, null)
}
}
import net.pterodactylus.sone.data.PostReply
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.test.mock
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import org.junit.Test
import org.mockito.Mockito.verify
private val page = MarkAsKnownPage(template, webInterface)
+ override fun getPage() = page
+
@Test
fun `posts can be marked as known`() {
addHttpRequestParameter("returnPage", "return.html")
val posts = listOf(mock<Post>(), mock<Post>())
addPost("post1", posts[0])
addPost("post3", posts[1])
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).markPostKnown(posts[0])
verify(core).markPostKnown(posts[1])
}
val replies = listOf(mock<PostReply>(), mock<PostReply>())
addPostReply("reply1", replies[0])
addPostReply("reply3", replies[1])
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).markReplyKnown(replies[0])
verify(core).markReplyKnown(replies[1])
}
val sones = listOf(mock<Sone>(), mock<Sone>())
addSone("sone1", sones[0])
addSone("sone3", sones[1])
- expectedException.expect(redirectsTo("return.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("return.html") {
verify(core).markSoneKnown(sones[0])
verify(core).markSoneKnown(sones[1])
}
@Test
fun `different type redirects to invalid page`() {
addHttpRequestParameter("type", "foo")
- expectedException.expect(redirectsTo("invalid.html"))
- page.handleRequest(freenetRequest, templateContext)
+ verifyRedirect("invalid.html")
}
}
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired
import net.pterodactylus.sone.fcp.FcpInterface.FullAccessRequired.WRITING
import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.WebTestUtils.redirectsTo
import net.pterodactylus.util.web.Method.GET
import net.pterodactylus.util.web.Method.POST
import org.hamcrest.MatcherAssert.assertThat
private val page = OptionsPage(template, webInterface)
+ override fun getPage() = page
+
@Before
fun setupPreferences() {
core.preferences.insertionDelay = 1
addHttpRequestParameter("show-custom-avatars", "ALWAYS")
addHttpRequestParameter("load-linked-images", "ALWAYS")
addHttpRequestParameter(option, setValue.toString())
- expectedException.expect(redirectsTo("options.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("options.html") {
assertThat(getter(), equalTo(expectedValue))
}
}
unsetCurrentSone()
request("", POST)
addHttpRequestParameter(name, setValue)
- expectedException.expect(redirectsTo("options.html"))
- try {
- page.handleRequest(freenetRequest, templateContext)
- } finally {
+ verifyRedirect("options.html") {
assertThat(getter(), equalTo(expectedValue))
}
}