Expose getStatusCode from ServerHttpResponse
This commit is contained in:
parent
7401d10f91
commit
2068f667f3
|
@ -97,7 +97,8 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HttpStatus getStatusCode() {
|
@Override
|
||||||
|
public HttpStatus getStatusCode() {
|
||||||
return this.statusCode;
|
return this.statusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,8 +40,13 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
|
||||||
boolean setStatusCode(HttpStatus status);
|
boolean setStatusCode(HttpStatus status);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a mutable map with the cookies to send to the server.
|
* Return the HTTP status code or {@code null} if not set.
|
||||||
*/
|
*/
|
||||||
|
HttpStatus getStatusCode();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return a mutable map with the cookies to send to the server.
|
||||||
|
*/
|
||||||
MultiValueMap<String, ResponseCookie> getCookies();
|
MultiValueMap<String, ResponseCookie> getCookies();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public HttpStatus getStatus() {
|
public HttpStatus getStatusCode() {
|
||||||
return this.status;
|
return this.status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -192,7 +192,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
Mono<Void> publisher = webHandler.handle(this.exchange);
|
Mono<Void> publisher = webHandler.handle(this.exchange);
|
||||||
|
|
||||||
publisher.block();
|
publisher.block();
|
||||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -204,7 +204,7 @@ public class DispatcherHandlerErrorTests {
|
||||||
Mono<Void> publisher = webHandler.handle(this.exchange);
|
Mono<Void> publisher = webHandler.handle(this.exchange);
|
||||||
|
|
||||||
publisher.block();
|
publisher.block();
|
||||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -67,7 +67,7 @@ public class ResponseStatusExceptionHandlerTests {
|
||||||
Mono<Void> publisher = this.handler.handle(this.exchange, ex);
|
Mono<Void> publisher = this.handler.handle(this.exchange, ex);
|
||||||
|
|
||||||
publisher.block();
|
publisher.block();
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
|
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -145,7 +145,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
HandlerResult result = handlerResult(value, type);
|
HandlerResult result = handlerResult(value, type);
|
||||||
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.NO_CONTENT, this.response.getStatus());
|
assertEquals(HttpStatus.NO_CONTENT, this.response.getStatusCode());
|
||||||
assertEquals(0, this.response.getHeaders().size());
|
assertEquals(0, this.response.getHeaders().size());
|
||||||
assertNull(this.response.getBody());
|
assertNull(this.response.getBody());
|
||||||
}
|
}
|
||||||
|
@ -158,7 +158,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
HandlerResult result = handlerResult(value, type);
|
HandlerResult result = handlerResult(value, type);
|
||||||
this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.CREATED, this.response.getStatus());
|
assertEquals(HttpStatus.CREATED, this.response.getStatusCode());
|
||||||
assertEquals(1, this.response.getHeaders().size());
|
assertEquals(1, this.response.getHeaders().size());
|
||||||
assertEquals(location, this.response.getHeaders().getLocation());
|
assertEquals(location, this.response.getHeaders().getLocation());
|
||||||
assertNull(this.response.getBody());
|
assertNull(this.response.getBody());
|
||||||
|
@ -188,7 +188,7 @@ public class ResponseEntityResultHandlerTests {
|
||||||
HandlerResult result = handlerResult(returnValue, type);
|
HandlerResult result = handlerResult(returnValue, type);
|
||||||
this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5));
|
this.resultHandler.handleResult(this.exchange, result).block(Duration.ofSeconds(5));
|
||||||
|
|
||||||
assertEquals(HttpStatus.OK, this.response.getStatus());
|
assertEquals(HttpStatus.OK, this.response.getStatusCode());
|
||||||
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getFirst("Content-Type"));
|
assertEquals("text/plain;charset=UTF-8", this.response.getHeaders().getFirst("Content-Type"));
|
||||||
assertResponseBody("abc");
|
assertResponseBody("abc");
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class ExceptionHandlingHttpHandlerTests {
|
||||||
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
|
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
|
||||||
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
||||||
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
|
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -77,7 +77,7 @@ public class ExceptionHandlingHttpHandlerTests {
|
||||||
};
|
};
|
||||||
createWebHandler(exceptionHandlers).handle(this.exchange).block();
|
createWebHandler(exceptionHandlers).handle(this.exchange).block();
|
||||||
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
|
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -85,7 +85,7 @@ public class ExceptionHandlingHttpHandlerTests {
|
||||||
WebExceptionHandler exceptionHandler = new UnresolvedExceptionHandler();
|
WebExceptionHandler exceptionHandler = new UnresolvedExceptionHandler();
|
||||||
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
||||||
|
|
||||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -93,7 +93,7 @@ public class ExceptionHandlingHttpHandlerTests {
|
||||||
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
|
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
|
||||||
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
createWebHandler(exceptionHandler).handle(this.exchange).block();
|
||||||
|
|
||||||
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
|
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
private WebHandler createWebHandler(WebExceptionHandler... handlers) {
|
private WebHandler createWebHandler(WebExceptionHandler... handlers) {
|
||||||
|
|
|
@ -117,7 +117,7 @@ public class FilteringWebHandlerTests {
|
||||||
.filters(new ExceptionFilter()).exceptionHandlers(exceptionHandler).build();
|
.filters(new ExceptionFilter()).exceptionHandlers(exceptionHandler).build();
|
||||||
handler.handle(this.request, this.response).block();
|
handler.handle(this.request, this.response).block();
|
||||||
|
|
||||||
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
|
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
|
||||||
|
|
||||||
Throwable savedException = exceptionHandler.ex;
|
Throwable savedException = exceptionHandler.ex;
|
||||||
assertNotNull(savedException);
|
assertNotNull(savedException);
|
||||||
|
|
Loading…
Reference in New Issue