spring-framework
spring-framework copied to clipboard
Deprecated MockMvcClientHttpRequestFactory is required to create a test HTTP client proxy
MockMvcClientHttpRequestFactory was deprecated in Spring 7 with the following deprecation message: Deprecated in favor of RestTestClient.bindTo(MockMvc).
I use this factory in the following test code, to create a test client proxy from an HTTP service interface:
fun myApiTestClient(mockMvc: MockMvc): MyApi {
val testRestClient = RestClient.builder()
.requestFactory(MockMvcClientHttpRequestFactory(mockMvc))
.build()
val adapter = RestClientAdapter.create(testRestClient)
val testHttpServiceProxyFactory = HttpServiceProxyFactory.builderFor(adapter).build()
return testHttpServiceProxyFactory.createClient<MyApi>()
}
// ...
@HttpExchange(accept = [MediaType.APPLICATION_JSON_VALUE])
interface MyApi {
@GetExchange("/example")
fun example(): ExampleResponse
}
However, I couldn't find an adapter for HttpServiceProxyFactory that would allow to use it with RestTestClient instead of RestClient.
Is there a proper way to create a test client proxy with mock MVC in Spring 7, or can this be supported?