From 52b087e92836e3ac36eab500ebafdd2dcdf11249 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 7 Apr 2020 20:49:11 +0200 Subject: [PATCH] =?utf8?q?=F0=9F=9A=A7=20Configure=20session=20provider=20?= =?utf8?q?in=20Sone=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/main/SoneModule.kt | 3 ++ .../net/pterodactylus/sone/main/SoneModuleTest.kt | 33 +++++++++++++--------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt index 1f92a93..a95cf78 100644 --- a/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt +++ b/src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt @@ -12,6 +12,8 @@ import net.pterodactylus.sone.database.* import net.pterodactylus.sone.database.memory.* import net.pterodactylus.sone.freenet.* import net.pterodactylus.sone.freenet.wot.* +import net.pterodactylus.sone.web.FreenetSessionProvider +import net.pterodactylus.sone.web.SessionProvider import net.pterodactylus.util.config.* import net.pterodactylus.util.config.ConfigurationException import net.pterodactylus.util.logging.* @@ -63,6 +65,7 @@ open class SoneModule(private val sonePlugin: SonePlugin, private val eventBus: bind(WebOfTrustConnector::class.java).to(PluginWebOfTrustConnector::class.java).`in`(Singleton::class.java) bind(TickerShutdown::class.java).`in`(Singleton::class.java) bind(SoneUriCreator::class.java).`in`(Singleton::class.java) + bind(SessionProvider::class.java).to(FreenetSessionProvider::class.java).`in`(Singleton::class.java) bindListener(Matchers.any(), object : TypeListener { override fun hear(typeLiteral: TypeLiteral, typeEncounter: TypeEncounter) { diff --git a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt index 676ca6b..01d1285 100644 --- a/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt @@ -4,7 +4,9 @@ import com.codahale.metrics.* import com.google.common.base.* import com.google.common.eventbus.* import com.google.inject.Guice.* +import com.google.inject.Injector import com.google.inject.name.Names.* +import freenet.clients.http.SessionManager import freenet.l10n.* import net.pterodactylus.sone.core.* import net.pterodactylus.sone.database.* @@ -13,6 +15,7 @@ import net.pterodactylus.sone.freenet.* import net.pterodactylus.sone.freenet.plugin.* import net.pterodactylus.sone.freenet.wot.* import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.web.SessionProvider import net.pterodactylus.util.config.* import net.pterodactylus.util.version.Version import org.hamcrest.MatcherAssert.* @@ -41,14 +44,7 @@ class SoneModuleTest { whenever(l10n()).thenReturn(l10n) } - private val injector by lazy { - createInjector( - SoneModule(sonePlugin, EventBus()), - FreenetInterface::class.isProvidedByDeepMock(), - PluginRespiratorFacade::class.isProvidedByDeepMock(), - PluginConnector::class.isProvidedByDeepMock() - ) - } + private val injector by lazy { createInjector() } @AfterTest fun removePropertiesFromCurrentDirectory() { @@ -198,16 +194,20 @@ class SoneModuleTest { @Test fun `core is registered with event bus`() { val eventBus = mock() - val injector = createInjector( - SoneModule(sonePlugin, eventBus), - FreenetInterface::class.isProvidedByDeepMock(), - PluginRespiratorFacade::class.isProvidedByDeepMock(), - PluginConnector::class.isProvidedByDeepMock() - ) + val injector = createInjector(eventBus) val core = injector.getInstance() verify(eventBus).register(core) } + private fun createInjector(eventBus: EventBus = EventBus()): Injector = + createInjector( + SoneModule(sonePlugin, eventBus), + FreenetInterface::class.isProvidedByDeepMock(), + PluginRespiratorFacade::class.isProvidedByDeepMock(), + PluginConnector::class.isProvidedByDeepMock(), + SessionManager::class.isProvidedByMock() + ) + @Test fun `metrics registry is created as singleton`() { injector.verifySingletonInstance() @@ -233,4 +233,9 @@ class SoneModuleTest { injector.verifySingletonInstance() } + @Test + fun `session provider is created as singleton`() { + injector.verifySingletonInstance() + } + } -- 2.7.4