I want to configure Spring feign with a configuration class, and I want to make sure that all the @Bean
methods are called when Spring configures the feign client for me.
How to test it?
For example, I have:
@FeignClient(
name = "PreAuthSendRequest",
url = "${xxx.services.preauth.send.url}",
configuration = AppFeignConfig.class)
public interface RequestService {
@PostMapping("")
@Headers("Content-Type: application/json")
PreAuthResponse execute(@RequestBody PreAuthRequest preAuthRequest);
}
And AppFeignConfig.java
:
@Configuration
@RequiredArgsConstructor
public class AppFeignConfig{
private final HttpClient httpClient;
private final Jackson2ObjectMapperBuilder contextObjectMapperBuilder;
@Bean
public ApacheHttpClient client() {
return new ApacheHttpClient(httpClient);
}
@Bean
public Decoder feignDecoder() {
return new JacksonDecoder((ObjectMapper)contextObjectMapperBuilder.build());
}
@Bean
public Encoder feignEncoder() {
return new JacksonEncoder((ObjectMapper)contextObjectMapperBuilder.build());
}
@Bean
public Retryer retryer() {
return Retryer.NEVER_RETRY;
}
@Bean
public ErrorDecoder errorDecoder() {
return new ServiceResponseErrorDecoder();
}
}
So, how to verify that all @Bean
methods are called? I know @MockBean
, but what I want to check is config.feignDecoder()
, etc., are indeed called.
When I am trying to context.getBean(RequestService.class);
and call execute()
method, it seems to send a real request and without wiremock, it fails, obviously.