🚧 Configure session provider in Sone module
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 18:49:11 +0000 (20:49 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 7 Apr 2020 18:49:11 +0000 (20:49 +0200)
src/main/kotlin/net/pterodactylus/sone/main/SoneModule.kt
src/test/kotlin/net/pterodactylus/sone/main/SoneModuleTest.kt

index 1f92a93..a95cf78 100644 (file)
@@ -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 <I> hear(typeLiteral: TypeLiteral<I>, typeEncounter: TypeEncounter<I>) {
index 676ca6b..01d1285 100644 (file)
@@ -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<EventBus>()
-               val injector = createInjector(
-                               SoneModule(sonePlugin, eventBus),
-                               FreenetInterface::class.isProvidedByDeepMock(),
-                               PluginRespiratorFacade::class.isProvidedByDeepMock(),
-                               PluginConnector::class.isProvidedByDeepMock()
-               )
+               val injector = createInjector(eventBus)
                val core = injector.getInstance<Core>()
                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<MetricRegistry>()
@@ -233,4 +233,9 @@ class SoneModuleTest {
                injector.verifySingletonInstance<SoneUriCreator>()
        }
 
+       @Test
+       fun `session provider is created as singleton`() {
+               injector.verifySingletonInstance<SessionProvider>()
+       }
+
 }