Replace test FilterRegistration with the one in testFixtures
See gh-33252
This commit is contained in:
parent
24ab6f61de
commit
5ac7e74bf2
|
|
@ -38,7 +38,7 @@ import org.springframework.lang.Nullable;
|
|||
* @author Rossen Stoyanchev
|
||||
* @since 6.2
|
||||
*/
|
||||
public class MockFilterRegistration implements FilterRegistration {
|
||||
public class MockFilterRegistration implements FilterRegistration.Dynamic {
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
@ -50,6 +50,8 @@ public class MockFilterRegistration implements FilterRegistration {
|
|||
|
||||
private final List<String> urlPatterns = new ArrayList<>();
|
||||
|
||||
private boolean asyncSupported;
|
||||
|
||||
|
||||
public MockFilterRegistration(String className) {
|
||||
this(className, "");
|
||||
|
|
@ -126,4 +128,13 @@ public class MockFilterRegistration implements FilterRegistration {
|
|||
return Collections.unmodifiableCollection(this.urlPatterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncSupported(boolean asyncSupported) {
|
||||
this.asyncSupported = asyncSupported;
|
||||
}
|
||||
|
||||
public boolean isAsyncSupported() {
|
||||
return this.asyncSupported;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ import org.springframework.lang.Nullable;
|
|||
* @author Rossen Stoyanchev
|
||||
* @since 6.2
|
||||
*/
|
||||
public class MockFilterRegistration implements FilterRegistration {
|
||||
public class MockFilterRegistration implements FilterRegistration.Dynamic {
|
||||
|
||||
private final String name;
|
||||
|
||||
|
|
@ -50,6 +50,8 @@ public class MockFilterRegistration implements FilterRegistration {
|
|||
|
||||
private final List<String> urlPatterns = new ArrayList<>();
|
||||
|
||||
private boolean asyncSupported;
|
||||
|
||||
|
||||
public MockFilterRegistration(String className) {
|
||||
this(className, "");
|
||||
|
|
@ -126,4 +128,13 @@ public class MockFilterRegistration implements FilterRegistration {
|
|||
return Collections.unmodifiableCollection(this.urlPatterns);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncSupported(boolean asyncSupported) {
|
||||
this.asyncSupported = asyncSupported;
|
||||
}
|
||||
|
||||
public boolean isAsyncSupported() {
|
||||
return this.asyncSupported;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,12 +17,10 @@
|
|||
package org.springframework.web.servlet.support;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.EventListener;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.Filter;
|
||||
import jakarta.servlet.FilterRegistration.Dynamic;
|
||||
import jakarta.servlet.Servlet;
|
||||
|
|
@ -40,6 +38,7 @@ import org.springframework.web.context.support.AnnotationConfigWebApplicationCon
|
|||
import org.springframework.web.filter.DelegatingFilterProxy;
|
||||
import org.springframework.web.filter.HiddenHttpMethodFilter;
|
||||
import org.springframework.web.servlet.DispatcherServlet;
|
||||
import org.springframework.web.testfixture.servlet.MockFilterRegistration;
|
||||
import org.springframework.web.testfixture.servlet.MockServletConfig;
|
||||
import org.springframework.web.testfixture.servlet.MockServletContext;
|
||||
|
||||
|
|
@ -112,11 +111,9 @@ class AnnotationConfigDispatcherServletInitializerTests {
|
|||
assertThat(filterRegistrations.get("delegatingFilterProxy#0")).isNotNull();
|
||||
assertThat(filterRegistrations.get("delegatingFilterProxy#1")).isNotNull();
|
||||
|
||||
for (MockFilterRegistration filterRegistration : filterRegistrations.values()) {
|
||||
assertThat(filterRegistration.isAsyncSupported()).isTrue();
|
||||
EnumSet<DispatcherType> enumSet = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD,
|
||||
DispatcherType.INCLUDE, DispatcherType.ASYNC);
|
||||
assertThat(filterRegistration.getMappings().get(SERVLET_NAME)).isEqualTo(enumSet);
|
||||
for (MockFilterRegistration registration : filterRegistrations.values()) {
|
||||
assertThat(registration.isAsyncSupported()).isTrue();
|
||||
assertThat(registration.getServletNameMappings().iterator().next()).isEqualTo(SERVLET_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -135,9 +132,9 @@ class AnnotationConfigDispatcherServletInitializerTests {
|
|||
MockServletRegistration servletRegistration = servletRegistrations.get(SERVLET_NAME);
|
||||
assertThat(servletRegistration.isAsyncSupported()).isFalse();
|
||||
|
||||
for (MockFilterRegistration filterRegistration : filterRegistrations.values()) {
|
||||
assertThat(filterRegistration.isAsyncSupported()).isFalse();
|
||||
assertThat(filterRegistration.getMappings().get(SERVLET_NAME)).isEqualTo(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE));
|
||||
for (MockFilterRegistration registration : filterRegistrations.values()) {
|
||||
assertThat(registration.isAsyncSupported()).isFalse();
|
||||
assertThat(registration.getServletNameMappings().iterator().next()).isEqualTo(SERVLET_NAME);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -209,7 +206,7 @@ class AnnotationConfigDispatcherServletInitializerTests {
|
|||
return null;
|
||||
}
|
||||
filters.put(filterName, filter);
|
||||
MockFilterRegistration registration = new MockFilterRegistration();
|
||||
MockFilterRegistration registration = new MockFilterRegistration(filter.getClass().getName(), filterName);
|
||||
filterRegistrations.put(filterName, registration);
|
||||
return registration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,104 +0,0 @@
|
|||
/*
|
||||
* Copyright 2002-2016 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.support;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import jakarta.servlet.DispatcherType;
|
||||
import jakarta.servlet.FilterRegistration.Dynamic;
|
||||
|
||||
class MockFilterRegistration implements Dynamic {
|
||||
|
||||
private boolean asyncSupported = false;
|
||||
|
||||
private Map<String, EnumSet<DispatcherType>> mappings = new HashMap<>();
|
||||
|
||||
|
||||
public Map<String, EnumSet<DispatcherType>> getMappings() {
|
||||
return this.mappings;
|
||||
}
|
||||
|
||||
public boolean isAsyncSupported() {
|
||||
return this.asyncSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAsyncSupported(boolean isAsyncSupported) {
|
||||
this.asyncSupported = isAsyncSupported;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMappingForServletNames(EnumSet<DispatcherType> dispatcherTypes,
|
||||
boolean isMatchAfter, String... servletNames) {
|
||||
|
||||
for (String servletName : servletNames) {
|
||||
this.mappings.put(servletName, dispatcherTypes);
|
||||
}
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getServletNameMappings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes,
|
||||
boolean isMatchAfter, String... urlPatterns) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> getUrlPatternMappings() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getClassName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setInitParameter(String name, String value) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInitParameter(String name) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> setInitParameters(Map<String, String> initParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> getInitParameters() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue