mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Add MediaType parameter to ApiVersionInserter
Closes gh-35259
This commit is contained in:
@@ -26,6 +26,7 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.client.JdkClientHttpRequestFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -73,6 +74,12 @@ public class RestClientVersionTests {
|
||||
expectRequest(request -> assertThat(request.getTarget()).isEqualTo("/path?api-version=1.2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void mediaTypeParam() {
|
||||
performRequest(ApiVersionInserter.useMediaTypeParam("v"));
|
||||
expectRequest(request -> assertThat(request.getHeaders().get("Content-Type")).isEqualTo("application/json;v=1.2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void pathSegmentIndexLessThanSize() {
|
||||
performRequest(ApiVersionInserter.builder().usePathSegment(0).withVersionFormatter(v -> "v" + v).build());
|
||||
@@ -103,7 +110,8 @@ public class RestClientVersionTests {
|
||||
|
||||
private void performRequest(ApiVersionInserter versionInserter) {
|
||||
restClientBuilder.apiVersionInserter(versionInserter).build()
|
||||
.get().uri("/path")
|
||||
.post().uri("/path")
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.apiVersion(1.2)
|
||||
.retrieve()
|
||||
.body(String.class);
|
||||
|
||||
Reference in New Issue
Block a user