@Test
fun `request without text results in fcp exception`() {
- parameters.putSingle("Sone", "LocalSoneId")
+ parameters += "Sone" to "LocalSoneId"
whenever(core.getSone("LocalSoneId")).thenReturn(Optional.of(localSone))
executeCommandAndExpectFcpException()
}
@Test
fun `request with text creates post`() {
- parameters.putSingle("Sone", "LocalSoneId")
- parameters.putSingle("Text", "Test")
+ parameters += "Sone" to "LocalSoneId"
+ parameters += "Text" to "Test"
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
whenever(core.createPost(localSone, absent(), "Test")).thenReturn(post)
@Test
fun `request with invalid recipient results in fcp exception`() {
- parameters.putSingle("Sone", "LocalSoneId")
- parameters.putSingle("Text", "Test")
- parameters.putSingle("Recipient", "InvalidSoneId")
+ parameters += "Sone" to "LocalSoneId"
+ parameters += "Text" to "Test"
+ parameters += "Recipient" to "InvalidSoneId"
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
executeCommandAndExpectFcpException()
}
@Test
fun `request with recipient the same as the sender returns an error response`() {
- parameters.putSingle("Sone", "LocalSoneId")
- parameters.putSingle("Text", "Test")
- parameters.putSingle("Recipient", "LocalSoneId")
+ parameters += "Sone" to "LocalSoneId"
+ parameters += "Text" to "Test"
+ parameters += "Recipient" to "LocalSoneId"
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
@Test
fun `request with text and recipient creates post`() {
- parameters.putSingle("Sone", "LocalSoneId")
- parameters.putSingle("Text", "Test")
- parameters.putSingle("Recipient", "RemoteSoneId")
+ parameters += "Sone" to "LocalSoneId"
+ parameters += "Text" to "Test"
+ parameters += "Recipient" to "RemoteSoneId"
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
whenever(core.getSone("RemoteSoneId")).thenReturn(of(remoteSone))
val post = mock<Post>().apply { whenever(id).thenReturn("PostId") }
}
private fun addValidLocalSoneParameter() {
- parameters.putSingle("Sone", "LocalSoneId")
+ parameters += "Sone" to "LocalSoneId"
whenever(core.getSone("LocalSoneId")).thenReturn(of(localSone))
}
@Test
fun `request with invalid post parameter results in fcp exception`() {
addValidLocalSoneParameter()
- parameters.putSingle("Post", "InvalidPostId")
+ parameters += "Post" to "InvalidPostId"
executeCommandAndExpectFcpException()
}
private fun addValidPostParameter() {
- parameters.putSingle("Post", "ValidPostId")
+ parameters += "Post" to "ValidPostId"
whenever(core.getPost("ValidPostId")).thenReturn(of(post))
}
fun `complete request creates reply`() {
addValidLocalSoneParameter()
addValidPostParameter()
- parameters.putSingle("Text", "Test")
+ parameters += "Text" to "Test"
val postReply = mock<PostReply>().apply { whenever(id).thenReturn("ReplyId") }
whenever(core.createReply(localSone, post, "Test")).thenReturn(postReply)
val response = command.execute(parameters)
@Test
fun `request with invalid post parameter results in fcp exception`() {
- parameters.putSingle("Post", "InvalidPostId")
+ parameters += "Post" to "InvalidPostId"
executeCommandAndExpectFcpException()
}
@Test
fun `request with post from remote sone returns error response`() {
- parameters.putSingle("Post", "RemotePostId")
+ parameters += "Post" to "RemotePostId"
whenever(core.getPost("RemotePostId")).thenReturn(of(postFromRemoteSone))
val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
@Test
fun `request with post from local sone deletes posts`() {
- parameters.putSingle("Post", "LocalPostId")
+ parameters += "Post" to "LocalPostId"
whenever(core.getPost("LocalPostId")).thenReturn(of(postFromLocalSone))
val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("PostDeleted"))
@Test
fun `request with invalid post reply parameter results in fcp exception`() {
- parameters.putSingle("Reply", "InvalidReplyId")
+ parameters += "Reply" to "InvalidReplyId"
executeCommandAndExpectFcpException()
}
@Test
fun `request with remote post reply parameter results in error response`() {
- parameters.putSingle("Reply", "RemoteReplyId")
+ parameters += "Reply" to "RemoteReplyId"
whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(remotePostReply))
val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("Error"))
@Test
fun `request with local post reply parameter deletes reply`() {
- parameters.putSingle("Reply", "RemoteReplyId")
+ parameters += "Reply" to "RemoteReplyId"
whenever(core.getPostReply("RemoteReplyId")).thenReturn(of(localPostReply))
val response = command.execute(parameters)
assertThat(response.replyParameters["Message"], equalTo("ReplyDeleted"))
@Test
fun `request with invalid post parameter results in fcp exception`() {
- parameters.putSingle("Post", "InvalidPostId")
+ parameters += "Post" to "InvalidPostId"
executeCommandAndExpectFcpException()
}
@Test
fun `request with valid post parameter returns post response`() {
- parameters.putSingle("Post", "ValidPostId")
+ parameters += "Post" to "ValidPostId"
val replyParameters = command.execute(parameters).replyParameters
verifyPostWithLikes(replyParameters)
assertThat(replyParameters["Post.Recipient"], nullValue())
@Test
fun `request with valid post parameter without replies returns post response without replies`() {
- parameters.putSingle("Post", "ValidPostId")
- parameters.putSingle("IncludeReplies", "false")
+ parameters += "Post" to "ValidPostId"
+ parameters += "IncludeReplies" to "false"
val replyParameters = command.execute(parameters).replyParameters
verifyPostWithLikes(replyParameters)
assertThat(replyParameters["Post.Recipient"], nullValue())
@Test
fun `request with valid post parameter returns post response with recipient`() {
- parameters.putSingle("Post", "ValidPostId")
+ parameters += "Post" to "ValidPostId"
whenever(post.recipientId).thenReturn("Sone2".asOptional())
val replyParameters = command.execute(parameters).replyParameters
verifyPostWithLikes(replyParameters)
@Test
fun `request with valid post parameter without replies returns post response without replies but with recipient`() {
- parameters.putSingle("Post", "ValidPostId")
- parameters.putSingle("IncludeReplies", "false")
+ parameters += "Post" to "ValidPostId"
+ parameters += "IncludeReplies" to "false"
whenever(post.recipientId).thenReturn("Sone2".asOptional())
val replyParameters = command.execute(parameters).replyParameters
verifyPostWithLikes(replyParameters)
}
private fun setupAllPostsAndReplies() {
- parameters.putSingle("Sone", "ValidSoneId")
+ parameters += "Sone" to "ValidSoneId"
whenever(localSone.id).thenReturn("ValidSoneId")
whenever(core.getSone("ValidSoneId")).thenReturn(localSone.asOptional())
whenever(core.getSone("Friend1")).thenReturn(friend1.asOptional())
@Test
fun `request with larger start than number of posts returns empty feed`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "20")
+ parameters += "StartPost" to "20"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("0"))
@Test
fun `request with max posts of 2 returns the first two posts`() {
setupAllPostsAndReplies()
- parameters.putSingle("MaxPosts", "2")
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("2"))
@Test
fun `request with max posts of 2 and start post of 1 returns the center two posts`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "1")
- parameters.putSingle("MaxPosts", "2")
+ parameters += "StartPost" to "1"
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("2"))
@Test
fun `request with max posts of 2 and start post of 3 returns the last post`() {
setupAllPostsAndReplies()
- parameters.putSingle("StartPost", "3")
- parameters.putSingle("MaxPosts", "2")
+ parameters += "StartPost" to "3"
+ parameters += "MaxPosts" to "2"
val replyParameters = command.execute(parameters).replyParameters
assertThat(replyParameters["Message"], equalTo("PostFeed"))
assertThat(replyParameters["Posts.Count"], equalTo("1"))
whenever(core.getSone("LocalSone")).thenReturn(localSone.asOptional())
whenever(core.getSone("ValidSoneId")).thenReturn(remoteSone.asOptional())
whenever(remoteSone.posts).thenReturn(listOf(post2, post1))
- parameters.putSingle("Sone", "ValidSoneId")
+ parameters += "Sone" to "ValidSoneId"
}
private fun verifyFirstPost(replyParameters: SimpleFieldSet, index: Int = 0) {
}
protected fun requestWithEmptySoneParameterResultsInFcpException() {
- parameters.putSingle("Sone", null)
+ parameters += "Sone" to null
executeCommandAndExpectFcpException()
}
protected fun requestWithInvalidSoneParameterResultsInFcpException() {
- parameters.putSingle("Sone", "InvalidSoneId")
+ parameters += "Sone" to "InvalidSoneId"
executeCommandAndExpectFcpException()
}
fun requestWithValidRemoteSoneParameterResultsInFcpException() {
- parameters.putSingle("Sone", "RemoteSoneId")
+ parameters += "Sone" to "RemoteSoneId"
whenever(core.getSone("RemoteSoneId")).thenReturn(Optional.of(remoteSone))
executeCommandAndExpectFcpException()
}
- protected operator fun SimpleFieldSet.plusAssign(keyValue: Pair<String, String>) = putSingle(keyValue.first, keyValue.second)
+ protected operator fun SimpleFieldSet.plusAssign(keyValue: Pair<String, String?>) = putSingle(keyValue.first, keyValue.second)
protected fun SimpleFieldSet.parsePost(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Recipient", "Time", "Text")
protected fun SimpleFieldSet.parseReply(prefix: String) = parseFromSimpleFieldSet(prefix, "ID", "Sone", "Time", "Text")