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:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user