X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FDeletePostCommandTest.kt;fp=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Ffcp%2FDeletePostCommandTest.kt;h=4a236020bce53a82194da797a3489c2491e84c80;hb=10d9eb5fcea8440b9ea06a3732678b286090934f;hp=0000000000000000000000000000000000000000;hpb=92adeef899fe2798c0952a6585463448cbf56c94;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt new file mode 100644 index 0000000..4a23602 --- /dev/null +++ b/src/test/kotlin/net/pterodactylus/sone/fcp/DeletePostCommandTest.kt @@ -0,0 +1,59 @@ +package net.pterodactylus.sone.fcp + +import com.google.common.base.Optional.of +import net.pterodactylus.sone.core.Core +import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.freenet.fcp.FcpException +import net.pterodactylus.sone.test.mock +import net.pterodactylus.sone.test.whenever +import org.hamcrest.MatcherAssert.assertThat +import org.hamcrest.Matchers.equalTo +import org.junit.Test +import org.mockito.Mockito +import org.mockito.Mockito.verify + +/** + * Unit test for [DeletePostCommand]. + */ +class DeletePostCommandTest : SoneCommandTest() { + + private val postFromRemoteSone = mock().apply { whenever(sone).thenReturn(remoteSone) } + private val postFromLocalSone = mock().apply { whenever(sone).thenReturn(localSone) } + override fun createCommand(core: Core) = DeletePostCommand(core) + + @Test + fun `command requires write access`() { + assertThat(command.requiresWriteAccess(), equalTo(true)) + } + + @Test + fun `request without any parameter results in fcp exception`() { + requestWithoutAnyParameterResultsInFcpException() + } + + @Test + fun `request with invalid post parameter results in fcp exception`() { + parameters.putSingle("Post", "InvalidPostId") + expectedException.expect(FcpException::class.java) + command.execute(parameters, null, null) + } + + @Test + fun `request with post from remote sone returns error response`() { + parameters.putSingle("Post", "RemotePostId") + whenever(core.getPost("RemotePostId")).thenReturn(of(postFromRemoteSone)) + val response = command.execute(parameters, null, null) + assertThat(response.replyParameters["Message"], equalTo("Error")) + assertThat(response.replyParameters["ErrorCode"], equalTo("401")) + } + + @Test + fun `request with post from local sone deletes posts`() { + parameters.putSingle("Post", "LocalPostId") + whenever(core.getPost("LocalPostId")).thenReturn(of(postFromLocalSone)) + val response = command.execute(parameters, null, null) + assertThat(response.replyParameters["Message"], equalTo("PostDeleted")) + verify(core).deletePost(postFromLocalSone) + } + +}