generated from aura-ascend/template-service
update AccountService with getById
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package ltd.lulz.service
|
package ltd.lulz.service
|
||||||
|
|
||||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||||
|
import java.util.UUID
|
||||||
import ltd.lulz.model.AccountEntity
|
import ltd.lulz.model.AccountEntity
|
||||||
import ltd.lulz.repository.AccountRepository
|
import ltd.lulz.repository.AccountRepository
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
@@ -16,4 +17,7 @@ class AccountService(
|
|||||||
fun create(entity: AccountEntity): Mono<AccountEntity> = accountRepository
|
fun create(entity: AccountEntity): Mono<AccountEntity> = accountRepository
|
||||||
.save(entity)
|
.save(entity)
|
||||||
.doOnNext { log.debug { "account created with id: ${it.id}" } }
|
.doOnNext { log.debug { "account created with id: ${it.id}" } }
|
||||||
|
|
||||||
|
fun getById(id: UUID): Mono<AccountEntity> = accountRepository.findById(id)
|
||||||
|
.doOnNext { log.debug { "found account by id: ${it.id}" } }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,4 +50,23 @@ class AccountServiceTest {
|
|||||||
|
|
||||||
verify { repository.save(any()) }
|
verify { repository.save(any()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `get by id`() {
|
||||||
|
// given
|
||||||
|
val capture = slot<UUID>()
|
||||||
|
every { repository.findById(capture(capture)) }
|
||||||
|
.answers { Mono.just(AccountEntity(capture.captured, name, amount)) }
|
||||||
|
|
||||||
|
// when stepped
|
||||||
|
StepVerifier.create(service.getById(uuid))
|
||||||
|
.assertNext { result ->
|
||||||
|
assertThat(result.id).isEqualTo(uuid)
|
||||||
|
assertThat(result.name).isEqualTo(name)
|
||||||
|
assertThat(result.amount).isEqualTo(amount)
|
||||||
|
}
|
||||||
|
.verifyComplete()
|
||||||
|
|
||||||
|
verify { repository.findById(any(UUID::class)) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user