Running and testing the application

We will be using the same movie model in this sample project. Since this is the only class that we need from our previous sample application, we will copy the class here. In an ideal scenario, we would have a JAR file containing all common classes, and it can be included in our pom.xml file.

Create the Run class (as seen earlier) and call the WebClient methods. The code snippet for one of the methods is as follows:

@SpringBootApplication
public class Run implements CommandLineRunner {
@Autowired
WebClientTestInterface webClient;
public static void main(String[] args) {
SpringApplication.run(Run.class, args);
}
@Override
public void run(String... args) throws Exception {
// get all movies
System.out.println("Get All Movies");
webClient.listMovies().subscribe(System.out::println);
Thread.sleep(3000);
… Other methods
}
//… Other WebClient methods getting called
}

After executing each WebClient call, we will sleep for three seconds. Since WebClient methods emit reactive types (Mono or Flux), you have to subscribe, as shown in the preceding code.

Start the spring-boot-webflux project, exposing the endpoints, which we will test by using WebClient in this project.

Make sure that your application's default port is changed in your application.properties file by including the following entry:

server.port=8081

Start the application by executing the Spring Boot command, as follows:

mvn spring-boot:run

If all goes well, you should see the output in the server console, as follows:

Figure 11: WebClient test execution
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.139.82.234