1 package net.pterodactylus.sone.web.page
3 import com.google.inject.*
4 import freenet.client.*
5 import freenet.clients.http.*
6 import net.pterodactylus.sone.test.*
7 import net.pterodactylus.sone.web.*
8 import net.pterodactylus.util.web.*
9 import org.hamcrest.MatcherAssert.*
10 import org.hamcrest.Matchers.*
13 private val highLevelSimpleClient = mock<HighLevelSimpleClient>()
14 private val sessionManager = mock<SessionManager>()
15 private const val pathPrefix = "/some/prefix/"
17 class PageToadletFactoryTest {
19 private val pageToadletFactory = PageToadletFactory(highLevelSimpleClient, sessionManager, pathPrefix)
22 fun `page toadlet without menu name is created without menu name`() {
23 val page = mock<Page<FreenetRequest>>()
24 val pageToadlet = pageToadletFactory.createPageToadlet(page)
25 assertThat(pageToadlet.menuName, nullValue())
29 fun `page toadlet with menu name is created with menu name`() {
30 val page = mock<Page<FreenetRequest>>()
31 val pageToadlet = pageToadletFactory.createPageToadlet(page, "testName")
32 assertThat(pageToadlet.menuName, equalTo("testName"))
36 fun `path prefix is handed down correctly`() {
37 val page = mock<Page<FreenetRequest>>().apply {
38 whenever(path).thenReturn("path")
40 val pageToadlet = pageToadletFactory.createPageToadlet(page)
41 assertThat(pageToadlet.path(), equalTo("/some/prefix/path"))
45 fun `menu name is added from annotation when no menu name is given`() {
46 val page = TestPageWithMenuName()
47 val pageToadlet = pageToadletFactory.createPageToadlet(page)
48 assertThat(pageToadlet.menuName, equalTo("testName"))
52 fun `menu name from annotation is ignored when menu name is given`() {
53 val page = TestPageWithMenuName()
54 val pageToadlet = pageToadletFactory.createPageToadlet(page, "foo")
55 assertThat(pageToadlet.menuName, equalTo("foo"))
59 fun `page toadlet factory can be created by guice`() {
60 val injector = Guice.createInjector(
61 HighLevelSimpleClient::class.isProvidedBy(highLevelSimpleClient),
62 SessionManager::class.isProvidedBy(sessionManager),
63 String::class.withNameIsProvidedBy("/Sone/", "toadletPathPrefix")
65 assertThat(injector.getInstance<PageToadletFactory>(), notNullValue())
71 private class TestPageWithMenuName : Page<FreenetRequest> {
73 override fun getPath() = ""
74 override fun isPrefixPage() = false
75 override fun handleRequest(request: FreenetRequest, response: Response) = response