Axel
05/08/2023, 2:18 PM@ExtendWith(SpringExtension::class)
@WebMvcTest(GetStoresByMarket::class)
internal class GetStoresByMarketTest {
@Autowired
private lateinit var mockMvc: MockMvc
@MockBean
private lateinit var getStoresByMarketAndConsumerId: GetStoresByMarketAndConsumerId
@MockBean
private lateinit var getStoresByMarketAndCategoryAndConsumerId: GetStoresByMarketAndCategoryAndConsumerId
@Test
fun `when market is unknown a client error should be returned`() {
mockMvc.get("/v1/stores/asd") {
param("consumerId", UUID.randomUUID().toString())
}.andExpect {
status { isBadRequest() }
}
}
}
the endpoint it tests is suspend
, so the test fails with this output:
MockHttpServletRequest:
HTTP Method = GET
Request URI = /v1/stores/asd
Parameters = {consumerId=[2d80c908-3699-4bf2-8eb8-ea1069de108a]}
Headers = []
Body = null
Session Attrs = {}
Handler:
Type = com.foo.http.v1.stores.GetStoresByMarket
Method = com.foo.http.v1.stores.GetStoresByMarket#getStoresByMarket(String, String, String, Integer, Integer, Continuation)
Async:
Async started = true
Async result = org.springframework.web.server.ResponseStatusException: 400 BAD_REQUEST
Resolved Exception:
Type = null
ModelAndView:
View name = null
View = null
Model = null
FlashMap:
Attributes = null
MockHttpServletResponse:
Status = 200
Error message = null
Headers = []
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
Status expected:<400> but was:<200>
Expected :400
Actual :200
How do I make sure I get the async result back in the test? I have tried variations of runBlocking
and runTest
to availIvan Pavlov
05/08/2023, 2:52 PMAxel
05/08/2023, 2:57 PM