mirror of https://github.com/usbharu/Hideout.git
test: MediaAPIのテストを復活
This commit is contained in:
parent
33d7bcb665
commit
5cc8267135
|
@ -51,3 +51,4 @@ out/
|
|||
/http-client.private.env.json
|
||||
/logs/
|
||||
/hideout-mastodon/logs/
|
||||
/hideout-mastodon/files/
|
||||
|
|
|
@ -21,9 +21,12 @@ import dev.usbharu.hideout.core.application.media.UploadMediaApplicationService
|
|||
import dev.usbharu.hideout.core.infrastructure.springframework.oauth2.SpringSecurityOauth2PrincipalContextHolder
|
||||
import dev.usbharu.hideout.mastodon.interfaces.api.generated.MediaApi
|
||||
import dev.usbharu.hideout.mastodon.interfaces.api.generated.model.MediaAttachment
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.ResponseEntity
|
||||
import org.springframework.stereotype.Controller
|
||||
import org.springframework.web.multipart.MultipartFile
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import java.nio.file.Files
|
||||
|
||||
@Controller
|
||||
|
@ -37,6 +40,13 @@ class SpringMediaApi(
|
|||
description: String?,
|
||||
focus: String?,
|
||||
): ResponseEntity<MediaAttachment> {
|
||||
|
||||
if (file.size == 0L) {
|
||||
logger.warn("File is empty.")
|
||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "File is empty.")
|
||||
}
|
||||
|
||||
|
||||
val tempFile = Files.createTempFile("hideout-tmp-file", ".tmp")
|
||||
|
||||
Files.newOutputStream(tempFile).use { outputStream ->
|
||||
|
@ -73,4 +83,8 @@ class SpringMediaApi(
|
|||
)
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
private val logger = LoggerFactory.getLogger(SpringMediaApi::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ import org.springframework.web.context.WebApplicationContext
|
|||
@SpringBootTest(classes = [SpringApplication::class])
|
||||
@AutoConfigureMockMvc
|
||||
@Transactional
|
||||
@Sql("/sql/actors.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
@Sql("/sql/actors.sql","/sql/userdetail.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_CLASS)
|
||||
class MediaTest {
|
||||
|
||||
@Autowired
|
||||
|
|
Before Width: | Height: | Size: 7.1 KiB After Width: | Height: | Size: 7.1 KiB |
Loading…
Reference in New Issue