X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Ftest%2Fkotlin%2Fnet%2Fpterodactylus%2Fsone%2Fweb%2Fpages%2FCreateAlbumPageTest.kt;h=224791f434b05c83467a66bfcde7dd79f245b913;hp=c4f2ee4da333a96e6b7b8e15c0c0ff92730d8391;hb=2e6be6f2fb6afede009dacc48b8e3318e30e5057;hpb=de7568a82eb4150bf6d2b0553841b7b69f84c968 diff --git a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt index c4f2ee4..224791f 100644 --- a/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt +++ b/src/test/kotlin/net/pterodactylus/sone/web/pages/CreateAlbumPageTest.kt @@ -1,28 +1,21 @@ package net.pterodactylus.sone.web.pages -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.selfMock -import net.pterodactylus.sone.test.whenever -import net.pterodactylus.sone.web.pages.WebPageTest -import net.pterodactylus.sone.web.pages.CreateAlbumPage -import net.pterodactylus.util.web.Method.POST -import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.equalTo -import org.junit.Before -import org.junit.Test -import org.mockito.Mockito.verify +import net.pterodactylus.sone.data.* +import net.pterodactylus.sone.data.Album.* +import net.pterodactylus.sone.data.Album.Modifier.* +import net.pterodactylus.sone.test.* +import net.pterodactylus.sone.web.* +import net.pterodactylus.sone.web.page.* +import net.pterodactylus.util.web.Method.* +import org.hamcrest.MatcherAssert.* +import org.hamcrest.Matchers.* +import org.junit.* +import org.mockito.Mockito.* /** * 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 +38,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(true)) } @@ -60,11 +53,11 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `title and description are set correctly on the album`() { - request("", POST) + setMethod(POST) addAlbum("parent-id", parentAlbum) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") - addHttpRequestParameter("parent", "parent-id") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") + addHttpRequestPart("parent", "parent-id") verifyRedirect("imageBrowser.html?album=album-id") { verify(newAlbum).modify() verify(newAlbum.modify()).setTitle("new name") @@ -76,30 +69,40 @@ class CreateAlbumPageTest: WebPageTest() { @Test fun `root album is used if no parent is specified`() { - request("", POST) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") + setMethod(POST) + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") verifyRedirect("imageBrowser.html?album=album-id") } @Test fun `empty album title redirects to error page`() { - request("", POST) + setMethod(POST) whenever(newAlbum.modify().update()).thenThrow(AlbumTitleMustNotBeEmpty::class.java) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new description") + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new description") verifyRedirect("emptyAlbumTitle.html") } @Test fun `album description is filtered`() { - request("", POST) - addHttpRequestParameter("name", "new name") - addHttpRequestParameter("description", "new http://localhost:12345/KSK@foo description") + setMethod(POST) + addHttpRequestPart("name", "new name") + addHttpRequestPart("description", "new http://localhost:12345/KSK@foo description") addHttpRequestHeader("Host", "localhost:12345") verifyRedirect("imageBrowser.html?album=album-id") { verify(newAlbum.modify()).setDescription("new KSK@foo description") } } + @Test + fun `page can be created by dependency injection`() { + assertThat(baseInjector.getInstance(), notNullValue()) + } + + @Test + fun `page is annotated with correct template path`() { + assertThat(page.templatePath, equalTo("/templates/createAlbum.html")) + } + }