1 package net.pterodactylus.sone.web.page
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.*
15 class SoneRequestTest {
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)
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))
34 fun `core is retained correctly`() {
35 assertThat(soneRequest.core, sameInstance(core))
39 fun `web interface is retained correctly`() {
40 assertThat(soneRequest.webInterface, sameInstance(webInterface))
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))