Skip to content

Deprecated MockMvcClientHttpRequestFactory is required to create a test HTTP client proxy #35989

@forketyfork

Description

@forketyfork

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: testIssues in the test modulein: webIssues in web modules (web, webmvc, webflux, websocket)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions