X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FWebPageTest2.kt;h=bf328a7691cd3990a3ad66cbd64990c0a612ae9d;hb=6a03d8624a9b1872f6e3eeb259f5d49b4a5686a3;hp=6c4372d3ca7ab3673827a453acfcad44ec8b7f62;hpb=ce75a1d1a837cd33046c0da5098240c3629f7df7;p=Sone.git diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt index 6c4372d..bf328a7 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/WebPageTest2.kt @@ -4,12 +4,17 @@ import com.google.common.eventbus.EventBus import freenet.clients.http.ToadletContext import freenet.support.api.HTTPRequest import net.pterodactylus.sone.core.Preferences +import net.pterodactylus.sone.data.Album +import net.pterodactylus.sone.data.Image import net.pterodactylus.sone.data.Post +import net.pterodactylus.sone.data.PostReply import net.pterodactylus.sone.data.Sone +import net.pterodactylus.sone.freenet.wot.OwnIdentity import net.pterodactylus.sone.test.deepMock import net.pterodactylus.sone.test.get import net.pterodactylus.sone.test.mock import net.pterodactylus.sone.test.whenever +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 @@ -51,19 +56,30 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla private val requestHeaders = mutableMapOf() private val getRequestParameters = mutableMapOf>() private val postRequestParameters = mutableMapOf() + private val ownIdentities = mutableSetOf() private val allSones = mutableMapOf() private val localSones = mutableMapOf() private val allPosts = mutableMapOf() + private val allPostReplies = mutableMapOf() + private val perPostReplies = mutableMapOf() + private val allAlbums = mutableMapOf() + private val allImages = mutableMapOf() private val translations = mutableMapOf() @Before fun setupCore() { whenever(core.preferences).thenReturn(preferences) + whenever(core.identityManager.allOwnIdentities).then { ownIdentities } whenever(core.sones).then { allSones.values } whenever(core.getSone(anyString())).then { allSones[it[0]].asOptional() } 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.getReplies(anyString())).then { perPostReplies[it[0]].asList() } + whenever(core.getAlbum(anyString())).then { allAlbums[it[0]] } + whenever(core.getImage(anyString())).then { allImages[it[0]]} + whenever(core.getImage(anyString(), anyBoolean())).then { allImages[it[0]]} } @Before @@ -88,6 +104,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla whenever(httpRequest.getLongParam(anyString(), anyLong())).then { getRequestParameters[it[0]]?.first()?.toLongOrNull() ?: it[1] } whenever(httpRequest.getMultipleParam(anyString())).then { getRequestParameters[it[0]]?.toTypedArray() ?: emptyArray() } whenever(httpRequest.getMultipleIntParam(anyString())).then { getRequestParameters[it[0]]?.map { it.toIntOrNull() ?: 0 } ?: emptyArray() } + whenever(httpRequest.isPartSet(anyString())).then { it[0] in postRequestParameters } whenever(httpRequest.getPartAsStringFailsafe(anyString(), anyInt())).then { postRequestParameters[it[0]]?.decode()?.take(it[1]) ?: "" } } @@ -133,6 +150,10 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla whenever(webInterface.getCurrentSoneWithoutCreatingSession(eq(toadletContext))).thenReturn(null) } + fun addOwnIdentity(ownIdentity: OwnIdentity) { + ownIdentities += ownIdentity + } + fun addSone(id: String, sone: Sone) { allSones[id] = sone } @@ -145,6 +166,19 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla allPosts[id] = post } + fun addPostReply(id: String, postReply: PostReply) { + allPostReplies[id] = postReply + postReply.postId?.also { perPostReplies[it] = postReply } + } + + fun addAlbum(id: String, album: Album) { + allAlbums[id] = album + } + + fun addImage(id: String, image: Image) { + allImages[id] = image + } + fun addTranslation(key: String, value: String) { translations[key] = value } @@ -159,7 +193,7 @@ abstract class WebPageTest2(pageSupplier: (Template, WebInterface) -> SoneTempla caughtException?.run { throw this } ?: assertions() } - fun verifyRedirect(target: String, assertions: () -> Unit) { + fun verifyRedirect(target: String, assertions: () -> Unit = {}) { try { page.handleRequest(freenetRequest, templateContext) fail()