Remove deprecated ThemeResolver support

See gh-33809
This commit is contained in:
rstoyanchev
2025-01-14 15:26:44 +00:00
parent 9ddbf800b9
commit 9f77d5ff1f
54 changed files with 39 additions and 2163 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -95,7 +95,7 @@ class XmlWebApplicationContextTests extends AbstractApplicationContextTests {
@Test
@Override
protected void count() {
assertThat(this.applicationContext.getBeanDefinitionCount()).as("should have 14 beans").isEqualTo(14);
assertThat(this.applicationContext.getBeanDefinitionCount()).as("should have 14 beans").isEqualTo(13);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -74,29 +74,19 @@ import org.springframework.web.util.WebUtils;
public class ComplexWebApplicationContext extends StaticWebApplicationContext {
@Override
@SuppressWarnings("deprecation")
public void refresh() throws BeansException {
registerSingleton(DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME, SessionLocaleResolver.class);
registerSingleton(DispatcherServlet.THEME_RESOLVER_BEAN_NAME,
org.springframework.web.servlet.theme.SessionThemeResolver.class);
LocaleChangeInterceptor interceptor1 = new LocaleChangeInterceptor();
LocaleChangeInterceptor interceptor2 = new LocaleChangeInterceptor();
interceptor2.setParamName("locale2");
org.springframework.web.servlet.theme.ThemeChangeInterceptor interceptor3 =
new org.springframework.web.servlet.theme.ThemeChangeInterceptor();
org.springframework.web.servlet.theme.ThemeChangeInterceptor interceptor4 =
new org.springframework.web.servlet.theme.ThemeChangeInterceptor();
interceptor4.setParamName("theme2");
UserRoleAuthorizationInterceptor interceptor5 = new UserRoleAuthorizationInterceptor();
interceptor5.setAuthorizedRoles("role1", "role2");
UserRoleAuthorizationInterceptor interceptor3 = new UserRoleAuthorizationInterceptor();
interceptor3.setAuthorizedRoles("role1", "role2");
List<Object> interceptors = new ArrayList<>();
interceptors.add(interceptor5);
interceptors.add(interceptor3);
interceptors.add(interceptor1);
interceptors.add(interceptor2);
interceptors.add(interceptor3);
interceptors.add(interceptor4);
interceptors.add(new MyHandlerInterceptor1());
interceptors.add(new MyHandlerInterceptor2());
interceptors.add(new MyWebRequestInterceptor());
@@ -457,16 +447,8 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
if (!TimeZone.getDefault().equals(LocaleContextHolder.getTimeZone())) {
throw new ServletException("Incorrect TimeZone");
}
if (!(RequestContextUtils.getThemeResolver(request)
instanceof org.springframework.web.servlet.theme.SessionThemeResolver)) {
throw new ServletException("Incorrect ThemeResolver");
}
if (!"theme".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
throw new ServletException("Incorrect theme name");
}
RequestContext rc = new RequestContext(request);
rc.changeLocale(Locale.US, TimeZone.getTimeZone("GMT+1"));
rc.changeTheme("theme2");
if (!Locale.US.equals(RequestContextUtils.getLocale(request))) {
throw new ServletException("Incorrect Locale");
}
@@ -479,9 +461,6 @@ public class ComplexWebApplicationContext extends StaticWebApplicationContext {
if (!TimeZone.getTimeZone("GMT+1").equals(LocaleContextHolder.getTimeZone())) {
throw new ServletException("Incorrect TimeZone");
}
if (!"theme2".equals(RequestContextUtils.getThemeResolver(request).resolveThemeName(request))) {
throw new ServletException("Incorrect theme name");
}
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -396,31 +396,6 @@ class DispatcherServletTests {
assertThat(response.getForwardedUrl()).as("Not forwarded").isNull();
}
@Test
void themeChangeInterceptor1() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
request.addParameter("theme", "mytheme");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getForwardedUrl()).as("forwarded URL").isEqualTo("failed0.jsp");
assertThat(request.getAttribute("exception").getClass().equals(ServletException.class)).as("Exception exposed").isTrue();
}
@Test
void themeChangeInterceptor2() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do");
request.addPreferredLocale(Locale.CANADA);
request.addUserRole("role1");
request.addParameter("theme", "mytheme");
request.addParameter("theme2", "theme");
MockHttpServletResponse response = new MockHttpServletResponse();
complexDispatcherServlet.service(request, response);
assertThat(response.getForwardedUrl()).as("Not forwarded").isNull();
}
@Test
void notAuthorized() throws Exception {
MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/locale.do");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -25,17 +25,11 @@ import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.BeansException;
import org.springframework.beans.MutablePropertyValues;
import org.springframework.context.support.StaticMessageSource;
import org.springframework.ui.context.Theme;
import org.springframework.ui.context.ThemeSource;
import org.springframework.ui.context.support.SimpleTheme;
import org.springframework.ui.context.support.UiApplicationContextUtils;
import org.springframework.web.context.support.StaticWebApplicationContext;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.support.RequestContextUtils;
import org.springframework.web.servlet.theme.AbstractThemeResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
/**
@@ -54,8 +48,6 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
addMessage("testArgs", Locale.ENGLISH, "test {0} message {1}");
addMessage("testArgsFormat", Locale.ENGLISH, "test {0} message {1,number,#.##} X");
registerSingleton(UiApplicationContextUtils.THEME_SOURCE_BEAN_NAME, DummyThemeSource.class);
registerSingleton("handlerMapping", BeanNameUrlHandlerMapping.class);
registerSingleton("viewResolver", InternalResourceViewResolver.class);
@@ -91,26 +83,4 @@ public class SimpleWebApplicationContext extends StaticWebApplicationContext {
}
}
public static class DummyThemeSource implements ThemeSource {
private final StaticMessageSource messageSource;
public DummyThemeSource() {
this.messageSource = new StaticMessageSource();
this.messageSource.addMessage("themetest", Locale.ENGLISH, "theme test message");
this.messageSource.addMessage("themetestArgs", Locale.ENGLISH, "theme test message {0}");
}
@Override
public Theme getTheme(String themeName) {
if (AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME.equals(themeName)) {
return new SimpleTheme(AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME, this.messageSource);
}
else {
return null;
}
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -50,7 +50,6 @@ import org.springframework.web.servlet.mvc.method.annotation.ServletWebArgumentR
import org.springframework.web.util.UrlPathHelper;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
/**
* Test fixture for the configuration in mvc-config-annotation-driven.xml.
@@ -74,8 +73,6 @@ class AnnotationDrivenBeanDefinitionParserTests {
((ConfigurableWebBindingInitializer) initializer).getMessageCodesResolver();
assertThat(resolver).isNotNull();
assertThat(resolver.getClass()).isEqualTo(TestMessageCodesResolver.class);
assertThat(new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"))
.asInstanceOf(BOOLEAN).isTrue();
}
@SuppressWarnings("removal")

View File

@@ -91,7 +91,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.RequestToViewNameTranslator;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.handler.AbstractHandlerMapping;
import org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping;
@@ -125,8 +124,6 @@ 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.support.SessionFlashMapManager;
import org.springframework.web.servlet.theme.CookieThemeResolver;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import org.springframework.web.servlet.view.BeanNameViewResolver;
import org.springframework.web.servlet.view.ContentNegotiatingViewResolver;
import org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator;
@@ -151,7 +148,6 @@ import org.springframework.web.util.pattern.PathPatternParser;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
/**
* Tests loading actual MVC namespace configuration.
@@ -218,8 +214,6 @@ public class MvcNamespaceTests {
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertThat(adapter).isNotNull();
assertThat(new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect"))
.asInstanceOf(BOOLEAN).isTrue();
List<HttpMessageConverter<?>> converters = adapter.getMessageConverters();
assertThat(converters.size()).isGreaterThan(0);
@@ -240,7 +234,6 @@ public class MvcNamespaceTests {
assertThat(appContext.getBean(LocalValidatorFactoryBean.class)).isNotNull();
assertThat(appContext.getBean(Validator.class)).isNotNull();
assertThat(appContext.getBean("localeResolver", LocaleResolver.class)).isNotNull();
assertThat(appContext.getBean("themeResolver", ThemeResolver.class)).isNotNull();
assertThat(appContext.getBean("viewNameTranslator", RequestToViewNameTranslator.class)).isNotNull();
assertThat(appContext.getBean("flashMapManager", FlashMapManager.class)).isNotNull();
@@ -277,11 +270,9 @@ public class MvcNamespaceTests {
}
@Test // gh-25290
@SuppressWarnings("removal")
void testDefaultConfigWithBeansInParentContext() {
StaticApplicationContext parent = new StaticApplicationContext();
parent.registerSingleton("localeResolver", CookieLocaleResolver.class);
parent.registerSingleton("themeResolver", CookieThemeResolver.class);
parent.registerSingleton("viewNameTranslator", DefaultRequestToViewNameTranslator.class);
parent.registerSingleton("flashMapManager", SessionFlashMapManager.class);
parent.refresh();
@@ -289,7 +280,6 @@ public class MvcNamespaceTests {
loadBeanDefinitions("mvc-config.xml");
assertThat(appContext.getBean("localeResolver")).isSameAs(parent.getBean("localeResolver"));
assertThat(appContext.getBean("themeResolver")).isSameAs(parent.getBean("themeResolver"));
assertThat(appContext.getBean("viewNameTranslator")).isSameAs(parent.getBean("viewNameTranslator"));
assertThat(appContext.getBean("flashMapManager")).isSameAs(parent.getBean("flashMapManager"));
}
@@ -326,7 +316,6 @@ public class MvcNamespaceTests {
doTestCustomValidator("mvc-config-custom-validator.xml");
}
@SuppressWarnings("removal")
private void doTestCustomValidator(String xml) throws Exception {
loadBeanDefinitions(xml);
@@ -336,7 +325,6 @@ public class MvcNamespaceTests {
RequestMappingHandlerAdapter adapter = appContext.getBean(RequestMappingHandlerAdapter.class);
assertThat(adapter).isNotNull();
assertThat(new DirectFieldAccessor(adapter).getPropertyValue("ignoreDefaultModelOnRedirect")).asInstanceOf(BOOLEAN).isTrue();
// default web binding initializer behavior test
MockHttpServletRequest request = new MockHttpServletRequest();
@@ -359,14 +347,12 @@ public class MvcNamespaceTests {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
request.setRequestURI("/accounts/12345");
request.addParameter("locale", "en");
request.addParameter("theme", "green");
HandlerExecutionChain chain = mapping.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(0).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(ThemeChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(UserRoleAuthorizationInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(UserRoleAuthorizationInterceptor.class);
request.setRequestURI("/admin/users");
chain = mapping.getHandler(request);
@@ -374,11 +360,11 @@ public class MvcNamespaceTests {
request.setRequestURI("/logged/accounts/12345");
chain = mapping.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).hasSize(2);
request.setRequestURI("/foo/logged");
chain = mapping.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).hasSize(2);
}
@Test
@@ -608,14 +594,11 @@ public class MvcNamespaceTests {
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/");
HandlerExecutionChain chain = mapping.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).hasSize(2);
assertThat(chain.getInterceptorList()).element(0).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(ThemeChangeInterceptor.class);
LocaleChangeInterceptor interceptor = (LocaleChangeInterceptor) chain.getInterceptorList().get(1);
assertThat(interceptor.getParamName()).isEqualTo("lang");
ThemeChangeInterceptor interceptor2 = (ThemeChangeInterceptor) chain.getInterceptorList().get(2);
assertThat(interceptor2.getParamName()).isEqualTo("style");
}
@Test
@@ -638,10 +621,9 @@ public class MvcNamespaceTests {
request.setMethod("GET");
HandlerExecutionChain chain = mapping.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).hasSize(2);
assertThat(chain.getInterceptorList()).element(0).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(ThemeChangeInterceptor.class);
SimpleUrlHandlerMapping mapping2 = appContext.getBean(SimpleUrlHandlerMapping.class);
assertThat(mapping2).isNotNull();
@@ -651,10 +633,9 @@ public class MvcNamespaceTests {
request = new MockHttpServletRequest("GET", "/foo");
chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
ModelAndView mv = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv.getViewName()).isNull();
@@ -662,10 +643,9 @@ public class MvcNamespaceTests {
request.setContextPath("/myapp");
request.setServletPath("/app");
chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
mv = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv.getViewName()).isEqualTo("baz");
@@ -673,10 +653,9 @@ public class MvcNamespaceTests {
request.setContextPath("/myapp");
request.setServletPath("/app");
chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
mv = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv.getViewName()).isEqualTo("root");
@@ -717,10 +696,9 @@ public class MvcNamespaceTests {
request.setServletPath("/app/");
request.setAttribute("com.ibm.websphere.servlet.uri_non_decoded", "/myapp/app/bar");
HandlerExecutionChain chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
ModelAndView mv2 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv2.getViewName()).isEqualTo("baz");
@@ -729,10 +707,9 @@ public class MvcNamespaceTests {
request.setServletPath("/app/");
request.setHttpServletMapping(new MockHttpServletMapping("", "", "", MappingMatch.PATH));
chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
ModelAndView mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv3.getViewName()).isEqualTo("root");
@@ -740,10 +717,9 @@ public class MvcNamespaceTests {
request.setContextPath("/myapp");
request.setServletPath("/");
chain = mapping2.getHandler(request);
assertThat(chain.getInterceptorList()).hasSize(4);
assertThat(chain.getInterceptorList()).hasSize(3);
assertThat(chain.getInterceptorList()).element(1).isInstanceOf(ConversionServiceExposingInterceptor.class);
assertThat(chain.getInterceptorList()).element(2).isInstanceOf(LocaleChangeInterceptor.class);
assertThat(chain.getInterceptorList()).element(3).isInstanceOf(ThemeChangeInterceptor.class);
mv3 = adapter.handle(request, new MockHttpServletResponse(), chain.getHandler());
assertThat(mv3.getViewName()).isEqualTo("root");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -35,7 +35,6 @@ import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.handler.MappedInterceptor;
import org.springframework.web.servlet.handler.WebRequestHandlerInterceptorAdapter;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.theme.ThemeChangeInterceptor;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
@@ -57,7 +56,7 @@ public class InterceptorRegistryTests {
private final HandlerInterceptor interceptor1 = new LocaleChangeInterceptor();
private final HandlerInterceptor interceptor2 = new ThemeChangeInterceptor();
private final HandlerInterceptor interceptor2 = new LocaleChangeInterceptor();
private TestWebRequestInterceptor webInterceptor1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -87,7 +87,6 @@ import org.springframework.web.util.UrlPathHelper;
import static com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
import static com.fasterxml.jackson.databind.MapperFeature.DEFAULT_VIEW_INCLUSION;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
import static org.mockito.Mockito.mock;
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.http.MediaType.APPLICATION_XML;
@@ -240,8 +239,6 @@ class WebMvcConfigurationSupportExtensionTests {
DeferredResultProcessingInterceptor[] deferredResultInterceptors =
(DeferredResultProcessingInterceptor[]) fieldAccessor.getPropertyValue("deferredResultInterceptors");
assertThat(deferredResultInterceptors).hasSize(1);
assertThat(fieldAccessor.getPropertyValue("ignoreDefaultModelOnRedirect")).asInstanceOf(BOOLEAN).isTrue();
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -99,7 +99,6 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.web.servlet.DispatcherServlet.FLASH_MAP_MANAGER_BEAN_NAME;
import static org.springframework.web.servlet.DispatcherServlet.LOCALE_RESOLVER_BEAN_NAME;
import static org.springframework.web.servlet.DispatcherServlet.REQUEST_TO_VIEW_NAME_TRANSLATOR_BEAN_NAME;
import static org.springframework.web.servlet.DispatcherServlet.THEME_RESOLVER_BEAN_NAME;
/**
* Integration tests for {@link WebMvcConfigurationSupport} (imported via
@@ -332,17 +331,6 @@ class WebMvcConfigurationSupportTests {
assertThat(localeResolver).isInstanceOf(AcceptHeaderLocaleResolver.class);
}
@Test
@SuppressWarnings("deprecation")
public void defaultThemeResolverConfiguration() {
ApplicationContext context = initContext(WebConfig.class);
org.springframework.web.servlet.ThemeResolver themeResolver =
context.getBean(THEME_RESOLVER_BEAN_NAME, org.springframework.web.servlet.ThemeResolver.class);
assertThat(themeResolver).isNotNull();
assertThat(themeResolver).isInstanceOf(org.springframework.web.servlet.theme.FixedThemeResolver.class);
}
@Test
void defaultFlashMapManagerConfiguration() {
ApplicationContext context = initContext(WebConfig.class);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -26,9 +26,7 @@ import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.SimpleWebApplicationContext;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.theme.FixedThemeResolver;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import org.springframework.web.testfixture.servlet.MockPageContext;
@@ -57,9 +55,6 @@ public abstract class AbstractTagTests {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
LocaleResolver lr = new AcceptHeaderLocaleResolver();
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, lr);
ThemeResolver tr = new FixedThemeResolver();
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, tr);
request.setAttribute(DispatcherServlet.THEME_SOURCE_ATTRIBUTE, wac);
}
else {
sc.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);

View File

@@ -1,74 +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.tags;
import java.util.List;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.jsp.JspException;
import jakarta.servlet.jsp.PageContext;
import jakarta.servlet.jsp.tagext.Tag;
import org.junit.jupiter.api.Test;
import org.springframework.context.MessageSourceResolvable;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.web.servlet.support.RequestContext;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Juergen Hoeller
* @author Alef Arendsen
*/
@SuppressWarnings("deprecation")
class ThemeTagTests extends AbstractTagTests {
@Test
void themeTag() throws JspException {
PageContext pc = createPageContext();
final StringBuilder message = new StringBuilder();
ThemeTag tag = new ThemeTag() {
@Override
protected void writeMessage(String msg) {
message.append(msg);
}
};
tag.setPageContext(pc);
tag.setCode("themetest");
assertThat(tag.doStartTag()).as("Correct doStartTag return value").isEqualTo(Tag.EVAL_BODY_INCLUDE);
assertThat(tag.doEndTag()).as("Correct doEndTag return value").isEqualTo(Tag.EVAL_PAGE);
assertThat(message.toString()).isEqualTo("theme test message");
}
@Test
@SuppressWarnings("rawtypes")
void requestContext() {
PageContext pc = createPageContext();
RequestContext rc = new RequestContext((HttpServletRequest) pc.getRequest());
assertThat(rc.getThemeMessage("themetest")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", (String[]) null)).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", "default")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetest", (Object[]) null, "default")).isEqualTo("theme test message");
assertThat(rc.getThemeMessage("themetestArgs", new String[]{"arg1"})).isEqualTo("theme test message arg1");
assertThat(rc.getThemeMessage("themetestArgs", List.of("arg1"))).isEqualTo("theme test message arg1");
assertThat(rc.getThemeMessage("themetesta", "default")).isEqualTo("default");
assertThat(rc.getThemeMessage("themetesta", (List) null, "default")).isEqualTo("default");
MessageSourceResolvable resolvable = new DefaultMessageSourceResolvable(new String[] {"themetest"});
assertThat(rc.getThemeMessage(resolvable)).isEqualTo("theme test message");
}
}

View File

@@ -1,86 +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.theme;
import org.junit.jupiter.api.Test;
import org.springframework.web.servlet.ThemeResolver;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import org.springframework.web.testfixture.servlet.MockServletContext;
import static org.assertj.core.api.Assertions.assertThat;
/**
* @author Jean-Pierre Pawlak
* @author Juergen Hoeller
* @since 19.06.2003
*/
@SuppressWarnings("deprecation")
public class ThemeResolverTests {
private static final String TEST_THEME_NAME = "test.theme";
private static final String DEFAULT_TEST_THEME_NAME = "default.theme";
private void internalTest(ThemeResolver themeResolver, boolean shouldSet, String defaultName) {
// create mocks
MockServletContext context = new MockServletContext();
MockHttpServletRequest request = new MockHttpServletRequest(context);
MockHttpServletResponse response = new MockHttpServletResponse();
// check original theme
String themeName = themeResolver.resolveThemeName(request);
assertThat(defaultName).isEqualTo(themeName);
// set new theme name
try {
themeResolver.setThemeName(request, response, TEST_THEME_NAME);
assertThat(shouldSet).as("able to set theme name").isTrue();
// check new theme namelocale
themeName = themeResolver.resolveThemeName(request);
assertThat(themeName).isEqualTo(TEST_THEME_NAME);
themeResolver.setThemeName(request, response, null);
themeName = themeResolver.resolveThemeName(request);
assertThat(defaultName).isEqualTo(themeName);
}
catch (UnsupportedOperationException ex) {
assertThat(shouldSet).as("able to set theme name").isFalse();
}
}
@Test
void fixedThemeResolver() {
internalTest(new FixedThemeResolver(), false, AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
}
@Test
@SuppressWarnings("removal")
void cookieThemeResolver() {
internalTest(new CookieThemeResolver(), true, AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
}
@Test
void sessionThemeResolver() {
internalTest(new SessionThemeResolver(), true,AbstractThemeResolver.ORIGINAL_DEFAULT_THEME_NAME);
}
@Test
void sessionThemeResolverWithDefault() {
SessionThemeResolver tr = new SessionThemeResolver();
tr.setDefaultThemeName(DEFAULT_TEST_THEME_NAME);
internalTest(tr, true, DEFAULT_TEST_THEME_NAME);
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -45,7 +45,6 @@ import org.springframework.web.servlet.View;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.i18n.FixedLocaleResolver;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.theme.FixedThemeResolver;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
import org.springframework.web.testfixture.servlet.MockHttpServletResponse;
import org.springframework.web.testfixture.servlet.MockRequestDispatcher;
@@ -177,7 +176,6 @@ class ViewResolverTests {
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
Map<String, Object> model = new HashMap<>();
TestBean tb = new TestBean();
model.put("tb", tb);
@@ -422,7 +420,6 @@ class ViewResolverTests {
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
view1.render(model, this.request, this.response);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat(this.request.getAttribute("test1")).as("Correct test1 attribute").isEqualTo("testvalue1");
@@ -431,7 +428,6 @@ class ViewResolverTests {
this.request.clearAttributes();
this.request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, this.wac);
this.request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
this.request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
view2.render(model, this.request, this.response);
assertThat(tb.equals(this.request.getAttribute("tb"))).as("Correct tb attribute").isTrue();
assertThat(this.request.getAttribute("test1")).as("Correct test1 attribute").isEqualTo("testvalue1");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -43,7 +43,6 @@ import org.springframework.web.servlet.DispatcherServlet;
import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver;
import org.springframework.web.servlet.support.BindStatus;
import org.springframework.web.servlet.support.RequestContext;
import org.springframework.web.servlet.theme.FixedThemeResolver;
import org.springframework.web.servlet.view.AbstractTemplateView;
import org.springframework.web.servlet.view.DummyMacroRequestContext;
import org.springframework.web.testfixture.servlet.MockHttpServletRequest;
@@ -90,7 +89,6 @@ public class FreeMarkerMacroTests {
request.setAttribute(DispatcherServlet.WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac);
request.setAttribute(DispatcherServlet.LOCALE_RESOLVER_ATTRIBUTE, new AcceptHeaderLocaleResolver());
request.setAttribute(DispatcherServlet.THEME_RESOLVER_ATTRIBUTE, new FixedThemeResolver());
}

View File

@@ -7,8 +7,6 @@
<import resource="resources/messageSource.xml"/>
<import resource="/resources/../resources/themeSource.xml"/>
<bean id="lifecyclePostProcessor" class="org.springframework.beans.testfixture.beans.LifecycleBean$PostProcessor"/>
<!--

View File

@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "https://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource">
<property name="basenamePrefix">
<value>${theme-base}</value>
</property>
</bean>
</beans>

View File

@@ -7,10 +7,6 @@
<property name="basename"><value>org/springframework/web/context/WEB-INF/test-messages</value></property>
</bean>
<bean id="themeSource" class="org.springframework.ui.context.support.ResourceBundleThemeSource">
<property name="basenamePrefix"><value>org/springframework/web/context/WEB-INF/test-</value></property>
</bean>
<bean id="aca" class="org.springframework.context.testfixture.beans.ACATester"/>
<bean id="aca-prototype" class="org.springframework.context.testfixture.beans.ACATester" scope="prototype"/>

View File

@@ -10,9 +10,6 @@
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="lang" />
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor">
<property name="paramName" value="style" />
</bean>
</mvc:interceptors>
</beans>

View File

@@ -5,8 +5,7 @@
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<mvc:annotation-driven validator="validator"
ignore-default-model-on-redirect="true" enable-matrix-variables="true" />
<mvc:annotation-driven validator="validator" enable-matrix-variables="true" />
<bean id="validator" class="org.springframework.web.servlet.config.MvcNamespaceTests$TestValidator" />

View File

@@ -9,12 +9,6 @@
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
<mvc:interceptor>
<mvc:mapping path="/**" />
<mvc:exclude-mapping path="/admin/**" />
<mvc:exclude-mapping path="/images/**" />
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<mvc:interceptors path-matcher="pathMatcher">

View File

@@ -19,7 +19,6 @@
<mvc:interceptors>
<bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"/>
<bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor"/>
</mvc:interceptors>
</beans>