+++ /dev/null
-/*
- * © 2013 xplosion interactive
- */
-
-package net.pterodactylus.sone.web.ajax;
-
-import java.util.Map;
-
-import com.fasterxml.jackson.annotation.JsonAnyGetter;
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.node.BooleanNode;
-import com.fasterxml.jackson.databind.node.IntNode;
-import com.fasterxml.jackson.databind.node.TextNode;
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.collect.Maps;
-
-/**
- * JSON return object for AJAX requests.
- *
- * @author <a href="mailto:d.roden@xplosion.de">David Roden</a>
- */
-public class JsonReturnObject {
-
- /** Whether the request was successful. */
- @JsonProperty
- private final boolean success;
-
- /** The returned values. */
- private final Map<String, JsonNode> content = Maps.newHashMap();
-
- /**
- * Creates a new JSON return object.
- *
- * @param success
- * {@code true} if the request was successful, {@code false} otherwise
- */
- public JsonReturnObject(boolean success) {
- this.success = success;
- }
-
- //
- // ACCESSORS
- //
-
- /**
- * Returns whether the request was successful.
- *
- * @return {@code true} if the request was successful, {@code false} otherwise
- */
- @VisibleForTesting
- public boolean isSuccess() {
- return success;
- }
-
- /**
- * Returns the value stored under the given key.
- *
- * @param key
- * The key of the value to retrieve
- * @return The value of the key, or {@code null} if there is no value for the
- * given key
- */
- @VisibleForTesting
- public JsonNode get(String key) {
- return content.get(key);
- }
-
- /**
- * Returns the content of this object for serialization.
- *
- * @return The content of this object
- */
- @JsonAnyGetter
- public Map<String, JsonNode> getContent() {
- return content;
- }
-
- //
- // ACTIONS
- //
-
- /**
- * Stores the given value under the given key.
- *
- * @param key
- * The key under which to store the value
- * @param value
- * The value to store
- * @return This JSON return object
- */
- public JsonReturnObject put(String key, boolean value) {
- return put(key, BooleanNode.valueOf(value));
- }
-
- /**
- * Stores the given value under the given key.
- *
- * @param key
- * The key under which to store the value
- * @param value
- * The value to store
- * @return This JSON return object
- */
- public JsonReturnObject put(String key, int value) {
- return put(key, new IntNode(value));
- }
-
- /**
- * Stores the given value under the given key.
- *
- * @param key
- * The key under which to store the value
- * @param value
- * The value to store
- * @return This JSON return object
- */
- public JsonReturnObject put(String key, String value) {
- return put(key, TextNode.valueOf(value));
- }
-
- /**
- * Stores the given value under the given key.
- *
- * @param key
- * The key under which to store the value
- * @param value
- * The value to store
- * @return This JSON return object
- */
- public JsonReturnObject put(String key, JsonNode value) {
- content.put(key, value);
- return this;
- }
-
- @Override
- public int hashCode() {
- return Boolean.valueOf(success).hashCode() ^ content.hashCode();
- }
-
- @Override
- public boolean equals(Object object) {
- if ((object == null) || (object.getClass() != getClass())) {
- return false;
- }
- JsonReturnObject other = (JsonReturnObject) object;
- return (success == other.success) && content.equals(other.content);
- }
-
-}
--- /dev/null
+package net.pterodactylus.sone.web.ajax
+
+import com.fasterxml.jackson.annotation.JsonAnyGetter
+import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.BooleanNode
+import com.fasterxml.jackson.databind.node.IntNode
+import com.fasterxml.jackson.databind.node.TextNode
+
+/**
+ * JSON return object for AJAX requests.
+ */
+open class JsonReturnObject(val isSuccess: Boolean) {
+
+ private val values = mutableMapOf<String, JsonNode?>()
+
+ val content: Map<String, Any?>
+ @JsonAnyGetter get() = values
+
+ operator fun get(key: String) = values[key]
+
+ fun put(key: String, value: String?) = apply {
+ values[key] = TextNode.valueOf(value)
+ }
+
+ fun put(key: String, value: Int) = apply {
+ values[key] = IntNode.valueOf(value)
+ }
+
+ fun put(key: String, value: Boolean) = apply {
+ values[key] = BooleanNode.valueOf(value)
+ }
+
+ fun put(key: String, value: JsonNode) = apply {
+ values[key] = value
+ }
+
+ override fun hashCode(): Int {
+ return isSuccess.hashCode() xor content.hashCode()
+ }
+
+ override fun equals(other: Any?) =
+ (other as? JsonReturnObject)?.let {
+ it.isSuccess == isSuccess && it.content == content
+ } ?: false
+
+}
val post = createPost()
whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postId"].asText(), equalTo("id"))
- assertThat(json["sone"].asText(), equalTo(currentSone.id))
+ assertThat(json["postId"]?.asText(), equalTo("id"))
+ assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
assertThat(json["recipient"], nullValue())
}
val post = createPost()
whenever(core.createPost(currentSone, Optional.absent(), "test")).thenReturn(post)
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postId"].asText(), equalTo("id"))
- assertThat(json["sone"].asText(), equalTo(currentSone.id))
+ assertThat(json["postId"]?.asText(), equalTo("id"))
+ assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
assertThat(json["recipient"], nullValue())
}
val post = createPost("valid")
whenever(core.createPost(currentSone, Optional.of(recipient), "test")).thenReturn(post)
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postId"].asText(), equalTo("id"))
- assertThat(json["sone"].asText(), equalTo(currentSone.id))
- assertThat(json["recipient"].asText(), equalTo("valid"))
+ assertThat(json["postId"]?.asText(), equalTo("id"))
+ assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
+ assertThat(json["recipient"]?.asText(), equalTo("valid"))
}
@Test
val post = createPost()
whenever(core.createPost(currentSone, Optional.absent(), "Link KSK@foo is filtered")).thenReturn(post)
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postId"].asText(), equalTo("id"))
- assertThat(json["sone"].asText(), equalTo(currentSone.id))
+ assertThat(json["postId"]?.asText(), equalTo("id"))
+ assertThat(json["sone"]?.asText(), equalTo(currentSone.id))
assertThat(json["recipient"], nullValue())
}
whenever(core.createReply(currentSone, post, "")).thenReturn(reply)
addRequestParameter("post", "post-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("soneId"))
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("soneId"))
}
@Test
addRequestParameter("text", "Text with http://127.0.0.1:8888/KSK@foo.bar link")
addRequestHeader("Host", "127.0.0.1:8888")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("soneId"))
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("soneId"))
}
@Test
addRequestParameter("text", "Text")
addRequestParameter("sender", "local-sone")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"].asText(), equalTo("reply-id"))
- assertThat(json["sone"].asText(), equalTo("local-sone"))
+ assertThat(json["reply"]?.asText(), equalTo("reply-id"))
+ assertThat(json["sone"]?.asText(), equalTo("local-sone"))
}
}
addSone(sone, "sone-id")
addRequestParameter("sone", "sone-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["trustValue"].asInt(), equalTo(-33))
+ assertThat(json["trustValue"]?.asInt(), equalTo(-33))
}
}
addRequestParameter("album", "album-id")
addRequestParameter("moveLeft", "true")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["sourceAlbumId"].asText(), equalTo("album-id"))
- assertThat(json["destinationAlbumId"].asText(), equalTo("swapped"))
+ assertThat(json["sourceAlbumId"]?.asText(), equalTo("album-id"))
+ assertThat(json["destinationAlbumId"]?.asText(), equalTo("swapped"))
}
@Test
addRequestParameter("album", "album-id")
addRequestParameter("moveRight", "true")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["sourceAlbumId"].asText(), equalTo("album-id"))
- assertThat(json["destinationAlbumId"].asText(), equalTo("swapped"))
+ assertThat(json["sourceAlbumId"]?.asText(), equalTo("album-id"))
+ assertThat(json["destinationAlbumId"]?.asText(), equalTo("swapped"))
}
@Test
addRequestParameter("description", "foo http://127.0.0.1:8888/KSK@foo.html link")
addRequestHeader("Host", "127.0.0.1:8888")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["albumId"].asText(), equalTo("album-id"))
- assertThat(json["title"].asText(), equalTo("new title"))
- assertThat(json["description"].asText(), equalTo("foo KSK@foo.html link"))
+ assertThat(json["albumId"]?.asText(), equalTo("album-id"))
+ assertThat(json["title"]?.asText(), equalTo("new title"))
+ assertThat(json["description"]?.asText(), equalTo("foo KSK@foo.html link"))
}
}
addRequestParameter("image", "image-id")
addRequestParameter("moveLeft", "true")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["sourceImageId"].asText(), equalTo("image-id"))
- assertThat(json["destinationImageId"].asText(), equalTo("swapped"))
+ assertThat(json["sourceImageId"]?.asText(), equalTo("image-id"))
+ assertThat(json["destinationImageId"]?.asText(), equalTo("swapped"))
verify(core).touchConfiguration()
}
addRequestParameter("image", "image-id")
addRequestParameter("moveRight", "true")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["sourceImageId"].asText(), equalTo("image-id"))
- assertThat(json["destinationImageId"].asText(), equalTo("swapped"))
+ assertThat(json["sourceImageId"]?.asText(), equalTo("image-id"))
+ assertThat(json["destinationImageId"]?.asText(), equalTo("swapped"))
verify(core).touchConfiguration()
}
addRequestParameter("description", "some http://127.0.0.1:8888/KSK@foo link")
addRequestHeader("Host", "127.0.0.1:8888")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["title"].asText(), equalTo("some title"))
- assertThat(json["description"].asText(), equalTo("some KSK@foo link"))
- assertThat(json["parsedDescription"].asText(), equalTo("rendered description"))
+ assertThat(json["title"]?.asText(), equalTo("some title"))
+ assertThat(json["description"]?.asText(), equalTo("some KSK@foo link"))
+ assertThat(json["parsedDescription"]?.asText(), equalTo("rendered description"))
verify(core).touchConfiguration()
val parameterCaptor = argumentCaptor<MutableMap<String, Any?>>()
verify(parserFilter).format(any(), any(), parameterCaptor.capture())
addRequestParameter("type", "post")
addRequestParameter("post", "post-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["likes"].asInt(), equalTo(3))
- assertThat(json["sones"].toList().map { it["id"].asText() to it["name"].asText() }, contains(
+ assertThat(json["likes"]?.asInt(), equalTo(3))
+ assertThat(json["sones"]!!.toList().map { it["id"].asText() to it["name"].asText() }, contains(
"S1" to "F1 M1 L1",
"S2" to "F2 M2 L2",
"S3" to "F3 M3 L3"
addRequestParameter("type", "reply")
addRequestParameter("reply", "reply-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["likes"].asInt(), equalTo(3))
- assertThat(json["sones"].toList().map { it["id"].asText() to it["name"].asText() }, contains(
+ assertThat(json["likes"]?.asInt(), equalTo(3))
+ assertThat(json["sones"]!!.toList().map { it["id"].asText() to it["name"].asText() }, contains(
"S1" to "F1 M1 L1",
"S2" to "F2 M2 L2",
"S3" to "F3 M3 L3"
else -> null
}
}
- assertThat(json.get("linkedElements").elements().asSequence().map { it.toMap() }.toList(), Matchers.containsInAnyOrder(
+ assertThat(json.get("linkedElements")!!.elements().asSequence().map { it.toMap() }.toList(), Matchers.containsInAnyOrder(
mapOf<String, String?>("link" to "KSK@foo.jpg", "html" to "jpeg-image"),
mapOf("link" to "KSK@foo.html", "html" to "html-page")
))
fun `notification hash is calculated correctly`() {
testNotifications.forEach { addNotification(it) }
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["notificationHash"].asInt(), equalTo(listOf(1, 0, 2).map(testNotifications::get).hashCode()))
+ assertThat(json["notificationHash"]?.asInt(), equalTo(listOf(1, 0, 2).map(testNotifications::get).hashCode()))
}
@Test
fun `options are included correctly`() {
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["options"]["ShowNotification/NewSones"].asBoolean(), equalTo(true))
- assertThat(json["options"]["ShowNotification/NewPosts"].asBoolean(), equalTo(true))
- assertThat(json["options"]["ShowNotification/NewReplies"].asBoolean(), equalTo(true))
+ assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(true))
+ assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(true))
+ assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(true))
}
@Test
currentSone.options.isShowNewPostNotifications = false
currentSone.options.isShowNewReplyNotifications = false
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["options"]["ShowNotification/NewSones"].asBoolean(), equalTo(false))
- assertThat(json["options"]["ShowNotification/NewPosts"].asBoolean(), equalTo(false))
- assertThat(json["options"]["ShowNotification/NewReplies"].asBoolean(), equalTo(false))
+ assertThat(json["options"]!!["ShowNotification/NewSones"].asBoolean(), equalTo(false))
+ assertThat(json["options"]!!["ShowNotification/NewPosts"].asBoolean(), equalTo(false))
+ assertThat(json["options"]!!["ShowNotification/NewReplies"].asBoolean(), equalTo(false))
}
@Test
fun `options are not included if user is not logged in`() {
unsetCurrentSone()
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["options"].toList(), empty())
+ assertThat(json["options"]?.toList(), empty())
}
@Test
fun `notifications are rendered correctly`() {
testNotifications.forEach { addNotification(it) }
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["notifications"].toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder(
+ assertThat(json["notifications"]!!.toList().map { node -> listOf("id", "text", "createdTime", "lastUpdatedTime", "dismissable").map { it to node.get(it).asText() }.toMap() }, containsInAnyOrder(
mapOf("id" to "n1", "createdTime" to "2000", "lastUpdatedTime" to "5000", "dismissable" to "true", "text" to "t1"),
mapOf("id" to "n2", "createdTime" to "1000", "lastUpdatedTime" to "6000", "dismissable" to "false", "text" to "t2"),
mapOf("id" to "n3", "createdTime" to "3000", "lastUpdatedTime" to "7000", "dismissable" to "true", "text" to "t3")
testNotifications.forEach { addNotification(it) }
addNotification(templateNotification)
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["notifications"].last()["text"].asText(), equalTo("t4"))
+ assertThat(json["notifications"]!!.last()["text"].asText(), equalTo("t4"))
val templateContext = argumentCaptor<TemplateContext>()
verify(templateNotification).render(templateContext.capture(), any())
assertThat(templateContext.value["core"], equalTo<Any>(core))
addPost(post)
addRequestParameter("post", "post-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["post"]["id"].asText(), equalTo("post-id"))
- assertThat(json["post"]["time"].asLong(), equalTo(1000L))
- assertThat(json["post"]["sone"].asText(), equalTo("sone-id"))
- assertThat(json["post"]["recipient"].asText(), equalTo("recipient-id"))
- assertThat(json["post"]["html"].asText(), equalTo(listOf(
+ assertThat(json["post"]!!["id"].asText(), equalTo("post-id"))
+ assertThat(json["post"]!!["time"].asLong(), equalTo(1000L))
+ assertThat(json["post"]!!["sone"].asText(), equalTo("sone-id"))
+ assertThat(json["post"]!!["recipient"].asText(), equalTo("recipient-id"))
+ assertThat(json["post"]!!["html"].asText(), equalTo(listOf(
core.toString(),
freenetRequest.toString(),
"post text",
addReply(reply)
addRequestParameter("reply", "reply-id")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["reply"]["id"].asText(), equalTo("reply-id"))
- assertThat(json["reply"]["soneId"].asText(), equalTo("sone-id"))
- assertThat(json["reply"]["postId"].asText(), equalTo("post-id"))
- assertThat(json["reply"]["time"].asLong(), equalTo(1000L))
- assertThat(json["reply"]["html"].asText(), equalTo(listOf(
+ assertThat(json["reply"]!!["id"].asText(), equalTo("reply-id"))
+ assertThat(json["reply"]!!["soneId"].asText(), equalTo("sone-id"))
+ assertThat(json["reply"]!!["postId"].asText(), equalTo("post-id"))
+ assertThat(json["reply"]!!["time"].asLong(), equalTo(1000L))
+ assertThat(json["reply"]!!["html"].asText(), equalTo(listOf(
core.toString(),
freenetRequest.toString(),
"reply text",
@Test
fun `page returns correct attribute “loggedIn” if sone is logged in`() {
- assertThat(json.get("loggedIn").asText(), equalTo("true"))
+ assertThat(json.get("loggedIn")?.asText(), equalTo("true"))
}
@Test
fun `page returns correct attribute “loggedIn” if sone is not logged in`() {
unsetCurrentSone()
- assertThat(json.get("loggedIn").asText(), equalTo("false"))
+ assertThat(json.get("loggedIn")?.asText(), equalTo("false"))
}
@Test
fun `page returns options for sone if sone is logged in`() {
- assertThat(json.get("options").toMap(), allOf(
+ assertThat(json.get("options")?.toMap(), allOf(
hasEntry("ShowNotification/NewSones", "true"),
hasEntry("ShowNotification/NewPosts", "true"),
hasEntry("ShowNotification/NewReplies", "true")
@Test
fun `page returns a sones object with the current sone if not other sones parameter is given`() {
- assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ assertThat(json.get("sones")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000")
))
}
addSone(deepMock<Sone>().mock("sone1", "Sone 1", false, 2000, downloading))
addSone(deepMock<Sone>().mock("sone3", "Sone 3", true, 3000, inserting))
addRequestParameter("soneIds", "sone1,sone2,sone3")
- assertThat(json.get("sones").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ assertThat(json.get("sones")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf<String, String?>("id" to "soneId", "name" to "Sone_Id", "local" to "true", "status" to "idle", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:01", "lastUpdatedText" to "1000"),
mapOf("id" to "sone1", "name" to "Sone 1", "local" to "false", "status" to "downloading", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:02", "lastUpdatedText" to "2000"),
mapOf("id" to "sone3", "name" to "Sone 3", "local" to "true", "status" to "inserting", "modified" to "false", "locked" to "false", "lastUpdatedUnknown" to "false", "lastUpdated" to "Jan 1, 1970, 00:00:03", "lastUpdatedText" to "3000")
mock<Notification>().apply { whenever(this.createdTime).thenReturn(1000) }
)
notifications.forEachIndexed { index, notification -> addNotification(notification, "notification$index")}
- assertThat(json.get("notificationHash").asInt(), equalTo(notifications.sortedBy { it.createdTime }.hashCode()))
+ assertThat(json.get("notificationHash")?.asInt(), equalTo(notifications.sortedBy { it.createdTime }.hashCode()))
}
@Test
fun `page returns new posts`() {
addNewPost("post1", "sone1", 1000)
addNewPost("post2", "sone2", 2000, "sone1")
- assertThat(json.get("newPosts").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ assertThat(json.get("newPosts")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf("id" to "post1", "sone" to "sone1", "time" to "1000", "recipient" to null),
mapOf("id" to "post2", "sone" to "sone2", "time" to "2000", "recipient" to "sone1")
))
fun `page returns new replies`() {
addNewReply("reply1", "sone1", "post1", "sone11")
addNewReply("reply2", "sone2", "post2", "sone22")
- assertThat(json.get("newReplies").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ assertThat(json.get("newReplies")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf<String, String?>("id" to "reply1", "sone" to "sone1", "post" to "post1", "postSone" to "sone11"),
mapOf("id" to "reply2", "sone" to "sone2", "post" to "post2", "postSone" to "sone22")
))
addLinkedElement("KSK@test.html", loading = true, failed = false)
addLinkedElement("KSK@test.jpeg", loading = false, failed = true)
addRequestParameter("elements", jsonArray("KSK@test.png", "KSK@test.html", "KSK@test.jpeg").toString())
- assertThat(json.get("linkedElements").elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
+ assertThat(json.get("linkedElements")!!.elements().asSequence().map { it.toMap() }.toList(), containsInAnyOrder(
mapOf<String, String?>("link" to "KSK@test.png", "loading" to "false", "failed" to "false"),
mapOf("link" to "KSK@test.html", "loading" to "true", "failed" to "false"),
mapOf("link" to "KSK@test.jpeg", "loading" to "false", "failed" to "true")
@Test
fun `request without any parameters responds with empty post and reply times`() {
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postTimes"].toList(), emptyIterable())
- assertThat(json["replyTimes"].toList(), emptyIterable())
+ assertThat(json["postTimes"]?.toList(), emptyIterable())
+ assertThat(json["replyTimes"]?.toList(), emptyIterable())
}
@Test
addPost(testPosts[0])
addRequestParameter("posts", "post1")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
+ assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
"post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01")
))
- assertThat(json["replyTimes"].toList(), emptyIterable())
+ assertThat(json["replyTimes"]?.toList(), emptyIterable())
}
@Test
addReply(testReplies[0])
addRequestParameter("replies", "reply1")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postTimes"].toList(), emptyIterable())
- assertThat(json["replyTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
+ assertThat(json["postTimes"]?.toList(), emptyIterable())
+ assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
"reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01")
))
}
addPost(testPosts[1])
addRequestParameter("posts", "post1,post2,post3")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
+ assertThat(json["postTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
"post1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"),
"post2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 00:00:02")
))
- assertThat(json["replyTimes"].toList(), emptyIterable())
+ assertThat(json["replyTimes"]?.toList(), emptyIterable())
}
@Test
addReply(testReplies[1])
addRequestParameter("replies", "reply1,reply2,reply3")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["postTimes"].toList(), emptyIterable())
- assertThat(json["replyTimes"].fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
+ assertThat(json["postTimes"]?.toList(), emptyIterable())
+ assertThat(json["replyTimes"]!!.fields().asSequence().map { it.key to it.value }.toList(), containsInAnyOrder<Pair<String, JsonNode>>(
"reply1" to jsonObject("timeText" to "1000", "refreshTime" to 2L, "tooltip" to "Jan 1, 1970, 00:00:01"),
"reply2" to jsonObject("timeText" to "2000", "refreshTime" to 4L, "tooltip" to "Jan 1, 1970, 00:00:02")
))
addTranslation("foo", "bar")
addRequestParameter("key", "foo")
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["value"].asText(), equalTo("bar"))
+ assertThat(json["value"]?.asText(), equalTo("bar"))
}
}
addRequestParameter("sone", "sone-id")
core.preferences.positiveTrust = 31
assertThat(json.isSuccess, equalTo(true))
- assertThat(json["trustValue"].asInt(), equalTo(31))
+ assertThat(json["trustValue"]?.asInt(), equalTo(31))
}
}