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