Changes because HttpMethod changed to class

This commit contains changes made because HttpMethod changed from enum
to class.

See gh-27697
This commit is contained in:
Arjen Poutsma
2021-11-25 13:45:34 +01:00
parent 6e335e3a9f
commit 7a4207cd7b
74 changed files with 337 additions and 274 deletions

View File

@@ -28,8 +28,8 @@ import java.util.Arrays;
import java.util.Base64;
import java.util.Calendar;
import java.util.Collections;
import java.util.EnumSet;
import java.util.GregorianCalendar;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map.Entry;
@@ -129,7 +129,7 @@ public class HttpHeadersTests {
@Test
void allow() {
EnumSet<HttpMethod> methods = EnumSet.of(HttpMethod.GET, HttpMethod.POST);
Set<HttpMethod> methods = new LinkedHashSet<>(Arrays.asList(HttpMethod.GET, HttpMethod.POST));
headers.setAllow(methods);
assertThat(headers.getAllow()).as("Invalid Allow header").isEqualTo(methods);
assertThat(headers.getFirst("Allow")).as("Invalid Allow header").isEqualTo("GET,POST");

View File

@@ -268,6 +268,7 @@ public class InterceptingClientHttpRequestFactoryTests {
}
@Override
@Deprecated
public String getMethodValue() {
return method.name();
}

View File

@@ -25,9 +25,9 @@ import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.EnumSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.function.Consumer;
@@ -62,8 +62,8 @@ public class ClientHttpConnectorTests {
private static final int BUF_SIZE = 1024;
private static final EnumSet<HttpMethod> METHODS_WITH_BODY =
EnumSet.of(HttpMethod.PUT, HttpMethod.POST, HttpMethod.PATCH);
private static final Set<HttpMethod> METHODS_WITH_BODY =
Set.of(HttpMethod.PUT, HttpMethod.POST, HttpMethod.PATCH);
private final MockWebServer server = new MockWebServer();

View File

@@ -23,7 +23,6 @@ import java.lang.annotation.Target;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Stream;
@@ -275,7 +274,7 @@ class RestTemplateIntegrationTests extends AbstractMockWebServerTests {
setUpClient(clientHttpRequestFactory);
Set<HttpMethod> allowed = template.optionsForAllow(new URI(baseUrl + "/get"));
assertThat(allowed).as("Invalid response").isEqualTo(EnumSet.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE));
assertThat(allowed).as("Invalid response").isEqualTo(Set.of(HttpMethod.GET, HttpMethod.OPTIONS, HttpMethod.HEAD, HttpMethod.TRACE));
}
@ParameterizedRestTemplateTest

View File

@@ -21,7 +21,6 @@ import java.io.IOException;
import java.net.URI;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -580,7 +579,7 @@ class RestTemplateTests {
mockSentRequest(OPTIONS, "https://example.com");
mockResponseStatus(HttpStatus.OK);
HttpHeaders responseHeaders = new HttpHeaders();
EnumSet<HttpMethod> expected = EnumSet.of(GET, POST);
Set<HttpMethod> expected = Set.of(GET, POST);
responseHeaders.setAllow(expected);
given(response.getHeaders()).willReturn(responseHeaders);

View File

@@ -20,7 +20,6 @@ import java.time.Duration;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
@@ -75,16 +74,6 @@ public class HiddenHttpMethodFilterTests {
assertThat(this.filterChain.getHttpMethod()).isEqualTo(HttpMethod.DELETE);
}
@Test
public void filterWithInvalidMethodValue() {
StepVerifier.create(postForm("_method=INVALID"))
.consumeErrorWith(error -> {
assertThat(error).isInstanceOf(IllegalArgumentException.class);
assertThat(error.getMessage()).isEqualTo("HttpMethod 'INVALID' not supported");
})
.verify();
}
@Test
public void filterWithHttpPut() {

View File

@@ -32,6 +32,7 @@ import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.util.LinkedMultiValueMap;
@@ -680,6 +681,12 @@ class UriComponentsBuilderTests {
void fromHttpRequestWithEmptyScheme() {
HttpRequest request = new HttpRequest() {
@Override
public HttpMethod getMethod() {
return HttpMethod.GET;
}
@Override
@Deprecated
public String getMethodValue() {
return "GET";
}