I got implementation like this:
@Serviceclass AbcService {private final RestClient client; public AbcService(@Value("url") final String url) { this.restClient = RestClient.builder().baseUrl(url).build(); } String getPlace(String id) { return restClient.get() .uri("places/{id}", id) .retrieve() .body(String.class); }}
and I tried test with MockRestServiceServer
but it doesn't work for me - I have error
java.lang.IllegalStateException: Unable to use auto-configured MockRestServiceServer since a mock server customizer has not been bound to a RestTemplate or RestClient
test
@RestClientTest(AbcService.class)class AbcServiceTest { @Autowired AbcService instance; @Autowired MockRestServiceServer server; @BeforeEach void setup() { System.setProperty("url", "server123"); } @Test void test() { server .expect(requestTo("places/id1")) .andRespond(withSuccess("string", APPLICATION_JSON)); assertEquals("string", instance.getPlace("id1")); }}
Can you help me with that?