🔥 Remove templates from FreenetTemplatePages
[Sone.git] / src / test / kotlin / net / pterodactylus / sone / web / pages / CreateAlbumPageTest.kt
index 9851530..b0db24d 100644 (file)
@@ -4,13 +4,15 @@ import net.pterodactylus.sone.data.Album
 import net.pterodactylus.sone.data.Album.Modifier
 import net.pterodactylus.sone.data.Album.Modifier.AlbumTitleMustNotBeEmpty
 import net.pterodactylus.sone.test.deepMock
+import net.pterodactylus.sone.test.getInstance
 import net.pterodactylus.sone.test.selfMock
 import net.pterodactylus.sone.test.whenever
-import net.pterodactylus.sone.web.pages.WebPageTest
-import net.pterodactylus.sone.web.pages.CreateAlbumPage
+import net.pterodactylus.sone.web.baseInjector
+import net.pterodactylus.sone.web.page.*
 import net.pterodactylus.util.web.Method.POST
 import org.hamcrest.MatcherAssert.assertThat
 import org.hamcrest.Matchers.equalTo
+import org.hamcrest.Matchers.notNullValue
 import org.junit.Before
 import org.junit.Test
 import org.mockito.Mockito.verify
@@ -18,11 +20,7 @@ import org.mockito.Mockito.verify
 /**
  * Unit test for [CreateAlbumPage].
  */
-class CreateAlbumPageTest: WebPageTest() {
-
-       private val page = CreateAlbumPage(template, webInterface)
-
-       override fun getPage() = page
+class CreateAlbumPageTest : WebPageTest(::CreateAlbumPage) {
 
        private val parentAlbum = createAlbum("parent-id")
        private val newAlbum = createAlbum("album-id")
@@ -45,7 +43,7 @@ class CreateAlbumPageTest: WebPageTest() {
 
        @Test
        fun `missing name results in attribute being set in template context`() {
-               request("", POST)
+               setMethod(POST)
                page.processTemplate(freenetRequest, templateContext)
                assertThat(templateContext["nameMissing"], equalTo<Any>(true))
        }
@@ -60,7 +58,7 @@ class CreateAlbumPageTest: WebPageTest() {
 
        @Test
        fun `title and description are set correctly on the album`() {
-               request("", POST)
+               setMethod(POST)
                addAlbum("parent-id", parentAlbum)
                addHttpRequestPart("name", "new name")
                addHttpRequestPart("description", "new description")
@@ -76,7 +74,7 @@ class CreateAlbumPageTest: WebPageTest() {
 
        @Test
        fun `root album is used if no parent is specified`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("name", "new name")
                addHttpRequestPart("description", "new description")
                verifyRedirect("imageBrowser.html?album=album-id")
@@ -84,7 +82,7 @@ class CreateAlbumPageTest: WebPageTest() {
 
        @Test
        fun `empty album title redirects to error page`() {
-               request("", POST)
+               setMethod(POST)
                whenever(newAlbum.modify().update()).thenThrow(AlbumTitleMustNotBeEmpty::class.java)
                addHttpRequestPart("name", "new name")
                addHttpRequestPart("description", "new description")
@@ -93,7 +91,7 @@ class CreateAlbumPageTest: WebPageTest() {
 
        @Test
        fun `album description is filtered`() {
-               request("", POST)
+               setMethod(POST)
                addHttpRequestPart("name", "new name")
                addHttpRequestPart("description", "new http://localhost:12345/KSK@foo description")
                addHttpRequestHeader("Host", "localhost:12345")
@@ -102,4 +100,14 @@ class CreateAlbumPageTest: WebPageTest() {
                }
        }
 
+       @Test
+       fun `page can be created by dependency injection`() {
+               assertThat(baseInjector.getInstance<CreateAlbumPage>(), notNullValue())
+       }
+
+       @Test
+       fun `page is annotated with correct template path`() {
+           assertThat(page.templatePath, equalTo("/templates/createAlbum.html"))
+       }
+
 }