mirror of https://github.com/usbharu/Hideout.git
test: メディアアップロードのテストを追加
This commit is contained in:
parent
fcb3d39881
commit
a91bb89859
|
@ -180,6 +180,7 @@ dependencies {
|
|||
implementation("org.postgresql:postgresql:42.6.0")
|
||||
implementation("com.twelvemonkeys.imageio:imageio-webp:3.10.0")
|
||||
implementation("org.apache.tika:tika-core:2.9.1")
|
||||
implementation("org.apache.tika:tika-parsers:2.9.1")
|
||||
implementation("net.coobird:thumbnailator:0.4.20")
|
||||
implementation("org.bytedeco:javacv-platform:1.5.9")
|
||||
implementation("org.flywaydb:flyway-core")
|
||||
|
@ -208,6 +209,7 @@ dependencies {
|
|||
intTestImplementation("org.springframework.security:spring-security-test")
|
||||
intTestImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version")
|
||||
intTestImplementation("org.jetbrains.kotlinx:kotlinx-coroutines-test:1.6.4")
|
||||
intTestImplementation("org.mockito.kotlin:mockito-kotlin:4.1.0")
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package mastodon
|
||||
|
||||
import dev.usbharu.hideout.SpringApplication
|
||||
import dev.usbharu.hideout.core.service.media.MediaDataStore
|
||||
import dev.usbharu.hideout.core.service.media.MediaSaveRequest
|
||||
import dev.usbharu.hideout.core.service.media.SuccessSavedMedia
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.kotlin.any
|
||||
import org.mockito.kotlin.doReturn
|
||||
import org.mockito.kotlin.whenever
|
||||
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.mock.web.MockMultipartFile
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority
|
||||
import org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.jwt
|
||||
import org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers
|
||||
import org.springframework.test.context.jdbc.Sql
|
||||
import org.springframework.test.web.servlet.MockMvc
|
||||
import org.springframework.test.web.servlet.multipart
|
||||
import org.springframework.test.web.servlet.setup.DefaultMockMvcBuilder
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
import org.springframework.web.context.WebApplicationContext
|
||||
|
||||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@AutoConfigureMockMvc
|
||||
@Transactional
|
||||
@Sql("/sql/test-user.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
class MediaTest {
|
||||
|
||||
@Autowired
|
||||
private lateinit var context: WebApplicationContext
|
||||
|
||||
private lateinit var mockMvc: MockMvc
|
||||
|
||||
|
||||
@MockBean
|
||||
private lateinit var mediaDataStore: MediaDataStore
|
||||
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
mockMvc = MockMvcBuilders.webAppContextSetup(context)
|
||||
.apply<DefaultMockMvcBuilder>(SecurityMockMvcConfigurers.springSecurity())
|
||||
.build()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun メディアをアップロードできる() = runTest {
|
||||
whenever(mediaDataStore.save(any<MediaSaveRequest>())).doReturn(SuccessSavedMedia("", "", ""))
|
||||
|
||||
mockMvc
|
||||
.multipart("/api/v1/media") {
|
||||
|
||||
file(
|
||||
MockMultipartFile(
|
||||
"file",
|
||||
"400x400.png",
|
||||
"image/png",
|
||||
String.javaClass.classLoader.getResourceAsStream("media/400x400.png")
|
||||
)
|
||||
)
|
||||
with(jwt().jwt { it.claim("uid", "1") }.authorities(SimpleGrantedAuthority("SCOPE_write")))
|
||||
}
|
||||
.asyncDispatch()
|
||||
.andExpect { status { isOk() } }
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
|
@ -0,0 +1,19 @@
|
|||
package dev.usbharu.hideout.core.service.media
|
||||
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.io.path.toPath
|
||||
|
||||
class ApatcheTikaFileTypeDeterminationServiceTest {
|
||||
@Test
|
||||
fun png() {
|
||||
val apatcheTikaFileTypeDeterminationService = ApatcheTikaFileTypeDeterminationService()
|
||||
|
||||
val mimeType = apatcheTikaFileTypeDeterminationService.fileType(
|
||||
String.javaClass.classLoader.getResource("400x400.png").toURI().toPath(), "400x400.png"
|
||||
)
|
||||
|
||||
assertThat(mimeType.type).isEqualTo("image")
|
||||
assertThat(mimeType.subtype).isEqualTo("png")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package dev.usbharu.hideout.core.service.media
|
||||
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class MediaServiceImplTest {
|
||||
@Test
|
||||
fun png画像をアップロードできる() {
|
||||
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 7.1 KiB |
Loading…
Reference in New Issue