Add support for @ExceptionHandler methods
This commit is contained in:
@@ -21,7 +21,6 @@ import org.junit.Before;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.http.server.reactive.boot.HttpServer;
|
||||
import org.springframework.http.server.reactive.boot.JettyHttpServer;
|
||||
import org.springframework.http.server.reactive.boot.ReactorHttpServer;
|
||||
|
||||
@@ -31,7 +31,7 @@ import reactor.Publishers;
|
||||
import reactor.core.publisher.PublisherFactory;
|
||||
import reactor.core.subscriber.SubscriberBarrier;
|
||||
import reactor.rx.Streams;
|
||||
import reactor.rx.action.Signal;
|
||||
import reactor.rx.stream.Signal;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
@@ -55,6 +55,7 @@ import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.server.reactive.AbstractHttpHandlerIntegrationTests;
|
||||
import org.springframework.http.server.reactive.HttpHandler;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.ExceptionHandler;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
@@ -122,6 +123,30 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
|
||||
assertEquals("Hello!", response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleWithThrownException() throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
URI url = new URI("http://localhost:" + port + "/thrown-exception");
|
||||
RequestEntity<Void> request = RequestEntity.get(url).build();
|
||||
ResponseEntity<String> response = restTemplate.exchange(request, String.class);
|
||||
|
||||
assertEquals("Recovered from error: Boo", response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void handleWithErrorSignal() throws Exception {
|
||||
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
||||
URI url = new URI("http://localhost:" + port + "/error-signal");
|
||||
RequestEntity<Void> request = RequestEntity.get(url).build();
|
||||
ResponseEntity<String> response = restTemplate.exchange(request, String.class);
|
||||
|
||||
assertEquals("Recovered from error: Boo", response.getBody());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void serializeAsPojo() throws Exception {
|
||||
serializeAsPojo("http://localhost:" + port + "/person");
|
||||
@@ -478,6 +503,24 @@ public class RequestMappingIntegrationTests extends AbstractHttpHandlerIntegrati
|
||||
return personStream.toList().doOnNext(persons::addAll).flatMap(document -> Observable.empty());
|
||||
}
|
||||
|
||||
@RequestMapping("/thrown-exception")
|
||||
@ResponseBody
|
||||
public Publisher<String> handleAndThrowException() {
|
||||
throw new IllegalStateException("Boo");
|
||||
}
|
||||
|
||||
@RequestMapping("/error-signal")
|
||||
@ResponseBody
|
||||
public Publisher<String> handleWithError() {
|
||||
return Publishers.error(new IllegalStateException("Boo"));
|
||||
}
|
||||
|
||||
@ExceptionHandler
|
||||
@ResponseBody
|
||||
public Publisher<String> handleException(IllegalStateException ex) {
|
||||
return Streams.just("Recovered from error: " + ex.getMessage());
|
||||
}
|
||||
|
||||
//TODO add mixed and T request mappings tests
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user