Expose getStatusCode from ServerHttpResponse

This commit is contained in:
Rossen Stoyanchev 2016-07-05 11:10:36 -04:00
parent 7401d10f91
commit 2068f667f3
8 changed files with 20 additions and 14 deletions

View File

@ -97,7 +97,8 @@ public abstract class AbstractServerHttpResponse implements ServerHttpResponse {
return false;
}
protected HttpStatus getStatusCode() {
@Override
public HttpStatus getStatusCode() {
return this.statusCode;
}

View File

@ -40,8 +40,13 @@ public interface ServerHttpResponse extends ReactiveHttpOutputMessage {
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();
/**

View File

@ -54,7 +54,7 @@ public class MockServerHttpResponse implements ServerHttpResponse {
return true;
}
public HttpStatus getStatus() {
public HttpStatus getStatusCode() {
return this.status;
}

View File

@ -192,7 +192,7 @@ public class DispatcherHandlerErrorTests {
Mono<Void> publisher = webHandler.handle(this.exchange);
publisher.block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
}
@Test
@ -204,7 +204,7 @@ public class DispatcherHandlerErrorTests {
Mono<Void> publisher = webHandler.handle(this.exchange);
publisher.block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
}

View File

@ -67,7 +67,7 @@ public class ResponseStatusExceptionHandlerTests {
Mono<Void> publisher = this.handler.handle(this.exchange, ex);
publisher.block();
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
}
@Test

View File

@ -145,7 +145,7 @@ public class ResponseEntityResultHandlerTests {
HandlerResult result = handlerResult(value, type);
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());
assertNull(this.response.getBody());
}
@ -158,7 +158,7 @@ public class ResponseEntityResultHandlerTests {
HandlerResult result = handlerResult(value, type);
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(location, this.response.getHeaders().getLocation());
assertNull(this.response.getBody());
@ -188,7 +188,7 @@ public class ResponseEntityResultHandlerTests {
HandlerResult result = handlerResult(returnValue, type);
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"));
assertResponseBody("abc");
}

View File

@ -64,7 +64,7 @@ public class ExceptionHandlingHttpHandlerTests {
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
createWebHandler(exceptionHandler).handle(this.exchange).block();
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
}
@Test
@ -77,7 +77,7 @@ public class ExceptionHandlingHttpHandlerTests {
};
createWebHandler(exceptionHandlers).handle(this.exchange).block();
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatus());
assertEquals(HttpStatus.BAD_REQUEST, this.response.getStatusCode());
}
@Test
@ -85,7 +85,7 @@ public class ExceptionHandlingHttpHandlerTests {
WebExceptionHandler exceptionHandler = new UnresolvedExceptionHandler();
createWebHandler(exceptionHandler).handle(this.exchange).block();
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatus());
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, this.response.getStatusCode());
}
@Test
@ -93,7 +93,7 @@ public class ExceptionHandlingHttpHandlerTests {
WebExceptionHandler exceptionHandler = new BadRequestExceptionHandler();
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) {

View File

@ -117,7 +117,7 @@ public class FilteringWebHandlerTests {
.filters(new ExceptionFilter()).exceptionHandlers(exceptionHandler).build();
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;
assertNotNull(savedException);