open class FreenetTemplatePage(
private val path: String,
private val templateContextFactory: TemplateContextFactory,
- private val loaders: Loaders,
- private val template: Template,
+ loaders: Loaders,
+ template: Template,
private val invalidFormPasswordRedirectTarget: String
) : FreenetPage, LinkEnabledCallback {
override fun isEnabled(toadletContext: ToadletContext) = !isFullAccessOnly
+ private val template = templatePath?.let(loaders::loadTemplate) ?: template
+
override fun handleRequest(request: FreenetRequest, response: Response): Response {
getRedirectTarget(request)?.let { redirectTarget -> return RedirectResponse(redirectTarget) }
import org.hamcrest.MatcherAssert.*
import org.hamcrest.Matchers.*
import org.junit.*
-import org.mockito.ArgumentMatchers.*
+import org.mockito.Mockito.*
class FreenetTemplatePageTest {
- private val templateContextFactory = mock<TemplateContextFactory>()
+ private val templateContextFactory = deepMock<TemplateContextFactory>()
private val loaders = mock<Loaders>()
private val template = mock<Template>()
private val page = FreenetTemplatePage("/test/path", templateContextFactory, loaders, template, "invalid-form-password")
assertThat(pageResponse.headers, contains(hasHeader("location", "invalid-form-password")))
}
+ @Test
+ fun `template from annotation is loaded`() {
+ val template = deepMock<Template>()
+ whenever(loaders.loadTemplate("template-path")).thenReturn(template)
+ TestPage(templateContextFactory, loaders)
+ verify(loaders).loadTemplate("template-path")
+ }
+
+ @TemplatePath("template-path")
+ private class TestPage(templateContextFactory: TemplateContextFactory, loaders: Loaders) : FreenetTemplatePage("/", templateContextFactory, loaders, Template(), "") {
+ override fun getPath() = ""
+ override fun isPrefixPage() = false
+ override fun handleRequest(request: FreenetRequest, response: Response) = response
+ }
+
}