|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright 2012-2016 the original author or authors.
|
|
|
|
|
* Copyright 2012-2017 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,6 +26,7 @@ import java.util.Map;
|
|
|
|
|
import javax.servlet.DispatcherType;
|
|
|
|
|
import javax.servlet.Filter;
|
|
|
|
|
import javax.servlet.FilterRegistration;
|
|
|
|
|
import javax.servlet.Servlet;
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
|
|
|
|
|
import org.junit.Before;
|
|
|
|
@ -74,7 +75,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void startupWithDefaults() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter());
|
|
|
|
|
verify(this.registration).setAsyncSupported(true);
|
|
|
|
@ -84,7 +85,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void startupWithSpecifiedValues() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.setName("test");
|
|
|
|
|
bean.setAsyncSupported(false);
|
|
|
|
|
bean.setInitParameters(Collections.singletonMap("a", "b"));
|
|
|
|
@ -112,7 +113,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void specificName() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.setName("specificName");
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.servletContext).addFilter(eq("specificName"), getExpectedFilter());
|
|
|
|
@ -120,14 +121,14 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void deducedName() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.servletContext).addFilter(eq("mockFilter"), getExpectedFilter());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void disable() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.setEnabled(false);
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.servletContext, times(0)).addFilter(eq("mockFilter"),
|
|
|
|
@ -136,7 +137,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setServletRegistrationBeanMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("ServletRegistrationBeans must not be null");
|
|
|
|
|
bean.setServletRegistrationBeans(null);
|
|
|
|
@ -144,7 +145,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addServletRegistrationBeanMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("ServletRegistrationBeans must not be null");
|
|
|
|
|
bean.addServletRegistrationBeans((ServletRegistrationBean[]) null);
|
|
|
|
@ -152,9 +153,9 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setServletRegistrationBeanReplacesValue() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean(
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean(
|
|
|
|
|
mockServletRegistration("a"));
|
|
|
|
|
bean.setServletRegistrationBeans(new LinkedHashSet<ServletRegistrationBean>(
|
|
|
|
|
bean.setServletRegistrationBeans(new LinkedHashSet<ServletRegistrationBean<?>>(
|
|
|
|
|
Arrays.asList(mockServletRegistration("b"))));
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.registration).addMappingForServletNames(ASYNC_DISPATCHER_TYPES, false,
|
|
|
|
@ -163,7 +164,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void modifyInitParameters() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.addInitParameter("a", "b");
|
|
|
|
|
bean.getInitParameters().put("a", "c");
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
@ -172,7 +173,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setUrlPatternMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("UrlPatterns must not be null");
|
|
|
|
|
bean.setUrlPatterns(null);
|
|
|
|
@ -180,7 +181,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addUrlPatternMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("UrlPatterns must not be null");
|
|
|
|
|
bean.addUrlPatterns((String[]) null);
|
|
|
|
@ -188,7 +189,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void setServletNameMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("ServletNames must not be null");
|
|
|
|
|
bean.setServletNames(null);
|
|
|
|
@ -196,7 +197,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void addServletNameMustNotBeNull() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
this.thrown.expectMessage("ServletNames must not be null");
|
|
|
|
|
bean.addServletNames((String[]) null);
|
|
|
|
@ -204,7 +205,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void withSpecificDispatcherTypes() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
bean.setDispatcherTypes(DispatcherType.INCLUDE, DispatcherType.FORWARD);
|
|
|
|
|
bean.onStartup(this.servletContext);
|
|
|
|
|
verify(this.registration).addMappingForUrlPatterns(
|
|
|
|
@ -213,7 +214,7 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void withSpecificDispatcherTypesEnumSet() throws Exception {
|
|
|
|
|
AbstractFilterRegistrationBean bean = createFilterRegistrationBean();
|
|
|
|
|
AbstractFilterRegistrationBean<?> bean = createFilterRegistrationBean();
|
|
|
|
|
EnumSet<DispatcherType> types = EnumSet.of(DispatcherType.INCLUDE,
|
|
|
|
|
DispatcherType.FORWARD);
|
|
|
|
|
bean.setDispatcherTypes(types);
|
|
|
|
@ -223,11 +224,11 @@ public abstract class AbstractFilterRegistrationBeanTests {
|
|
|
|
|
|
|
|
|
|
protected abstract Filter getExpectedFilter();
|
|
|
|
|
|
|
|
|
|
protected abstract AbstractFilterRegistrationBean createFilterRegistrationBean(
|
|
|
|
|
ServletRegistrationBean... servletRegistrationBeans);
|
|
|
|
|
protected abstract AbstractFilterRegistrationBean<?> createFilterRegistrationBean(
|
|
|
|
|
ServletRegistrationBean<?>... servletRegistrationBeans);
|
|
|
|
|
|
|
|
|
|
protected final ServletRegistrationBean mockServletRegistration(String name) {
|
|
|
|
|
ServletRegistrationBean bean = new ServletRegistrationBean();
|
|
|
|
|
protected final ServletRegistrationBean<?> mockServletRegistration(String name) {
|
|
|
|
|
ServletRegistrationBean<?> bean = new ServletRegistrationBean<Servlet>();
|
|
|
|
|
bean.setName(name);
|
|
|
|
|
return bean;
|
|
|
|
|
}
|
|
|
|
|