JAVA-3090: updating README.md for spring-reactive
This commit is contained in:
@@ -1,17 +1,16 @@
|
||||
## Spring Reactive
|
||||
|
||||
This module contains articles about Spring Reactor.
|
||||
This module contains articles describing reactive processing in Spring.
|
||||
|
||||
## Relevant articles:
|
||||
|
||||
- [Introduction to Project Reactor Bus](https://www.baeldung.com/reactor-bus)
|
||||
- [Intro To Reactor Core](https://www.baeldung.com/reactor-core)
|
||||
- [Debugging Reactive Streams in Java](https://www.baeldung.com/spring-debugging-reactive-streams)
|
||||
- [Guide to Spring 5 WebFlux](https://www.baeldung.com/spring-webflux)
|
||||
- [Introduction to the Functional Web Framework in Spring 5](https://www.baeldung.com/spring-5-functional-web)
|
||||
- [Spring 5 WebClient](https://www.baeldung.com/spring-5-webclient)
|
||||
- [Spring WebClient vs. RestTemplate](https://www.baeldung.com/spring-webclient-resttemplate)
|
||||
- [https://www.baeldung.com/webflux-webclient-parameters](https://www.baeldung.com/webflux-webclient-parameters)
|
||||
- [Spring WebClient Requests with Parameters](https://www.baeldung.com/webflux-webclient-parameters)
|
||||
- [Handling Errors in Spring WebFlux](https://www.baeldung.com/spring-webflux-errors)
|
||||
- [Spring Security 5 for Reactive Applications](https://www.baeldung.com/spring-security-5-reactive)
|
||||
- [https://www.baeldung.com/spring-webflux-concurrency](https://www.baeldung.com/spring-webflux-concurrency)
|
||||
- [Concurrency in Spring WebFlux](https://www.baeldung.com/spring-webflux-concurrency)
|
||||
@@ -0,0 +1,176 @@
|
||||
package com.baeldung.reactive.errorhandling;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
|
||||
@DirtiesContext
|
||||
@WithMockUser
|
||||
@AutoConfigureWebTestClient(timeout = "10000")
|
||||
public class ErrorHandlingIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private WebTestClient webTestClient;
|
||||
|
||||
@Test
|
||||
public void givenErrorReturn_whenUsernamePresent_thenOk() throws IOException {
|
||||
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint1?name={username}", "Tony")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Tony", s);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenErrorReturn_whenNoUsername_thenOk() throws IOException {
|
||||
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint1")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Stranger", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeFallback_whenUsernamePresent_thenOk() throws IOException {
|
||||
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint2?name={username}", "Tony")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Tony", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeFallback_whenNoUsername_thenOk() throws IOException {
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint2")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Stranger", s);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeDynamicValue_whenUsernamePresent_thenOk() throws IOException {
|
||||
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint3?name={username}", "Tony")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Tony", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeDynamicValue_whenNoUsername_thenOk() throws IOException {
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint3")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hi, I looked around for your name but found: No value present", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeRethrow_whenUsernamePresent_thenOk() throws IOException {
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint4?name={username}", "Tony")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Tony", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenResumeRethrow_whenNoUsername_thenOk() throws IOException {
|
||||
|
||||
webTestClient.get()
|
||||
.uri("/api/endpoint4")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest()
|
||||
.expectHeader()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.expectBody()
|
||||
.jsonPath("$.message")
|
||||
.isNotEmpty()
|
||||
.jsonPath("$.message")
|
||||
.isEqualTo("please provide a name");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGlobalErrorHandling_whenUsernamePresent_thenOk() throws IOException {
|
||||
|
||||
String s = webTestClient.get()
|
||||
.uri("/api/endpoint5?name={username}", "Tony")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.returnResult(String.class)
|
||||
.getResponseBody()
|
||||
.blockFirst();
|
||||
|
||||
assertEquals("Hello, Tony", s);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenGlobalErrorHandling_whenNoUsername_thenOk() throws IOException {
|
||||
webTestClient.get()
|
||||
.uri("/api/endpoint5")
|
||||
.accept(MediaType.TEXT_PLAIN)
|
||||
.exchange()
|
||||
.expectStatus()
|
||||
.isBadRequest()
|
||||
.expectHeader()
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.expectBody()
|
||||
.jsonPath("$.message")
|
||||
.isNotEmpty()
|
||||
.jsonPath("$.message")
|
||||
.isEqualTo("please provide a name");
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user