spring-projects / spring-projects/spring-boot
Support HTTP Interface Clients for @RestClientTest
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 81.5k
- Forks
- 42.7k
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 65
Description
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?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with @RestClientTest, AutoConfigureWebClient, and the referenced AutoConfigureWebClient.imports entry, then reproduce the HelloClient sample. Investigate how multiple HTTP client interfaces and annotation components should be selected. Done means the intended configuration is defined and the HelloClient example, including multiple-client behavior, is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring-boot
- Domain
- backend-api-design, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100