Add permanent/temporary redirect to ServerResponse

This commit adds the temporaryRedirect(URI) and permanentRedirect(URI)
static creation methods to ServerResponse.
This commit is contained in:
Arjen Poutsma
2017-02-28 15:45:06 +01:00
parent 6556b40c2b
commit 56d669f849
2 changed files with 54 additions and 9 deletions

View File

@@ -35,8 +35,9 @@ import org.springframework.http.MediaType;
import org.springframework.mock.http.server.reactive.test.MockServerHttpResponse;
import org.springframework.web.server.ServerWebExchange;
import static org.junit.Assert.*;
import static org.mockito.Mockito.*;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
/**
* @author Arjen Poutsma
@@ -104,6 +105,28 @@ public class DefaultServerResponseBuilderTests {
}
@Test
public void temporaryRedirect() throws Exception {
URI location = URI.create("http://example.com");
Mono<ServerResponse> result = ServerResponse.temporaryRedirect(location).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.TEMPORARY_REDIRECT.equals(response.statusCode()) &&
location.equals(response.headers().getLocation()))
.expectComplete()
.verify();
}
@Test
public void permanentRedirect() throws Exception {
URI location = URI.create("http://example.com");
Mono<ServerResponse> result = ServerResponse.permanentRedirect(location).build();
StepVerifier.create(result)
.expectNextMatches(response -> HttpStatus.PERMANENT_REDIRECT.equals(response.statusCode()) &&
location.equals(response.headers().getLocation()))
.expectComplete()
.verify();
}
@Test
public void badRequest() throws Exception {
Mono<ServerResponse> result = ServerResponse.badRequest().build();