1 package net.pterodactylus.sone.web.page
3 import freenet.clients.http.*
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.*
16 class SoneRequestTest {
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)
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))
35 fun `core is retained correctly`() {
36 assertThat(soneRequest.core, sameInstance(core))
40 fun `web interface is retained correctly`() {
41 assertThat(soneRequest.webInterface, sameInstance(webInterface))
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))