Remove APIs marked as deprecated for removal

Closes gh-33809
This commit is contained in:
Juergen Hoeller
2024-12-04 13:19:39 +01:00
parent 078d683f47
commit 2b9010c2a2
150 changed files with 141 additions and 5922 deletions

View File

@@ -304,9 +304,6 @@ public class DispatcherServlet extends FrameworkServlet {
/** Detect all ViewResolvers or just expect "viewResolver" bean?. */
private boolean detectAllViewResolvers = true;
/** Throw a NoHandlerFoundException if no Handler was found to process this request? *.*/
private boolean throwExceptionIfNoHandlerFound = true;
/** Perform cleanup of request attributes after include request?. */
private boolean cleanupAfterInclude = true;
@@ -456,26 +453,6 @@ public class DispatcherServlet extends FrameworkServlet {
this.detectAllViewResolvers = detectAllViewResolvers;
}
/**
* Set whether to throw a NoHandlerFoundException when no Handler was found for this request.
* This exception can then be caught with a HandlerExceptionResolver or an
* {@code @ExceptionHandler} controller method.
* <p>Note that if {@link org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler}
* is used, then requests will always be forwarded to the default servlet and a
* NoHandlerFoundException would never be thrown in that case.
* <p>Default is "false", meaning the DispatcherServlet sends a NOT_FOUND error through the
* Servlet response.
* @since 4.0
* @deprecated as of 6.1 this property is set to {@code true} by default, and
* should not need to be customized; in effect, {@link DispatcherServlet}
* should always raise {@link NoHandlerFoundException} and allow it to be
* handled through a {@link HandlerExceptionResolver}.
*/
@Deprecated(since = "6.1", forRemoval = true)
public void setThrowExceptionIfNoHandlerFound(boolean throwExceptionIfNoHandlerFound) {
this.throwExceptionIfNoHandlerFound = throwExceptionIfNoHandlerFound;
}
/**
* Set whether to perform cleanup of request attributes after an include request, that is,
* whether to reset the original state of all request attributes after the DispatcherServlet
@@ -1299,13 +1276,8 @@ public class DispatcherServlet extends FrameworkServlet {
if (pageNotFoundLogger.isWarnEnabled()) {
pageNotFoundLogger.warn("No mapping for " + request.getMethod() + " " + getRequestUri(request));
}
if (this.throwExceptionIfNoHandlerFound) {
throw new NoHandlerFoundException(request.getMethod(), getRequestUri(request),
new ServletServerHttpRequest(request).getHeaders());
}
else {
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
throw new NoHandlerFoundException(request.getMethod(), getRequestUri(request),
new ServletServerHttpRequest(request).getHeaders());
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2024 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.
@@ -46,6 +46,7 @@ import org.springframework.web.servlet.resource.CachingResourceTransformer;
import org.springframework.web.servlet.resource.ContentVersionStrategy;
import org.springframework.web.servlet.resource.CssLinkResourceTransformer;
import org.springframework.web.servlet.resource.FixedVersionStrategy;
import org.springframework.web.servlet.resource.LiteWebJarsResourceResolver;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
import org.springframework.web.servlet.resource.ResourceResolver;
@@ -53,7 +54,6 @@ import org.springframework.web.servlet.resource.ResourceTransformer;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.resource.WebJarsResourceResolver;
/**
* {@link org.springframework.beans.factory.xml.BeanDefinitionParser} that parses a
@@ -82,7 +82,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
private static final String RESOURCE_URL_PROVIDER = "mvcResourceUrlProvider";
private static final boolean webJarsPresent = ClassUtils.isPresent(
"org.webjars.WebJarAssetLocator", ResourcesBeanDefinitionParser.class.getClassLoader());
"org.webjars.WebJarVersionLocator", ResourcesBeanDefinitionParser.class.getClassLoader());
@Override
@@ -334,7 +334,7 @@ class ResourcesBeanDefinitionParser implements BeanDefinitionParser {
if (isAutoRegistration) {
if (webJarsPresent) {
RootBeanDefinition webJarsResolverDef = new RootBeanDefinition(WebJarsResourceResolver.class);
RootBeanDefinition webJarsResolverDef = new RootBeanDefinition(LiteWebJarsResourceResolver.class);
webJarsResolverDef.setSource(source);
webJarsResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
resourceResolvers.add(webJarsResolverDef);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2024 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.
@@ -32,7 +32,6 @@ import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.ResourceResolver;
import org.springframework.web.servlet.resource.ResourceTransformer;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.resource.WebJarsResourceResolver;
/**
* Assists with the registration of resource resolvers and transformers.
@@ -44,10 +43,7 @@ public class ResourceChainRegistration {
private static final String DEFAULT_CACHE_NAME = "spring-resource-chain-cache";
private static final boolean isWebJarAssetLocatorPresent = ClassUtils.isPresent(
"org.webjars.WebJarAssetLocator", ResourceChainRegistration.class.getClassLoader());
private static final boolean isWebJarVersionLocatorPresent = ClassUtils.isPresent(
private static final boolean webJarsPresent = ClassUtils.isPresent(
"org.webjars.WebJarVersionLocator", ResourceChainRegistration.class.getClassLoader());
@@ -93,7 +89,7 @@ public class ResourceChainRegistration {
else if (resolver instanceof PathResourceResolver) {
this.hasPathResolver = true;
}
else if (resolver instanceof WebJarsResourceResolver || resolver instanceof LiteWebJarsResourceResolver) {
else if (resolver instanceof LiteWebJarsResourceResolver) {
this.hasWebjarsResolver = true;
}
return this;
@@ -113,16 +109,12 @@ public class ResourceChainRegistration {
return this;
}
@SuppressWarnings("removal")
protected List<ResourceResolver> getResourceResolvers() {
if (!this.hasPathResolver) {
List<ResourceResolver> result = new ArrayList<>(this.resolvers);
if (isWebJarVersionLocatorPresent && !this.hasWebjarsResolver) {
if (webJarsPresent && !this.hasWebjarsResolver) {
result.add(new LiteWebJarsResourceResolver());
}
else if (isWebJarAssetLocatorPresent && !this.hasWebjarsResolver) {
result.add(new WebJarsResourceResolver());
}
result.add(new PathResourceResolver());
return result;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -65,13 +65,6 @@ abstract class AbstractServerResponse extends ErrorHandlingServerResponse {
return this.statusCode;
}
@Override
@Deprecated
@SuppressWarnings("removal")
public int rawStatusCode() {
return this.statusCode.value();
}
@Override
public final HttpHeaders headers() {
return this.headers;

View File

@@ -46,6 +46,7 @@ final class CompletedAsyncServerResponse implements AsyncServerResponse {
this.serverResponse = serverResponse;
}
@Override
public ServerResponse block() {
return this.serverResponse;
@@ -56,13 +57,6 @@ final class CompletedAsyncServerResponse implements AsyncServerResponse {
return this.serverResponse.statusCode();
}
@Override
@Deprecated
@SuppressWarnings("removal")
public int rawStatusCode() {
return this.serverResponse.rawStatusCode();
}
@Override
public HttpHeaders headers() {
return this.serverResponse.headers();
@@ -73,11 +67,12 @@ final class CompletedAsyncServerResponse implements AsyncServerResponse {
return this.serverResponse.cookies();
}
@Nullable
@Override
@Nullable
public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context)
throws ServletException, IOException {
return this.serverResponse.writeTo(request, response, context);
}
}

View File

@@ -83,13 +83,6 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple
return delegate(ServerResponse::statusCode);
}
@Override
@Deprecated
@SuppressWarnings("removal")
public int rawStatusCode() {
return delegate(ServerResponse::rawStatusCode);
}
@Override
public HttpHeaders headers() {
return delegate(ServerResponse::headers);
@@ -110,8 +103,8 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple
}
}
@Nullable
@Override
@Nullable
public ModelAndView writeTo(HttpServletRequest request, HttpServletResponse response, Context context)
throws ServletException, IOException {
@@ -164,4 +157,5 @@ final class DefaultAsyncServerResponse extends ErrorHandlingServerResponse imple
});
return result;
}
}

View File

@@ -65,14 +65,6 @@ public interface ServerResponse {
*/
HttpStatusCode statusCode();
/**
* Return the status code of this response as integer.
* @return the status as an integer
* @deprecated in favor of {@link #statusCode()}, for removal in 7.0
*/
@Deprecated(since = "6.0", forRemoval = true)
int rawStatusCode();
/**
* Return the headers of this response.
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2024 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.
@@ -135,18 +135,6 @@ public final class MappedInterceptor implements HandlerInterceptor {
}
/**
* Get the include path patterns this interceptor is mapped to.
* @see #getIncludePathPatterns()
* @see #getExcludePathPatterns()
* @deprecated since 6.1 in favor of {@link #getIncludePathPatterns()}
*/
@Nullable
@Deprecated(since = "6.1", forRemoval = true)
public String[] getPathPatterns() {
return getIncludePathPatterns();
}
/**
* Get the include path patterns this interceptor is mapped to.
* @since 6.1

View File

@@ -28,8 +28,7 @@ import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.method.support.ModelAndViewContainer;
/**
* Handler for return values of type {@link DeferredResult},
* {@link org.springframework.util.concurrent.ListenableFuture}, and
* Handler for return values of type {@link DeferredResult} and
* {@link CompletionStage}.
*
* @author Rossen Stoyanchev
@@ -37,16 +36,13 @@ import org.springframework.web.method.support.ModelAndViewContainer;
*/
public class DeferredResultMethodReturnValueHandler implements HandlerMethodReturnValueHandler {
@SuppressWarnings({"deprecation", "removal"})
@Override
public boolean supportsReturnType(MethodParameter returnType) {
Class<?> type = returnType.getParameterType();
return (DeferredResult.class.isAssignableFrom(type) ||
org.springframework.util.concurrent.ListenableFuture.class.isAssignableFrom(type) ||
CompletionStage.class.isAssignableFrom(type));
}
@SuppressWarnings({"deprecation", "removal"})
@Override
public void handleReturnValue(@Nullable Object returnValue, MethodParameter returnType,
ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
@@ -61,9 +57,6 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu
if (returnValue instanceof DeferredResult<?> deferredResult) {
result = deferredResult;
}
else if (returnValue instanceof org.springframework.util.concurrent.ListenableFuture<?> listenableFuture) {
result = adaptListenableFuture(listenableFuture);
}
else if (returnValue instanceof CompletionStage<?> completionStage) {
result = adaptCompletionStage(completionStage);
}
@@ -75,22 +68,6 @@ public class DeferredResultMethodReturnValueHandler implements HandlerMethodRetu
WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(result, mavContainer);
}
@SuppressWarnings({"deprecation", "removal"})
private DeferredResult<Object> adaptListenableFuture(org.springframework.util.concurrent.ListenableFuture<?> future) {
DeferredResult<Object> result = new DeferredResult<>();
future.addCallback(new org.springframework.util.concurrent.ListenableFutureCallback<Object>() {
@Override
public void onSuccess(@Nullable Object value) {
result.setResult(value);
}
@Override
public void onFailure(Throwable ex) {
result.setErrorResult(ex);
}
});
return result;
}
private DeferredResult<Object> adaptCompletionStage(CompletionStage<?> future) {
DeferredResult<Object> result = new DeferredResult<>();
future.whenComplete((value, ex) -> {

View File

@@ -1,125 +0,0 @@
/*
* Copyright 2002-2024 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.servlet.resource;
import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import org.webjars.WebJarAssetLocator;
import org.springframework.core.io.Resource;
import org.springframework.lang.Nullable;
/**
* A {@code ResourceResolver} that delegates to the chain to locate a resource and then
* attempts to find a matching versioned resource contained in a WebJar JAR file.
*
* <p>This allows WebJars.org users to write version agnostic paths in their templates,
* like {@code <script src="/webjars/jquery/jquery.min.js"/>}.
* This path will be resolved to the unique version {@code <script src="/webjars/jquery/1.2.0/jquery.min.js"/>},
* which is a better fit for HTTP caching and version management in applications.
*
* <p>This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
*
* <p>This resolver requires the {@code org.webjars:webjars-locator-core} library
* on the classpath and is automatically registered if that library is present.
*
* <p>Be aware that {@code WebJarAssetLocator} constructor performs a classpath scanning that
* could slow down application startup.
*
* @author Brian Clozel
* @author Sebastien Deleuze
* @since 4.2
* @see org.springframework.web.servlet.config.annotation.ResourceChainRegistration
* @see <a href="https://www.webjars.org">webjars.org</a>
* @see LiteWebJarsResourceResolver
* @deprecated as of 6.2, in favor of {@link LiteWebJarsResourceResolver}
*/
@Deprecated(since = "6.2", forRemoval = true)
public class WebJarsResourceResolver extends AbstractResourceResolver {
private static final String WEBJARS_LOCATION = "META-INF/resources/webjars/";
private static final int WEBJARS_LOCATION_LENGTH = WEBJARS_LOCATION.length();
private final WebJarAssetLocator webJarAssetLocator;
/**
* Create a {@code WebJarsResourceResolver} with a default {@code WebJarAssetLocator} instance.
*/
public WebJarsResourceResolver() {
this(new WebJarAssetLocator());
}
/**
* Create a {@code WebJarsResourceResolver} with a custom {@code WebJarAssetLocator} instance,
* for example, with a custom index.
* @since 4.3
*/
public WebJarsResourceResolver(WebJarAssetLocator webJarAssetLocator) {
this.webJarAssetLocator = webJarAssetLocator;
}
@Override
@Nullable
protected Resource resolveResourceInternal(@Nullable HttpServletRequest request, String requestPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
Resource resolved = chain.resolveResource(request, requestPath, locations);
if (resolved == null) {
String webJarResourcePath = findWebJarResourcePath(requestPath);
if (webJarResourcePath != null) {
return chain.resolveResource(request, webJarResourcePath, locations);
}
}
return resolved;
}
@Override
@Nullable
protected String resolveUrlPathInternal(String resourceUrlPath,
List<? extends Resource> locations, ResourceResolverChain chain) {
String path = chain.resolveUrlPath(resourceUrlPath, locations);
if (path == null) {
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
if (webJarResourcePath != null) {
return chain.resolveUrlPath(webJarResourcePath, locations);
}
}
return path;
}
@Nullable
protected String findWebJarResourcePath(String path) {
int startOffset = (path.startsWith("/") ? 1 : 0);
int endOffset = path.indexOf('/', 1);
if (endOffset != -1) {
String webjar = path.substring(startOffset, endOffset);
String partialPath = path.substring(endOffset + 1);
String webJarPath = this.webJarAssetLocator.getFullPathExact(webjar, partialPath);
if (webJarPath != null) {
return webJarPath.substring(WEBJARS_LOCATION_LENGTH);
}
}
return null;
}
}

View File

@@ -88,43 +88,6 @@ public interface FragmentsRendering extends SmartView {
return new DefaultFragmentsRenderingBuilder().fragments(fragments);
}
/**
* Create a builder with one HTML fragment, also inheriting attributes from
* the shared model for the request.
* @param viewName the name of the view for the fragment
* @return the created builder
* @deprecated in favor of {@link #fragment(String)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder with(String viewName) {
return fragment(viewName);
}
/**
* Create a builder with one HTML fragment.
* @param viewName the view name for the fragment
* @param model attributes for the fragment, in addition to attributes from the
* shared model for the request
* @return the created builder
* @deprecated in favor of {@link #fragment(String, Map)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder with(String viewName, Map<String, Object> model) {
return fragment(viewName, model);
}
/**
* Create a builder with multiple HTML fragments.
* @param fragments the fragments to add; each fragment also inherits
* attributes from the shared model for the request
* @return the created builder
* @deprecated in favor of {@link #fragments(Collection)}
*/
@Deprecated(since = "6.2.1", forRemoval = true)
static Builder with(Collection<ModelAndView> fragments) {
return fragments(fragments);
}
/**
* Defines a builder for {@link FragmentsRendering}.

View File

@@ -114,6 +114,7 @@ import org.springframework.web.servlet.resource.CssLinkResourceTransformer;
import org.springframework.web.servlet.resource.DefaultServletHttpRequestHandler;
import org.springframework.web.servlet.resource.EncodedResourceResolver;
import org.springframework.web.servlet.resource.FixedVersionStrategy;
import org.springframework.web.servlet.resource.LiteWebJarsResourceResolver;
import org.springframework.web.servlet.resource.NoResourceFoundException;
import org.springframework.web.servlet.resource.PathResourceResolver;
import org.springframework.web.servlet.resource.ResourceHttpRequestHandler;
@@ -122,7 +123,6 @@ import org.springframework.web.servlet.resource.ResourceTransformer;
import org.springframework.web.servlet.resource.ResourceUrlProvider;
import org.springframework.web.servlet.resource.ResourceUrlProviderExposingInterceptor;
import org.springframework.web.servlet.resource.VersionResourceResolver;
import org.springframework.web.servlet.resource.WebJarsResourceResolver;
import org.springframework.web.servlet.support.SessionFlashMapManager;
import org.springframework.web.servlet.theme.CookieThemeResolver;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
@@ -439,7 +439,6 @@ public class MvcNamespaceTests {
}
@Test
@SuppressWarnings("removal")
void testResourcesWithResolversTransformers() {
loadBeanDefinitions("mvc-config-resources-chain.xml");
@@ -456,7 +455,7 @@ public class MvcNamespaceTests {
assertThat(resolvers).hasSize(4);
assertThat(resolvers).element(0).isInstanceOf(CachingResourceResolver.class);
assertThat(resolvers).element(1).isInstanceOf(VersionResourceResolver.class);
assertThat(resolvers).element(2).isInstanceOf(WebJarsResourceResolver.class);
assertThat(resolvers).element(2).isInstanceOf(LiteWebJarsResourceResolver.class);
assertThat(resolvers).element(3).isInstanceOf(PathResourceResolver.class);
CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);

View File

@@ -48,6 +48,7 @@ class DefaultEntityResponseBuilderTests {
static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList;
@Test
void fromObject() {
String body = "foo";
@@ -66,14 +67,12 @@ class DefaultEntityResponseBuilderTests {
}
@Test
@SuppressWarnings("removal")
void status() {
String body = "foo";
EntityResponse<String> result =
EntityResponse.fromObject(body).status(HttpStatus.CREATED).build();
assertThat(result.statusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(result.rawStatusCode()).isEqualTo(201);
}
@Test

View File

@@ -54,12 +54,11 @@ class DefaultServerResponseBuilderTests {
static final ServerResponse.Context EMPTY_CONTEXT = Collections::emptyList;
@Test
@SuppressWarnings("removal")
void status() {
ServerResponse response = ServerResponse.status(HttpStatus.CREATED).build();
assertThat(response.statusCode()).isEqualTo(HttpStatus.CREATED);
assertThat(response.rawStatusCode()).isEqualTo(201);
}
@Test
@@ -75,7 +74,6 @@ class DefaultServerResponseBuilderTests {
assertThat(result.cookies().getFirst("foo")).isEqualTo(cookie);
}
@Test
void ok() {
ServerResponse response = ServerResponse.ok().build();

View File

@@ -63,14 +63,10 @@ class DeferredResultReturnValueHandlerTests {
@Test
@SuppressWarnings({"deprecation", "removal"})
public void supportsReturnType() throws Exception {
assertThat(this.handler.supportsReturnType(
on(TestController.class).resolveReturnType(DeferredResult.class, String.class))).isTrue();
assertThat(this.handler.supportsReturnType(
on(TestController.class).resolveReturnType(org.springframework.util.concurrent.ListenableFuture.class, String.class))).isTrue();
assertThat(this.handler.supportsReturnType(
on(TestController.class).resolveReturnType(CompletableFuture.class, String.class))).isTrue();
}
@@ -87,15 +83,6 @@ class DeferredResultReturnValueHandlerTests {
testHandle(result, DeferredResult.class, () -> result.setErrorResult(ex), ex);
}
@Test
@SuppressWarnings({"deprecation", "removal"})
public void listenableFuture() throws Exception {
org.springframework.util.concurrent.SettableListenableFuture<String> future =
new org.springframework.util.concurrent.SettableListenableFuture<>();
testHandle(future, org.springframework.util.concurrent.ListenableFuture.class,
() -> future.set("foo"), "foo");
}
@Test
void completableFuture() throws Exception {
CompletableFuture<String> future = new CompletableFuture<>();
@@ -108,16 +95,6 @@ class DeferredResultReturnValueHandlerTests {
testHandle(result, DeferredResult.class, () -> result.setResult("foo"), "foo");
}
@Test
@SuppressWarnings({"deprecation", "removal"})
public void listenableFutureWithError() throws Exception {
org.springframework.util.concurrent.SettableListenableFuture<String> future =
new org.springframework.util.concurrent.SettableListenableFuture<>();
IllegalStateException ex = new IllegalStateException();
testHandle(future, org.springframework.util.concurrent.ListenableFuture.class,
() -> future.setException(ex), ex);
}
@Test
void completableFutureWithError() throws Exception {
CompletableFuture<String> future = new CompletableFuture<>();
@@ -150,9 +127,6 @@ class DeferredResultReturnValueHandlerTests {
DeferredResult<String> handleDeferredResult() { return null; }
@SuppressWarnings({"deprecation", "removal"})
org.springframework.util.concurrent.ListenableFuture<String> handleListenableFuture() { return null; }
CompletableFuture<String> handleCompletableFuture() { return null; }
}

View File

@@ -1,140 +0,0 @@
/*
* Copyright 2002-2024 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.servlet.resource;
import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests for {@link WebJarsResourceResolver}.
*
* @author Brian Clozel
* @author Sam Brannen
*/
@SuppressWarnings("removal")
class WebJarsResourceResolverTests {
private List<Resource> locations = List.of(new ClassPathResource("/META-INF/resources/webjars"));
// for this to work, an actual WebJar must be on the test classpath
private WebJarsResourceResolver resolver = new WebJarsResourceResolver();
private ResourceResolverChain chain = mock();
private HttpServletRequest request = new MockHttpServletRequest();
@Test
void resolveUrlExisting() {
String file = "/foo/2.3/foo.txt";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(file);
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
assertThat(actual).isEqualTo(file);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
}
@Test
void resolveUrlExistingNotInJarFile() {
String file = "foo/foo.txt";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath("foo/2.3/foo.txt", this.locations);
}
@Test
void resolveUrlWebJarResource() {
String file = "underscorejs/underscore.js";
String expected = "underscorejs/1.8.3/underscore.js";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
given(this.chain.resolveUrlPath(expected, this.locations)).willReturn(expected);
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, times(1)).resolveUrlPath(expected, this.locations);
}
@Test
void resolveUrlWebJarResourceNotFound() {
String file = "something/something.js";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
String actual = this.resolver.resolveUrlPath(file, this.locations, this.chain);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveUrlPath(file, this.locations);
verify(this.chain, never()).resolveUrlPath(null, this.locations);
}
@Test
void resolveResourceExisting() {
Resource expected = mock();
String file = "foo/2.3/foo.txt";
given(this.chain.resolveResource(this.request, file, this.locations)).willReturn(expected);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
}
@Test
void resolveResourceNotFound() {
String file = "something/something.js";
given(this.chain.resolveUrlPath(file, this.locations)).willReturn(null);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertThat(actual).isNull();
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
verify(this.chain, never()).resolveResource(this.request, null, this.locations);
}
@Test
void resolveResourceWebJar() {
Resource expected = mock();
String file = "underscorejs/underscore.js";
String expectedPath = "underscorejs/1.8.3/underscore.js";
given(this.chain.resolveResource(this.request, expectedPath, this.locations)).willReturn(expected);
Resource actual = this.resolver.resolveResource(this.request, file, this.locations, this.chain);
assertThat(actual).isEqualTo(expected);
verify(this.chain, times(1)).resolveResource(this.request, file, this.locations);
}
}