java-allandsundry.com

Unit test for Spring's WebClient

WebClient to quote its Java documentation is Spring Framework's Non-blocking, reactive client to perform HTTP requests, exposing a fluent, reactive API over underlying HTTP client libraries such as Reactor Netty.In my current project I have been using WebClient extensively in making service to service calls and have found it to be an awesome API and I love its use of fluent interface. Consider a remote service which returns a list of "Cities". A code using WebClient looks like this:...import org.springframework.http.MediaTypeimport...

mrhaki

Spocklight: Use Stub or Mock For Spring Component Using @SpringBean

When we write tests or specifications using Spock for our Spring Boot application, we might want to replace some Spring components with a stub or mock version. With the stub or mock version we can write expected outcomes and behaviour in our specifications. Since Spock 1.2 and the Spock Spring extension we can use the @SpringBean annotation to replace a Spring component with a stub or mock version. (This is quite similar as the @MockBean for Mockito mocks that is supported by Spring Boot). We only have to declare a variable in our...

java-allandsundry.com

Chicken and egg - resolving Spring properties ahead of a test

Consider a service class responsible for making a remote call and retrieving a detail:...public class CitiesService { private final WebClient.Builder webClientBuilder; private final String baseUrl; public CitiesService( WebClient.Builder webClientBuilder, @Value("${cityservice.url}") String baseUrl) { this.webClientBuilder = webClientBuilder; this.baseUrl = baseUrl; } public Flux<City> getCities() { return this.webClientBuilder.build() .get()....This is a...

stackabuse.com

Spring Annotations: Testing

Introduction The Spring Framework is a very robust framework, released in 2002. Its core features can be applied to plain Java applications or extended to complex, modern web applications. As it's constantly being updated and is following new architectural and programming paradigms, it offers support for many other frameworks that work hand-in-hand with it. With such a vast array of functionalities, it's only normal that it introduces us to some new annotations, which are a key part of developing Spring applications. Spring's configuration is...

stackabuse.com

Spring Annotations: Spring Cloud

Introduction The Spring Framework is a very robust framework, released in 2002. Its core features can be applied to plain Java applications or extended to complex, modern web applications. As it's constantly being updated and is following new architectural and programming paradigms, it offers support for many other frameworks that work hand-in-hand with it. With such a vast array of functionalities, it's only normal that it introduces us to some new annotations, which are a key part of developing Spring applications. Spring's configuration is...