package net.pterodactylus.sone.web.pages
import com.google.common.eventbus.EventBus
-import freenet.clients.http.ToadletContext
+import freenet.clients.http.*
import freenet.support.SimpleReadOnlyArrayBucket
import freenet.support.api.HTTPRequest
import freenet.support.api.HTTPUploadedFile
import net.pterodactylus.sone.data.Sone
import net.pterodactylus.sone.data.TemporaryImage
import net.pterodactylus.sone.freenet.wot.OwnIdentity
+import net.pterodactylus.sone.main.*
import net.pterodactylus.sone.test.deepMock
import net.pterodactylus.sone.test.get
import net.pterodactylus.sone.test.mock
import net.pterodactylus.sone.utils.asList
import net.pterodactylus.sone.utils.asOptional
import net.pterodactylus.sone.web.WebInterface
-import net.pterodactylus.sone.web.page.FreenetRequest
+import net.pterodactylus.sone.web.page.*
import net.pterodactylus.sone.web.page.FreenetTemplatePage.RedirectException
import net.pterodactylus.util.notify.Notification
import net.pterodactylus.util.template.Template
/**
* Base class for web page tests.
*/
-open class WebPageTest(pageSupplier: (Template, WebInterface) -> SoneTemplatePage = { _, _ -> mock<SoneTemplatePage>() }) {
+open class WebPageTest(pageSupplier: (Template, WebInterface, Loaders) -> SoneTemplatePage = { _, _, _ -> mock() }) {
val currentSone = mock<Sone>()
+ val loaders = mock<Loaders>()
val template = mock<Template>()
val webInterface = deepMock<WebInterface>()
val core = webInterface.core
val eventBus = mock<EventBus>()
val preferences = Preferences(eventBus)
val l10n = webInterface.l10n!!
+ val sessionManager = mock<SessionManager>()
+
+ val page by lazy { pageSupplier(template, webInterface, loaders) }
- val page by lazy { pageSupplier(template, webInterface) }
val httpRequest = mock<HTTPRequest>()
val freenetRequest = mock<FreenetRequest>()
+ init {
+ whenever(freenetRequest.l10n).thenReturn(l10n)
+ whenever(freenetRequest.sessionManager).thenReturn(sessionManager)
+ whenever(freenetRequest.uri).thenReturn(mock())
+ }
+ val soneRequest by lazy { freenetRequest.toSoneRequest(core, webInterface) }
val templateContext = TemplateContext()
val toadletContext = deepMock<ToadletContext>()
val responseContent = ByteArrayOutputStream()
whenever(core.getSone(anyString())).then { allSones[it[0]] }
whenever(core.localSones).then { localSones.values }
whenever(core.getLocalSone(anyString())).then { localSones[it[0]] }
- whenever(core.getPost(anyString())).then { allPosts[it[0]].asOptional() }
- whenever(core.getPostReply(anyString())).then { allPostReplies[it[0]].asOptional() }
+ whenever(core.getPost(anyString())).then { allPosts[it[0]] }
+ whenever(core.getPostReply(anyString())).then { allPostReplies[it[0]] }
whenever(core.getReplies(anyString())).then { perPostReplies[it[0]].asList() }
whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] }
whenever(core.getImage(anyString())).then { allImages[it[0]]}
}
private fun setupWebInterface() {
+ whenever(webInterface.sessionManager).thenReturn(sessionManager)
whenever(webInterface.getCurrentSoneCreatingSession(eq(toadletContext))).thenReturn(currentSone)
whenever(webInterface.getCurrentSone(eq(toadletContext), anyBoolean())).thenReturn(currentSone)
whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(currentSone)
}
fun addHttpRequestParameter(name: String, value: String) {
- getRequestParameters[name] = getRequestParameters.getOrElse(name) { mutableListOf<String>() }.apply { add(value) }
+ getRequestParameters[name] = getRequestParameters.getOrElse(name) { mutableListOf() }.apply { add(value) }
}
fun addHttpRequestPart(name: String, value: String) {