pageToadletRegistry.addPage(new EmptyImageTitlePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new EmptyAlbumTitlePage(this, loaders, templateRenderer));
pageToadletRegistry.addPage(new DismissNotificationPage(this, loaders, templateRenderer));
- if (getCore().getDebug()) {
- pageToadletRegistry.addPage(new MetricsPage(this, loaders, templateRenderer, metricRegistry));
- }
+ pageToadletRegistry.addDebugPage(new MetricsPage(this, loaders, templateRenderer, metricRegistry));
pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("css/", "/static/css/", "text/css"));
pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("javascript/", "/static/javascript/", "text/javascript"));
pageToadletRegistry.addPage(loaders.<FreenetRequest>loadStaticPage("images/", "/static/images/", "image/png"));
) {
private val pages = mutableListOf<Page<FreenetRequest>>()
+ private val debugPages = mutableListOf<Page<FreenetRequest>>()
private val registeredToadlets = mutableListOf<PageToadlet>()
private val registered = AtomicBoolean(false)
pages += page
}
+ fun addDebugPage(page: Page<FreenetRequest>) {
+ if (registered.get()) throw IllegalStateException()
+ debugPages += page
+ }
+
fun registerToadlets() {
registered.set(true)
pageMaker.addNavigationCategory("/Sone/index.html", soneMenuName, "$soneMenu.Tooltip", sonePlugin)
addPages()
}
- private fun addPages() =
+ private fun addPages(pages: List<Page<FreenetRequest>> = this.pages) =
pages
.map { pageToadletFactory.createPageToadlet(it) }
.onEach(registeredToadlets::plusAssign)
registeredToadlets.forEach(toadletContainer::unregister)
}
+ fun activateDebugMode() =
+ addPages(debugPages)
+
}
import org.junit.*
import org.junit.rules.*
import org.mockito.Mockito.*
+import kotlin.test.Test
class PageToadletRegistryTest {
verify(toadletContainer).unregister(toadletWithMenuname)
}
+ @Test
+ fun `adding a debug page will not add it to the container`() {
+ val toadlet = createPageToadlet()
+ whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+ pageToadletRegistry.addDebugPage(page)
+ pageToadletRegistry.registerToadlets()
+ verify(toadletContainer, never()).register(toadlet, null, "/Sone/", true, false)
+ }
+
+ @Test
+ fun `adding a debug page and activating debug mode will add it to the container`() {
+ val toadlet = createPageToadlet()
+ whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+ pageToadletRegistry.addDebugPage(page)
+ pageToadletRegistry.registerToadlets()
+ pageToadletRegistry.activateDebugMode()
+ verify(toadletContainer).register(toadlet, null, "/Sone/", true, false)
+ }
+
+ @Test
+ fun `debug pages are ungegistered from the container`() {
+ val toadlet = createPageToadlet()
+ whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+ pageToadletRegistry.addDebugPage(page)
+ pageToadletRegistry.registerToadlets()
+ pageToadletRegistry.activateDebugMode()
+ pageToadletRegistry.unregisterToadlets()
+ verify(toadletContainer).unregister(toadlet)
+ }
+
+ @Test
+ fun `inactive debug pages are not ungegistered from the container`() {
+ val toadlet = createPageToadlet()
+ whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+ pageToadletRegistry.addDebugPage(page)
+ pageToadletRegistry.registerToadlets()
+ pageToadletRegistry.unregisterToadlets()
+ verify(toadletContainer, never()).unregister(toadlet)
+ }
+
+ @Test
+ fun `debug page can not be added after registering`() {
+ val toadlet = createPageToadlet()
+ whenever(pageToadletFactory.createPageToadlet(page)).thenReturn(toadlet)
+ pageToadletRegistry.registerToadlets()
+ expectedException.expect(IllegalStateException::class.java)
+ pageToadletRegistry.addDebugPage(page)
+ }
+
private fun createPageToadlet(menuName: String? = null) =
mock<PageToadlet>().apply {
whenever(this.path()).thenReturn("/Sone/")