Does it make sense to support a way to wire up HTTP interface clients with @RestClientTest
?
Example:
@HttpServiceClient("hello")
public interface HelloClient {
@GetExchange(value = "/hello", version = "2")
String hello();
}
@RestClientTest(HelloClientTest.class)
class HelloClientTest {
@Autowired
private HelloClient helloClient;
@Autowired
MockRestServiceServer mockRestServiceServer;
@Test
void hello() {
mockRestServiceServer.expect(requestToUriTemplate("http://localhost:8080/hello?version={version}", 2))
.andRespond(withSuccess("Hello There!", MediaType.TEXT_PLAIN));
assertThat(helloClient.hello()).isEqualTo("Hello There!");
}
}
I was able to get this to work in this Sample Repository by adding HttpServiceClientAutoConfiguration
to AutoConfigureWebClient
. This doesn't work when you define more than one HTTP client interfaces. Maybe it could use the components
defined on the annotation to pick which client to wire up? Or maybe a new @HttpServiceClientTest
?