Early removal of 5.x-deprecated code

Closes gh-27686
This commit is contained in:
Juergen Hoeller
2021-11-18 09:18:06 +01:00
parent 17cdd97c37
commit 4750a9430c
132 changed files with 89 additions and 9216 deletions

View File

@@ -1,76 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.http.client.support;
import java.net.URI;
import org.junit.jupiter.api.Test;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.http.HttpMethod;
import org.springframework.http.client.ClientHttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link BasicAuthorizationInterceptor}.
*
* @author Phillip Webb
* @author Stephane Nicoll
*/
@SuppressWarnings("deprecation")
public class BasicAuthorizationInterceptorTests {
@Test
public void createWhenUsernameContainsColonShouldThrowException() {
assertThatIllegalArgumentException().isThrownBy(() ->
new BasicAuthorizationInterceptor("username:", "password"))
.withMessageContaining("Username must not contain a colon");
}
@Test
public void createWhenUsernameIsNullShouldUseEmptyUsername() throws Exception {
BasicAuthorizationInterceptor interceptor = new BasicAuthorizationInterceptor(
null, "password");
assertThat(new DirectFieldAccessor(interceptor).getPropertyValue("username")).isEqualTo("");
}
@Test
public void createWhenPasswordIsNullShouldUseEmptyPassword() throws Exception {
BasicAuthorizationInterceptor interceptor = new BasicAuthorizationInterceptor(
"username", null);
assertThat(new DirectFieldAccessor(interceptor).getPropertyValue("password")).isEqualTo("");
}
@Test
public void interceptShouldAddHeader() throws Exception {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
ClientHttpRequest request = requestFactory.createRequest(new URI("https://example.com"), HttpMethod.GET);
ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class);
byte[] body = new byte[] {};
new BasicAuthorizationInterceptor("spring", "boot").intercept(request, body,
execution);
verify(execution).execute(request, body);
assertThat(request.getHeaders().getFirst("Authorization")).isEqualTo("Basic c3ByaW5nOmJvb3Q=");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@ package org.springframework.http.converter.protobuf;
import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
@@ -32,10 +33,7 @@ import org.springframework.protobuf.Msg;
import org.springframework.protobuf.SecondMsg;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Test suite for {@link ProtobufHttpMessageConverter}.
@@ -45,44 +43,23 @@ import static org.mockito.Mockito.verify;
* @author Andreas Ahlenstorf
* @author Sebastien Deleuze
*/
@SuppressWarnings("deprecation")
public class ProtobufHttpMessageConverterTests {
private ProtobufHttpMessageConverter converter;
private ExtensionRegistry extensionRegistry;
private ExtensionRegistryInitializer registryInitializer;
private Msg testMsg;
@BeforeEach
public void setup() {
this.registryInitializer = mock(ExtensionRegistryInitializer.class);
this.extensionRegistry = mock(ExtensionRegistry.class);
this.converter = new ProtobufHttpMessageConverter(this.registryInitializer);
this.converter = new ProtobufHttpMessageConverter();
this.testMsg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
}
@Test
public void extensionRegistryInitialized() {
verify(this.registryInitializer, times(1)).initializeExtensionRegistry(any());
}
@Test
public void extensionRegistryInitializerNull() {
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter((ExtensionRegistryInitializer)null);
assertThat(converter.extensionRegistry).isNotNull();
}
@Test
public void extensionRegistryNull() {
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter((ExtensionRegistry)null);
assertThat(converter.extensionRegistry).isNotNull();
}
@Test
public void canRead() {
assertThat(this.converter.canRead(Msg.class, null)).isTrue();
@@ -175,7 +152,7 @@ public class ProtobufHttpMessageConverterTests {
assertThat(outputMessage.getHeaders().getContentType()).isEqualTo(contentType);
final String body = outputMessage.getBodyAsString(Charset.forName("UTF-8"));
String body = outputMessage.getBodyAsString(StandardCharsets.UTF_8);
assertThat(body.isEmpty()).as("body is empty").isFalse();
Msg.Builder builder = Msg.newBuilder();
@@ -189,12 +166,12 @@ public class ProtobufHttpMessageConverterTests {
}
@Test
public void defaultContentType() throws Exception {
public void defaultContentType() {
assertThat(this.converter.getDefaultContentType(this.testMsg)).isEqualTo(ProtobufHttpMessageConverter.PROTOBUF);
}
@Test
public void getContentLength() throws Exception {
public void getContentLength() throws IOException {
MockHttpOutputMessage outputMessage = new MockHttpOutputMessage();
MediaType contentType = ProtobufHttpMessageConverter.PROTOBUF;
this.converter.write(this.testMsg, contentType, outputMessage);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -18,7 +18,6 @@ package org.springframework.http.converter.protobuf;
import java.io.IOException;
import com.google.protobuf.ExtensionRegistry;
import com.google.protobuf.Message;
import com.google.protobuf.util.JsonFormat;
import org.junit.jupiter.api.Test;
@@ -30,10 +29,6 @@ import org.springframework.protobuf.Msg;
import org.springframework.protobuf.SecondMsg;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Test suite for {@link ProtobufJsonFormatHttpMessageConverter}.
@@ -41,34 +36,14 @@ import static org.mockito.Mockito.verify;
* @author Juergen Hoeller
* @author Sebastien Deleuze
*/
@SuppressWarnings("deprecation")
public class ProtobufJsonFormatHttpMessageConverterTests {
private final ExtensionRegistryInitializer registryInitializer = mock(ExtensionRegistryInitializer.class);
private final ProtobufHttpMessageConverter converter = new ProtobufJsonFormatHttpMessageConverter(
JsonFormat.parser(), JsonFormat.printer(), this.registryInitializer);
JsonFormat.parser(), JsonFormat.printer());
private final Msg testMsg = Msg.newBuilder().setFoo("Foo").setBlah(SecondMsg.newBuilder().setBlah(123).build()).build();
@Test
public void extensionRegistryInitialized() {
verify(this.registryInitializer, times(1)).initializeExtensionRegistry(any());
}
@Test
public void extensionRegistryInitializerNull() {
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter((ExtensionRegistryInitializer)null);
assertThat(converter).isNotNull();
}
@Test
public void extensionRegistryInitializer() {
ProtobufHttpMessageConverter converter = new ProtobufHttpMessageConverter((ExtensionRegistry)null);
assertThat(converter).isNotNull();
}
@Test
public void canRead() {
assertThat(this.converter.canRead(Msg.class, null)).isTrue();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,13 +16,11 @@
package org.springframework.web.cors.reactive;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Mono;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.adapter.ForwardedHeaderTransformer;
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpRequest;
import org.springframework.web.testfixture.server.MockServerWebExchange;
@@ -32,6 +30,7 @@ import static org.springframework.web.testfixture.http.server.reactive.MockServe
/**
* Test case for reactive {@link CorsUtils}.
*
* @author Sebastien Deleuze
* @author Rossen Stoyanchev
*/
@@ -141,15 +140,9 @@ public class CorsUtilsTests {
}
// SPR-16668
@SuppressWarnings("deprecation")
private ServerHttpRequest adaptFromForwardedHeaders(MockServerHttpRequest.BaseBuilder<?> builder) {
AtomicReference<ServerHttpRequest> requestRef = new AtomicReference<>();
MockServerWebExchange exchange = MockServerWebExchange.from(builder);
new org.springframework.web.filter.reactive.ForwardedHeaderFilter().filter(exchange, exchange2 -> {
requestRef.set(exchange2.getRequest());
return Mono.empty();
}).block();
return requestRef.get();
return new ForwardedHeaderTransformer().apply(exchange.getRequest());
}
}

View File

@@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link WebHttpHandlerBuilder}.
*
* @author Rossen Stoyanchev
*/
public class WebHttpHandlerBuilderTests {
@@ -73,7 +74,7 @@ public class WebHttpHandlerBuilderTests {
@Test
void forwardedHeaderTransformer() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(ForwardedHeaderFilterConfig.class);
context.register(ForwardedHeaderTransformerConfig.class);
context.refresh();
WebHttpHandlerBuilder builder = WebHttpHandlerBuilder.applicationContext(context);
@@ -199,7 +200,6 @@ public class WebHttpHandlerBuilderTests {
@Configuration
@SuppressWarnings("unused")
static class OrderedWebFilterBeanConfig {
private static final String ATTRIBUTE = "attr";
@@ -234,7 +234,6 @@ public class WebHttpHandlerBuilderTests {
@Configuration
@SuppressWarnings("unused")
static class OrderedExceptionHandlerBeanConfig {
@Bean
@@ -256,13 +255,11 @@ public class WebHttpHandlerBuilderTests {
}
@Configuration
@SuppressWarnings("unused")
static class ForwardedHeaderFilterConfig {
static class ForwardedHeaderTransformerConfig {
@Bean
@SuppressWarnings("deprecation")
public WebFilter forwardedHeaderFilter() {
return new org.springframework.web.filter.reactive.ForwardedHeaderFilter();
public ForwardedHeaderTransformer forwardedHeaderTransformer() {
return new ForwardedHeaderTransformer();
}
@Bean
@@ -272,7 +269,6 @@ public class WebHttpHandlerBuilderTests {
}
@Configuration
@SuppressWarnings("unused")
static class NoFilterConfig {
@Bean

View File

@@ -1,151 +0,0 @@
/*
* Copyright 2002-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.web.util;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Unit tests for {@link DefaultUriTemplateHandler}.
*
* @author Rossen Stoyanchev
*/
@SuppressWarnings("deprecation")
public class DefaultUriTemplateHandlerTests {
private final DefaultUriTemplateHandler handler = new DefaultUriTemplateHandler();
@Test
public void baseUrlWithoutPath() throws Exception {
this.handler.setBaseUrl("http://localhost:8080");
URI actual = this.handler.expand("/myapiresource");
assertThat(actual.toString()).isEqualTo("http://localhost:8080/myapiresource");
}
@Test
public void baseUrlWithPath() throws Exception {
this.handler.setBaseUrl("http://localhost:8080/context");
URI actual = this.handler.expand("/myapiresource");
assertThat(actual.toString()).isEqualTo("http://localhost:8080/context/myapiresource");
}
@Test // SPR-14147
public void defaultUriVariables() throws Exception {
Map<String, String> defaultVars = new HashMap<>(2);
defaultVars.put("host", "api.example.com");
defaultVars.put("port", "443");
this.handler.setDefaultUriVariables(defaultVars);
Map<String, Object> vars = new HashMap<>(1);
vars.put("id", 123L);
String template = "https://{host}:{port}/v42/customers/{id}";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://api.example.com:443/v42/customers/123");
}
@Test
public void parsePathIsOff() throws Exception {
this.handler.setParsePath(false);
Map<String, String> vars = new HashMap<>(2);
vars.put("hotel", "1");
vars.put("publicpath", "pics/logo.png");
String template = "https://example.com/hotels/{hotel}/pic/{publicpath}";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://example.com/hotels/1/pic/pics/logo.png");
}
@Test
public void parsePathIsOn() throws Exception {
this.handler.setParsePath(true);
Map<String, String> vars = new HashMap<>(2);
vars.put("hotel", "1");
vars.put("publicpath", "pics/logo.png");
vars.put("scale", "150x150");
String template = "https://example.com/hotels/{hotel}/pic/{publicpath}/size/{scale}";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://example.com/hotels/1/pic/pics%2Flogo.png/size/150x150");
}
@Test
public void strictEncodingIsOffWithMap() throws Exception {
this.handler.setStrictEncoding(false);
Map<String, String> vars = new HashMap<>(2);
vars.put("userId", "john;doe");
String template = "https://www.example.com/user/{userId}/dashboard";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://www.example.com/user/john;doe/dashboard");
}
@Test
public void strictEncodingOffWithArray() throws Exception {
this.handler.setStrictEncoding(false);
String template = "https://www.example.com/user/{userId}/dashboard";
URI actual = this.handler.expand(template, "john;doe");
assertThat(actual.toString()).isEqualTo("https://www.example.com/user/john;doe/dashboard");
}
@Test
public void strictEncodingOnWithMap() throws Exception {
this.handler.setStrictEncoding(true);
Map<String, String> vars = new HashMap<>(2);
vars.put("userId", "john;doe");
String template = "https://www.example.com/user/{userId}/dashboard";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://www.example.com/user/john%3Bdoe/dashboard");
}
@Test
public void strictEncodingOnWithArray() throws Exception {
this.handler.setStrictEncoding(true);
String template = "https://www.example.com/user/{userId}/dashboard";
URI actual = this.handler.expand(template, "john;doe");
assertThat(actual.toString()).isEqualTo("https://www.example.com/user/john%3Bdoe/dashboard");
}
@Test // SPR-14147
public void strictEncodingAndDefaultUriVariables() throws Exception {
Map<String, String> defaultVars = new HashMap<>(1);
defaultVars.put("host", "www.example.com");
this.handler.setDefaultUriVariables(defaultVars);
this.handler.setStrictEncoding(true);
Map<String, Object> vars = new HashMap<>(1);
vars.put("userId", "john;doe");
String template = "https://{host}/user/{userId}/dashboard";
URI actual = this.handler.expand(template, vars);
assertThat(actual.toString()).isEqualTo("https://www.example.com/user/john%3Bdoe/dashboard");
}
}