Fix tests by parsing the created JSON reply
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / fcp / LockSoneCommandTest.kt
1 package net.pterodactylus.sone.fcp
2
3 import net.pterodactylus.sone.core.Core
4 import net.pterodactylus.sone.test.whenever
5 import net.pterodactylus.sone.utils.asOptional
6 import org.hamcrest.MatcherAssert.assertThat
7 import org.hamcrest.Matchers.equalTo
8 import org.junit.Before
9 import org.junit.Test
10 import org.mockito.Mockito.verify
11
12 /**
13  * Unit test for [LockSoneCommand].
14  */
15 class LockSoneCommandTest : SoneCommandTest() {
16
17         override fun createCommand(core: Core) = LockSoneCommand(core)
18
19         @Before
20         fun setupSones() {
21                 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone.asOptional())
22                 whenever(core.getSone("LocalSoneId")).thenReturn(localSone.asOptional())
23                 whenever(localSone.id).thenReturn("LocalSoneId")
24         }
25
26         @Test
27         fun `command requires write access`() {
28                 assertThat(command.requiresWriteAccess(), equalTo(true))
29         }
30
31         @Test
32         fun `request without any parameters results in FCP exception`() {
33             requestWithoutAnyParameterResultsInFcpException()
34         }
35
36         @Test
37         fun `request with invalid sone parameter results in FCP exception`() {
38             requestWithInvalidSoneParameterResultsInFcpException()
39         }
40
41         @Test
42         fun `request with valid remote sone parameter results in FCP exception`() {
43             requestWithValidRemoteSoneParameterResultsInFcpException()
44         }
45         
46         @Test
47         fun `request with local sone parameter locks the sone`() {
48             parameters += "Sone" to "LocalSoneId"
49                 val replyParameters = command.execute(parameters).replyParameters
50                 assertThat(replyParameters["Message"], equalTo("SoneLocked"))
51                 assertThat(replyParameters["Sone"], equalTo("LocalSoneId"))
52                 verify(core).lockSone(localSone)
53         }
54
55 }