🔀 Merge branch 'release/v82'
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / page / SoneRequestTest.kt
1 package net.pterodactylus.sone.web.page
2
3 import freenet.clients.http.*
4 import freenet.support.api.*
5 import net.pterodactylus.sone.core.*
6 import net.pterodactylus.sone.test.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.util.web.*
9 import org.hamcrest.MatcherAssert.*
10 import org.hamcrest.Matchers.*
11 import org.junit.*
12 import org.mockito.*
13 import java.net.*
14
15 class SoneRequestTest {
16
17         private val uri = URI(".")
18         private val method = Method.GET
19         private val httpRequest = Mockito.mock(HTTPRequest::class.java)
20         private val toadletContext = Mockito.mock(ToadletContext::class.java)
21         private val core = mock<Core>()
22         private val webInterface = mock<WebInterface>()
23         private val soneRequest = SoneRequest(uri, method, httpRequest, toadletContext, core, webInterface)
24
25         @Test
26         fun `freenet request properties are retained correctly`() {
27                 assertThat(soneRequest.uri, equalTo(uri))
28                 assertThat(soneRequest.method, equalTo(method))
29                 assertThat(soneRequest.httpRequest, equalTo(httpRequest))
30                 assertThat(soneRequest.toadletContext, equalTo(toadletContext))
31         }
32
33         @Test
34         fun `core is retained correctly`() {
35                 assertThat(soneRequest.core, sameInstance(core))
36         }
37
38         @Test
39         fun `web interface is retained correctly`() {
40                 assertThat(soneRequest.webInterface, sameInstance(webInterface))
41         }
42
43         @Test
44         fun `freenet request is wrapped correctly`() {
45             val freenetRequest = FreenetRequest(uri, method, httpRequest, toadletContext)
46                 val wrappedSoneRequest = freenetRequest.toSoneRequest(core, webInterface)
47                 assertThat(wrappedSoneRequest.uri, equalTo(uri))
48                 assertThat(wrappedSoneRequest.method, equalTo(method))
49                 assertThat(wrappedSoneRequest.httpRequest, equalTo(httpRequest))
50                 assertThat(wrappedSoneRequest.toadletContext, equalTo(toadletContext))
51                 assertThat(wrappedSoneRequest.core, sameInstance(core))
52                 assertThat(wrappedSoneRequest.webInterface, sameInstance(webInterface))
53         }
54
55 }