🔀 Merge branch 'release/v82'
[Sone.git] / 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 org.hamcrest.MatcherAssert.assertThat
6 import org.hamcrest.Matchers.equalTo
7 import org.junit.Before
8 import org.junit.Test
9 import org.mockito.Mockito.verify
10
11 /**
12  * Unit test for [LockSoneCommand].
13  */
14 class LockSoneCommandTest : SoneCommandTest() {
15
16         override fun createCommand(core: Core) = LockSoneCommand(core)
17
18         @Before
19         fun setupSones() {
20                 whenever(core.getSone("RemoteSoneId")).thenReturn(remoteSone)
21                 whenever(core.getSone("LocalSoneId")).thenReturn(localSone)
22                 whenever(localSone.id).thenReturn("LocalSoneId")
23         }
24
25         @Test
26         fun `command requires write access`() {
27                 assertThat(command.requiresWriteAccess, equalTo(true))
28         }
29
30         @Test
31         fun `request without any parameters results in FCP exception`() {
32             requestWithoutAnyParameterResultsInFcpException()
33         }
34
35         @Test
36         fun `request with invalid sone parameter results in FCP exception`() {
37             requestWithInvalidSoneParameterResultsInFcpException()
38         }
39
40         @Test
41         fun `request with valid remote sone parameter results in FCP exception`() {
42             requestWithValidRemoteSoneParameterResultsInFcpException()
43         }
44         
45         @Test
46         fun `request with local sone parameter locks the sone`() {
47             parameters += "Sone" to "LocalSoneId"
48                 val replyParameters = command.execute(parameters).replyParameters
49                 assertThat(replyParameters["Message"], equalTo("SoneLocked"))
50                 assertThat(replyParameters["Sone"], equalTo("LocalSoneId"))
51                 verify(core).lockSone(localSone)
52         }
53
54 }