mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-23 22:59:03 +00:00
Update RestTestClient ExchangeResult
to expose request and URI template information and to have toString See gh-34428
This commit is contained in:
+13
-3
@@ -16,12 +16,16 @@
|
||||
|
||||
package org.springframework.test.web.servlet.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ResponseCookie;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -47,9 +51,14 @@ public class CookieAssertionsTests {
|
||||
.sameSite("Lax")
|
||||
.build();
|
||||
|
||||
private final CookieAssertions assertions = cookieAssertions(cookie);
|
||||
private CookieAssertions assertions;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
void setUp() throws IOException {
|
||||
this.assertions = cookieAssertions(cookie);
|
||||
}
|
||||
|
||||
@Test
|
||||
void valueEquals() {
|
||||
assertions.valueEquals("foo", "bar");
|
||||
@@ -135,12 +144,13 @@ public class CookieAssertionsTests {
|
||||
}
|
||||
|
||||
|
||||
private CookieAssertions cookieAssertions(ResponseCookie cookie) {
|
||||
private CookieAssertions cookieAssertions(ResponseCookie cookie) throws IOException {
|
||||
RestClient.RequestHeadersSpec.ConvertibleClientHttpResponse response = mock();
|
||||
var headers = new HttpHeaders();
|
||||
headers.set(HttpHeaders.SET_COOKIE, cookie.toString());
|
||||
when(response.getHeaders()).thenReturn(headers);
|
||||
ExchangeResult result = new ExchangeResult(response);
|
||||
when(response.getStatusCode()).thenReturn(HttpStatusCode.valueOf(200));
|
||||
ExchangeResult result = new ExchangeResult(new MockClientHttpRequest(), response, null);
|
||||
return new CookieAssertions(result, mock());
|
||||
}
|
||||
|
||||
|
||||
+10
-1
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.test.web.servlet.client;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.time.ZoneId;
|
||||
import java.time.ZonedDateTime;
|
||||
@@ -26,7 +27,9 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.http.CacheControl;
|
||||
import org.springframework.http.ContentDisposition;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -311,10 +314,16 @@ class HeaderAssertionTests {
|
||||
}
|
||||
|
||||
private HeaderAssertions headerAssertions(HttpHeaders responseHeaders) {
|
||||
try {
|
||||
RestClient.RequestHeadersSpec.ConvertibleClientHttpResponse response = mock();
|
||||
when(response.getStatusCode()).thenReturn(HttpStatusCode.valueOf(200));
|
||||
when(response.getHeaders()).thenReturn(responseHeaders);
|
||||
ExchangeResult result = new ExchangeResult(response);
|
||||
ExchangeResult result = new ExchangeResult(new MockClientHttpRequest(), response, null);
|
||||
return new HeaderAssertions(result, mock());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-1
@@ -20,8 +20,10 @@ import java.io.IOException;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.mock.http.client.MockClientHttpRequest;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -255,7 +257,8 @@ class StatusAssertionTests {
|
||||
try {
|
||||
RestClient.RequestHeadersSpec.ConvertibleClientHttpResponse response = mock();
|
||||
when(response.getStatusCode()).thenReturn(HttpStatusCode.valueOf(status));
|
||||
ExchangeResult result = new ExchangeResult(response);
|
||||
when(response.getHeaders()).thenReturn(new HttpHeaders());
|
||||
ExchangeResult result = new ExchangeResult(new MockClientHttpRequest(), response, null);
|
||||
return new StatusAssertions(result, mock());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
|
||||
Reference in New Issue
Block a user