- Kotlin
- Spring-Boot
- Exposed
- Spring-Boot Security
- KoTest
{
"loginId": "raonpark",
"password": "12345678",
"name": "raonpark",
"role": "user"
}
?loginId=raonpark&password=12345678
- 403 Forbidden인 이유는 SecurityConfig에서 permitAll을 해주지 않아서 그렇다. 테스트용 API이다.
@PathVariable id: String
return type:
{
"id": UUID,
"loginId": String,
"name": String,
"authority": String
}
{
"model": "Taylor 314CE",
"price": 3300,
"companyName": "Taylor Guitars",
"isUsed": false
}
{
"companyName": "Taylor Guitars",
"established": "1974-06-01T12:00:00"
}
- Postman을 사용한 LocalDateTime 직렬화를 할 때 제대로 되지 않아서 (KSerialize라는 클래스를 찾지 못하는 오류가 발생함) kotlinx-serialization-json 패키지와 kotlinx-datetime 패키지를 추가하여 해결할 수 있었다.
SchemaUtils.create(MemberTable, BoardTable)
given("게시판에 글을 쓸 유저 한 명이 주어진다.") {
val user = transaction {
MemberTable.insertAndGetId {
it[loginId] = "raonpark"
it[name] = "박수민"
it[password] = "1234"
it[authority] = "USER"
}
}
`when`("게시판에 raonpark 아이디를 가진 유저가 글을 쓴다.") {
transaction {
BoardTable.insert {
it[title] = "테일러 314CE 사실 분?"
it[content] = "테일러 314CE 2년 안됐는데 사실 분 구합니다."
it[image] = "asdfawerw"
it[username] = user
it[published] = CurrentDateTime
it[type] = TypeOfBoard.TRADING
}
}
then("게시판에 새로운 글 하나가 올라왔다.") {
transaction { BoardTable.selectAll().count() } shouldBeGreaterThan 0
}
}
이 경우에서 Database.connect()는 괜찮지만 SchemaUtils.create()는 transaction {} 블록에 넣어야 no transaction in context 문제가 해결된다.
- 해결 못하고 mock을 걷어내는 것으로 해결했다..
- 굳이 H2에다가 Exposed를 사용하는데 mock까지 사용할 필요는 없는것 같다.
- mockk에 대해서 조금 공부할 필요는 있을 것 같다.