I got implementation like this:
@Service
class 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(AbcResponse.class);
}
record AbcResponse(String id, boolean flag) {}
}
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(new AbcResponse("string", true), APPLICATION_JSON));
assertEquals(new AbcResponse("string", true), instance.getPlace("id1"));
}
}
Can you help me with that?