From: David ‘Bombe’ Roden Date: Thu, 5 Oct 2017 20:22:21 +0000 (+0200) Subject: Fix tests by parsing the created JSON reply X-Git-Tag: 0.9.7^2~16 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=959d2b0a4c4636c73d531d1097f062bf5f8e3edf;p=Sone.git Fix tests by parsing the created JSON reply --- diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt index 2e0eda3..75a0cd4 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/JsonPageBaseTest.kt @@ -54,7 +54,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(403)) assertThat(response.statusText, equalTo("Forbidden")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":false,\"error\":\"auth-required\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to false, "error" to "auth-required"))) } @Test @@ -64,7 +64,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(403)) assertThat(response.statusText, equalTo("Forbidden")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":false,\"error\":\"auth-required\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to false, "error" to "auth-required"))) } @Test @@ -75,7 +75,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(403)) assertThat(response.statusText, equalTo("Forbidden")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":false,\"error\":\"auth-required\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to false, "error" to "auth-required"))) } @Test @@ -86,7 +86,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(200)) assertThat(response.statusText, equalTo("OK")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":true,\"foo\":\"bar\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to true, "foo" to "bar"))) } @Test @@ -96,7 +96,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(403)) assertThat(response.statusText, equalTo("Forbidden")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":false,\"error\":\"auth-required\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to false, "error" to "auth-required"))) } @Test @@ -106,7 +106,7 @@ class JsonPageBaseTest : TestObjects() { assertThat(response.statusCode, equalTo(200)) assertThat(response.statusText, equalTo("OK")) assertThat(response.contentType, equalTo("application/json")) - assertThat(outputStream.toString("UTF-8"), equalTo("{\"success\":true,\"foo\":\"bar\"}")) + assertThat(outputStream.toString("UTF-8").asJson(), equalTo(mapOf("success" to true, "foo" to "bar"))) } @Test @@ -130,4 +130,6 @@ class JsonPageBaseTest : TestObjects() { assertThat(page.isPrefixPage, equalTo(false)) } + private fun String.asJson() = objectMapper.readValue(this, Map::class.java) as Map + } diff --git a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt index a7e0a8a..1cbba3d 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/ajax/TestObjects.kt @@ -1,5 +1,6 @@ package net.pterodactylus.sone.web.ajax +import com.fasterxml.jackson.databind.ObjectMapper import com.google.common.eventbus.EventBus import freenet.clients.http.ToadletContext import freenet.l10n.BaseL10n @@ -39,6 +40,8 @@ import javax.naming.SizeLimitExceededException */ open class TestObjects { + val objectMapper = ObjectMapper() + val webInterface = mock() var formPassword = "form-password" val l10n = mock()