Added a couple of tests for ImageController
This commit is contained in:
parent
8d0a5217a5
commit
a3bcade36b
52
src/test/kotlin/uk/co/neviyn/booru/ImageControllerTest.kt
Normal file
52
src/test/kotlin/uk/co/neviyn/booru/ImageControllerTest.kt
Normal file
@ -0,0 +1,52 @@
|
||||
package uk.co.neviyn.booru
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
import org.mockito.Mockito
|
||||
import org.mockito.Mockito.doReturn
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.mock.mockito.MockBean
|
||||
import org.springframework.data.domain.PageImpl
|
||||
import org.springframework.data.domain.PageRequest
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders
|
||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers
|
||||
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
internal class ImageControllerTest {
|
||||
|
||||
@Autowired
|
||||
lateinit var mockMvc: MockMvc
|
||||
|
||||
@MockBean
|
||||
lateinit var imageRepository: ImageRepository
|
||||
|
||||
@Test
|
||||
fun `get an empty gallery page`(){
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/gallery"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||
.andExpect(MockMvcResultMatchers.view().name("gallery"))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("imagePage", null))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("commonTags", null))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("pageNumber", null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `get a gallery page with a single page of images`() {
|
||||
val images = listOf(
|
||||
Image(id = 1, filename = "image1.jpg"),
|
||||
Image(id = 2, filename = "image2.jpg")
|
||||
)
|
||||
val page = PageImpl(images)
|
||||
doReturn(page).`when`(imageRepository).findAll(Mockito.any(PageRequest::class.java))
|
||||
mockMvc.perform(MockMvcRequestBuilders.get("/gallery"))
|
||||
.andExpect(MockMvcResultMatchers.status().isOk)
|
||||
.andExpect(MockMvcResultMatchers.view().name("gallery"))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("imagePage", page))
|
||||
.andExpect(MockMvcResultMatchers.model().attribute("pageNumber", 1))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user