윤동환
12/27/2023, 12:26 AM[오전 9:16] @AutoConfigureMockMvc
@SpringBootTest
class MyTest(
private val orderRepository: OrderRepository,
private val itemRepository: OrderItemRepository,
private val mockMvc: MockMvc,
private val objectMapper: ObjectMapper,
) : DescribeSpec({
describe("create orderLine api integration test") {
context("when api called successfully") {
// prepare dataset
val order = createOrder()
val item = createItem()
order.add(item)
orderRepository.save(order)
// when calling requestApi function,
val requestApi = {
<http://mockMvc.post|mockMvc.post>("/api/orders") {
contentType = MediaType.APPLICATION_JSON
content = objectMapper.writeValueAsString(order)
}
}
it("returns status code 200") {
requestApi().andExpect { status { isOk() } }
}
}
}
// clear dataset
afterContainer {
itemRepository.deleteAll()
orderRepository.deleteAll()
}
})
Im using DescribeSpec and usually i call IO operation methods on context container. And the test is finished, i want to clearr all changed data that prepared dataset order and orderItem and some other created or updated by calling requestApi. My idea is using PlatformTransactionManager and start or commit transaction manually… (편집됨)Emil Kantis
12/27/2023, 1:27 AM@Transactional
on your test class?