new client project, general cleanup, testing work
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
package com.baeldung.reactive.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@AllArgsConstructor
|
||||
@Data
|
||||
public class Foo {
|
||||
|
||||
private long id;
|
||||
private String name;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
logging.level.root=INFO
|
||||
|
||||
server.port=8081
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
# Pattern of log message for console appender
|
||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="INFO" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="stdout" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
@@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
|
||||
version="3.1">
|
||||
|
||||
<display-name>Spring Functional Application</display-name>
|
||||
|
||||
<servlet>
|
||||
<servlet-name>functional</servlet-name>
|
||||
<servlet-class>com.baeldung.functional.RootServlet</servlet-class>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
<async-supported>true</async-supported>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>functional</servlet-name>
|
||||
<url-pattern>/</url-pattern>
|
||||
</servlet-mapping>
|
||||
|
||||
|
||||
</web-app>
|
||||
+42
@@ -0,0 +1,42 @@
|
||||
package com.baeldung.reactive;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.web.reactive.function.client.ClientResponse;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import com.baeldung.reactive.model.Foo;
|
||||
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
@SpringBootTest
|
||||
public class ReactiveIntegrationTest {
|
||||
|
||||
private WebClient client;
|
||||
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
client = WebClient.create("http://localhost:8080");
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
@Test
|
||||
public void whenMonoReactiveEndpointIsConsumed_thenCorrectOutput() {
|
||||
final Mono<ClientResponse> fooMono = client.get().uri("/foos/123").exchange().log();
|
||||
|
||||
System.out.println(fooMono.subscribe());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenFluxReactiveEndpointIsConsumed_thenCorrectOutput() throws InterruptedException {
|
||||
client.get().uri("/foos")
|
||||
.retrieve()
|
||||
.bodyToFlux(Foo.class).log()
|
||||
.subscribe(System.out::println);
|
||||
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
package com.baeldung.reactive;
|
||||
|
||||
import org.springframework.boot.CommandLineRunner;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.web.reactive.function.client.WebClient;
|
||||
|
||||
import com.baeldung.reactive.model.Foo;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Spring5ReactiveTestApplication {
|
||||
|
||||
@Bean
|
||||
public WebClient client() {
|
||||
return WebClient.create("http://localhost:8080");
|
||||
}
|
||||
|
||||
@Bean
|
||||
CommandLineRunner cmd(WebClient client) {
|
||||
return args -> {
|
||||
client.get().uri("/foos2")
|
||||
.retrieve()
|
||||
.bodyToFlux(Foo.class).log()
|
||||
.subscribe(System.out::println);
|
||||
};
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Spring5ReactiveTestApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<configuration>
|
||||
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<layout class="ch.qos.logback.classic.PatternLayout">
|
||||
# Pattern of log message for console appender
|
||||
<Pattern>%d{yyyy-MM-dd HH:mm:ss} %-5p %m%n</Pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
|
||||
<logger name="org.springframework" level="INFO" />
|
||||
|
||||
<root level="INFO">
|
||||
<appender-ref ref="stdout" />
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user