@ -39,13 +39,14 @@ import org.mockito.MockitoAnnotations;
import org.springframework.beans.MutablePropertyValues ;
import org.springframework.boot.bind.RelaxedDataBinder ;
import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletContainer ;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory ;
import org.springframework.boot.context.embedded.tomcat.TomcatContextCustomizer ;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer ;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory ;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory ;
import org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory ;
import org.springframework.boot.web.embedded.tomcat.TomcatContextCustomizer ;
import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory ;
import org.springframework.boot.web.embedded.tomcat.TomcatWebServer ;
import org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory ;
import org.springframework.boot.web.servlet.ServletContextInitializer ;
import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory ;
import org.springframework.boot.web.servlet.server.ServletWebServerFactoryCustomizer ;
import org.springframework.mock.env.MockEnvironment ;
import static org.assertj.core.api.Assertions.assertThat ;
@ -58,84 +59,83 @@ import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify ;
/ * *
* Tests for { @link DefaultServletContainer Customizer} .
* Tests for { @link ServerProperties} { @link ServletWebServerFactory Customizer} .
*
* @author Brian Clozel
* /
public class DefaultServletContainer CustomizerTests {
public class ServerPropertiesServletWebServerFactory CustomizerTests {
private final ServerProperties properties = new ServerProperties ( ) ;
private DefaultServlet Container Customizer customizer ;
private DefaultServlet WebServerFactory Customizer customizer ;
@Before
public void setup ( ) throws Exception {
MockitoAnnotations . initMocks ( this ) ;
this . customizer = new DefaultServlet Container Customizer( this . properties ) ;
this . customizer = new DefaultServlet WebServerFactory Customizer( this . properties ) ;
}
@Test
public void tomcatAccessLogIsDisabledByDefault ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( tomcatContainer . getEngineValves ( ) ) . isEmpty ( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getEngineValves ( ) ) . isEmpty ( ) ;
}
@Test
public void tomcatAccessLogCanBeEnabled ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.accesslog.enabled" , "true" ) ;
bindProperties ( map ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( tomcatContainer . getEngineValves ( ) ) . hasSize ( 1 ) ;
assertThat ( tomcatContainer . getEngineValves ( ) ) . first ( )
. isInstanceOf ( AccessLogValve . class ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getEngineValves ( ) ) . hasSize ( 1 ) ;
assertThat ( factory . getEngineValves ( ) ) . first ( ) . isInstanceOf ( AccessLogValve . class ) ;
}
@Test
public void tomcatAccessLogFileDateFormatByDefault ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
Map < String , String > map = new HashMap < String , String > ( ) ;
map . put ( "server.tomcat.accesslog.enabled" , "true" ) ;
bindProperties ( map ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( ( ( AccessLogValve ) tomcatContainer . getEngineValves ( ) . iterator ( ) . next ( ) )
this . customizer . customize ( factory ) ;
assertThat ( ( ( AccessLogValve ) factory . getEngineValves ( ) . iterator ( ) . next ( ) )
. getFileDateFormat ( ) ) . isEqualTo ( ".yyyy-MM-dd" ) ;
}
@Test
public void tomcatAccessLogFileDateFormatCanBeRedefined ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
Map < String , String > map = new HashMap < String , String > ( ) ;
map . put ( "server.tomcat.accesslog.enabled" , "true" ) ;
map . put ( "server.tomcat.accesslog.file-date-format" , "yyyy-MM-dd.HH" ) ;
bindProperties ( map ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( ( ( AccessLogValve ) tomcatContainer . getEngineValves ( ) . iterator ( ) . next ( ) )
this . customizer . customize ( factory ) ;
assertThat ( ( ( AccessLogValve ) factory . getEngineValves ( ) . iterator ( ) . next ( ) )
. getFileDateFormat ( ) ) . isEqualTo ( "yyyy-MM-dd.HH" ) ;
}
@Test
public void tomcatAccessLogIsBufferedByDefault ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.accesslog.enabled" , "true" ) ;
bindProperties ( map ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( ( ( AccessLogValve ) tomcatContainer . getEngineValves ( ) . iterator ( ) . next ( ) )
this . customizer . customize ( factory ) ;
assertThat ( ( ( AccessLogValve ) factory . getEngineValves ( ) . iterator ( ) . next ( ) )
. isBuffered ( ) ) . isTrue ( ) ;
}
@Test
public void tomcatAccessLogBufferingCanBeDisabled ( ) {
Tomcat EmbeddedServletContainerFactory tomcatContainer = new TomcatEmbeddedServletContain erFactory( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.accesslog.enabled" , "true" ) ;
map . put ( "server.tomcat.accesslog.buffered" , "false" ) ;
bindProperties ( map ) ;
this . customizer . customize ( tomcatContainer ) ;
assertThat ( ( ( AccessLogValve ) tomcatContainer . getEngineValves ( ) . iterator ( ) . next ( ) )
this . customizer . customize ( factory ) ;
assertThat ( ( ( AccessLogValve ) factory . getEngineValves ( ) . iterator ( ) . next ( ) )
. isBuffered ( ) ) . isFalse ( ) ;
}
@ -146,11 +146,10 @@ public class DefaultServletContainerCustomizerTests {
bindProperties ( map ) ;
ServerProperties . Tomcat tomcat = this . properties . getTomcat ( ) ;
assertThat ( tomcat . getRedirectContextRoot ( ) ) . isEqualTo ( false ) ;
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
Context context = mock ( Context . class ) ;
for ( TomcatContextCustomizer customizer : container
. getTomcatContextCustomizers ( ) ) {
for ( TomcatContextCustomizer customizer : factory . getTomcatContextCustomizers ( ) ) {
customizer . customize ( context ) ;
}
verify ( context ) . setMapperContextRootRedirectEnabled ( false ) ;
@ -158,24 +157,24 @@ public class DefaultServletContainerCustomizerTests {
@Test
public void testCustomizeTomcat ( ) throws Exception {
Configurable EmbeddedServletContainer factory = mock (
Configurable EmbeddedServletContainer . class ) ;
Configurable ServletWebServerFactory factory = mock (
Configurable ServletWebServerFactory . class ) ;
this . customizer . customize ( factory ) ;
verify ( factory , never ( ) ) . setContextPath ( "" ) ;
}
@Test
public void testDefaultDisplayName ( ) throws Exception {
Configurable EmbeddedServletContainer factory = mock (
Configurable EmbeddedServletContainer . class ) ;
Configurable ServletWebServerFactory factory = mock (
Configurable ServletWebServerFactory . class ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setDisplayName ( "application" ) ;
}
@Test
public void testCustomizeDisplayName ( ) throws Exception {
Configurable EmbeddedServletContainer factory = mock (
Configurable EmbeddedServletContainer . class ) ;
Configurable ServletWebServerFactory factory = mock (
Configurable ServletWebServerFactory . class ) ;
this . properties . setDisplayName ( "TestName" ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setDisplayName ( "TestName" ) ;
@ -194,8 +193,8 @@ public class DefaultServletContainerCustomizerTests {
map . put ( "server.session.cookie.secure" , "true" ) ;
map . put ( "server.session.cookie.max-age" , "60" ) ;
bindProperties ( map ) ;
Configurable EmbeddedServletContainer factory = mock (
Configurable EmbeddedServletContainer . class ) ;
Configurable ServletWebServerFactory factory = mock (
Configurable ServletWebServerFactory . class ) ;
ServletContext servletContext = mock ( ServletContext . class ) ;
SessionCookieConfig sessionCookieConfig = mock ( SessionCookieConfig . class ) ;
given ( servletContext . getSessionCookieConfig ( ) ) . willReturn ( sessionCookieConfig ) ;
@ -215,8 +214,8 @@ public class DefaultServletContainerCustomizerTests {
@Test
public void testCustomizeTomcatPort ( ) throws Exception {
Configurable EmbeddedServletContainer factory = mock (
Configurable EmbeddedServletContainer . class ) ;
Configurable ServletWebServerFactory factory = mock (
Configurable ServletWebServerFactory . class ) ;
this . properties . setPort ( 8080 ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setPort ( 8080 ) ;
@ -227,9 +226,9 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.display-name" , "MyBootApp" ) ;
bindProperties ( map ) ;
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
assertThat ( container . getDisplayName ( ) ) . isEqualTo ( "MyBootApp" ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getDisplayName ( ) ) . isEqualTo ( "MyBootApp" ) ;
}
@Test
@ -238,19 +237,17 @@ public class DefaultServletContainerCustomizerTests {
map . put ( "server.tomcat.remote_ip_header" , "" ) ;
map . put ( "server.tomcat.protocol_header" , "" ) ;
bindProperties ( map ) ;
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
assertThat ( container . getEngineValves ( ) ) . isEmpty ( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getEngineValves ( ) ) . isEmpty ( ) ;
}
@Test
public void defaultTomcatBackgroundProcessorDelay ( ) throws Exception {
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory ( ) ;
this . customizer . customize ( container ) ;
assertThat (
( ( TomcatEmbeddedServletContainer ) container . getEmbeddedServletContainer ( ) )
. getTomcat ( ) . getEngine ( ) . getBackgroundProcessorDelay ( ) )
. isEqualTo ( 30 ) ;
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ( ) ;
this . customizer . customize ( factory ) ;
assertThat ( ( ( TomcatWebServer ) factory . getWebServer ( ) ) . getTomcat ( ) . getEngine ( )
. getBackgroundProcessorDelay ( ) ) . isEqualTo ( 30 ) ;
}
@Test
@ -258,12 +255,10 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.background-processor-delay" , "5" ) ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory ( ) ;
this . customizer . customize ( container ) ;
assertThat (
( ( TomcatEmbeddedServletContainer ) container . getEmbeddedServletContainer ( ) )
. getTomcat ( ) . getEngine ( ) . getBackgroundProcessorDelay ( ) )
. isEqualTo ( 5 ) ;
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ( ) ;
this . customizer . customize ( factory ) ;
assertThat ( ( ( TomcatWebServer ) factory . getWebServer ( ) ) . getTomcat ( ) . getEngine ( )
. getBackgroundProcessorDelay ( ) ) . isEqualTo ( 5 ) ;
}
@Test
@ -290,10 +285,10 @@ public class DefaultServletContainerCustomizerTests {
}
private void testRemoteIpValveConfigured ( ) {
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
assertThat ( container . getEngineValves ( ) ) . hasSize ( 1 ) ;
Valve valve = container . getEngineValves ( ) . iterator ( ) . next ( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getEngineValves ( ) ) . hasSize ( 1 ) ;
Valve valve = factory . getEngineValves ( ) . iterator ( ) . next ( ) ;
assertThat ( valve ) . isInstanceOf ( RemoteIpValve . class ) ;
RemoteIpValve remoteIpValve = ( RemoteIpValve ) valve ;
assertThat ( remoteIpValve . getProtocolHeader ( ) ) . isEqualTo ( "X-Forwarded-Proto" ) ;
@ -318,10 +313,10 @@ public class DefaultServletContainerCustomizerTests {
map . put ( "server.tomcat.port-header" , "x-my-forward-port" ) ;
map . put ( "server.tomcat.protocol-header-https-value" , "On" ) ;
bindProperties ( map ) ;
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
assertThat ( container . getEngineValves ( ) ) . hasSize ( 1 ) ;
Valve valve = container . getEngineValves ( ) . iterator ( ) . next ( ) ;
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getEngineValves ( ) ) . hasSize ( 1 ) ;
Valve valve = factory . getEngineValves ( ) . iterator ( ) . next ( ) ;
assertThat ( valve ) . isInstanceOf ( RemoteIpValve . class ) ;
RemoteIpValve remoteIpValve = ( RemoteIpValve ) valve ;
assertThat ( remoteIpValve . getProtocolHeader ( ) ) . isEqualTo ( "x-my-protocol-header" ) ;
@ -336,18 +331,16 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.accept-count" , "10" ) ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory (
0 ) ;
this . customizer . customize ( container ) ;
TomcatEmbeddedServletContainer embeddedContainer = ( TomcatEmbeddedServletContainer ) container
. getEmbeddedServletContainer ( ) ;
embeddedContainer . start ( ) ;
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ( 0 ) ;
this . customizer . customize ( factory ) ;
TomcatWebServer embeddedfactory = ( TomcatWebServer ) factory . getWebServer ( ) ;
embeddedfactory . start ( ) ;
try {
assertThat ( ( ( AbstractProtocol < ? > ) embedded Container . getTomcat ( ) . getConnector ( )
assertThat ( ( ( AbstractProtocol < ? > ) embeddedfactory . getTomcat ( ) . getConnector ( )
. getProtocolHandler ( ) ) . getBacklog ( ) ) . isEqualTo ( 10 ) ;
}
finally {
embedded Container . stop ( ) ;
embedded factory . stop ( ) ;
}
}
@ -356,18 +349,16 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.max-connections" , "5" ) ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory (
0 ) ;
this . customizer . customize ( container ) ;
TomcatEmbeddedServletContainer embeddedContainer = ( TomcatEmbeddedServletContainer ) container
. getEmbeddedServletContainer ( ) ;
embeddedContainer . start ( ) ;
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ( 0 ) ;
this . customizer . customize ( factory ) ;
TomcatWebServer embeddedfactory = ( TomcatWebServer ) factory . getWebServer ( ) ;
embeddedfactory . start ( ) ;
try {
assertThat ( ( ( AbstractProtocol < ? > ) embedded Container . getTomcat ( ) . getConnector ( )
assertThat ( ( ( AbstractProtocol < ? > ) embeddedfactory . getTomcat ( ) . getConnector ( )
. getProtocolHandler ( ) ) . getMaxConnections ( ) ) . isEqualTo ( 5 ) ;
}
finally {
embedded Container . stop ( ) ;
embedded factory . stop ( ) ;
}
}
@ -376,18 +367,16 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.tomcat.max-http-post-size" , "10000" ) ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory container = new TomcatEmbeddedServletContainerFactory (
0 ) ;
this . customizer . customize ( container ) ;
TomcatEmbeddedServletContainer embeddedContainer = ( TomcatEmbeddedServletContainer ) container
. getEmbeddedServletContainer ( ) ;
embeddedContainer . start ( ) ;
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory ( 0 ) ;
this . customizer . customize ( factory ) ;
TomcatWebServer embeddedfactory = ( TomcatWebServer ) factory . getWebServer ( ) ;
embeddedfactory . start ( ) ;
try {
assertThat ( embedded Container . getTomcat ( ) . getConnector ( ) . getMaxPostSize ( ) )
assertThat ( embeddedfactory . getTomcat ( ) . getConnector ( ) . getMaxPostSize ( ) )
. isEqualTo ( 10000 ) ;
}
finally {
embedded Container . stop ( ) ;
embedded factory . stop ( ) ;
}
}
@ -401,15 +390,15 @@ public class DefaultServletContainerCustomizerTests {
map . put ( "server.undertow.accesslog.dir" , "test-logs" ) ;
map . put ( "server.undertow.accesslog.rotate" , "false" ) ;
bindProperties ( map ) ;
Undertow EmbeddedServletContainerFactory container = spy (
new Undertow EmbeddedServletContain erFactory( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setAccessLogEnabled ( true ) ;
verify ( container ) . setAccessLogPattern ( "foo" ) ;
verify ( container ) . setAccessLogPrefix ( "test_log" ) ;
verify ( container ) . setAccessLogSuffix ( "txt" ) ;
verify ( container ) . setAccessLogDirectory ( new File ( "test-logs" ) ) ;
verify ( container ) . setAccessLogRotate ( false ) ;
Undertow ServletWebServerFactory factory = spy (
new Undertow ServletWebServ erFactory( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setAccessLogEnabled ( true ) ;
verify ( factory ) . setAccessLogPattern ( "foo" ) ;
verify ( factory ) . setAccessLogPrefix ( "test_log" ) ;
verify ( factory ) . setAccessLogSuffix ( "txt" ) ;
verify ( factory ) . setAccessLogDirectory ( new File ( "test-logs" ) ) ;
verify ( factory ) . setAccessLogRotate ( false ) ;
}
@Test
@ -438,63 +427,60 @@ public class DefaultServletContainerCustomizerTests {
}
private void testCustomTomcatTldSkip ( String . . . expectedJars ) {
Tomcat EmbeddedServletContainerFactory container = new TomcatEmbeddedServletContain erFactory( ) ;
this . customizer . customize ( container ) ;
assertThat ( container . getTldSkipPatterns ( ) ) . contains ( expectedJars ) ;
assertThat ( container . getTldSkipPatterns ( ) ) . contains ( "junit-*.jar" ,
Tomcat ServletWebServerFactory factory = new TomcatServletWebServ erFactory( ) ;
this . customizer . customize ( factory ) ;
assertThat ( factory . getTldSkipPatterns ( ) ) . contains ( expectedJars ) ;
assertThat ( factory . getTldSkipPatterns ( ) ) . contains ( "junit-*.jar" ,
"spring-boot-*.jar" ) ;
}
@Test
public void defaultUseForwardHeadersUndertow ( ) throws Exception {
Undertow EmbeddedServletContainerFactory container = spy (
new Undertow EmbeddedServletContain erFactory( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( false ) ;
Undertow ServletWebServerFactory factory = spy (
new Undertow ServletWebServ erFactory( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( false ) ;
}
@Test
public void setUseForwardHeadersUndertow ( ) throws Exception {
this . properties . setUseForwardHeaders ( true ) ;
Undertow EmbeddedServletContainerFactory container = spy (
new Undertow EmbeddedServletContain erFactory( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( true ) ;
Undertow ServletWebServerFactory factory = spy (
new Undertow ServletWebServ erFactory( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( true ) ;
}
@Test
public void deduceUseForwardHeadersUndertow ( ) throws Exception {
this . customizer . setEnvironment ( new MockEnvironment ( ) . withProperty ( "DYNO" , "-" ) ) ;
Undertow EmbeddedServletContainerFactory container = spy (
new Undertow EmbeddedServletContain erFactory( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( true ) ;
Undertow ServletWebServerFactory factory = spy (
new Undertow ServletWebServ erFactory( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( true ) ;
}
@Test
public void defaultUseForwardHeadersJetty ( ) throws Exception {
JettyEmbeddedServletContainerFactory container = spy (
new JettyEmbeddedServletContainerFactory ( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( false ) ;
JettyServletWebServerFactory factory = spy ( new JettyServletWebServerFactory ( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( false ) ;
}
@Test
public void setUseForwardHeadersJetty ( ) throws Exception {
this . properties . setUseForwardHeaders ( true ) ;
JettyEmbeddedServletContainerFactory container = spy (
new JettyEmbeddedServletContainerFactory ( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( true ) ;
JettyServletWebServerFactory factory = spy ( new JettyServletWebServerFactory ( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( true ) ;
}
@Test
public void deduceUseForwardHeadersJetty ( ) throws Exception {
this . customizer . setEnvironment ( new MockEnvironment ( ) . withProperty ( "DYNO" , "-" ) ) ;
JettyEmbeddedServletContainerFactory container = spy (
new JettyEmbeddedServletContainerFactory ( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setUseForwardHeaders ( true ) ;
JettyServletWebServerFactory factory = spy ( new JettyServletWebServerFactory ( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setUseForwardHeaders ( true ) ;
}
@Test
@ -502,24 +488,22 @@ public class DefaultServletContainerCustomizerTests {
Map < String , String > map = new HashMap < > ( ) ;
map . put ( "server.session.store-dir" , "myfolder" ) ;
bindProperties ( map ) ;
JettyEmbeddedServletContainerFactory container = spy (
new JettyEmbeddedServletContainerFactory ( ) ) ;
this . customizer . customize ( container ) ;
verify ( container ) . setSessionStoreDir ( new File ( "myfolder" ) ) ;
JettyServletWebServerFactory factory = spy ( new JettyServletWebServerFactory ( ) ) ;
this . customizer . customize ( factory ) ;
verify ( factory ) . setSessionStoreDir ( new File ( "myfolder" ) ) ;
}
@Test
public void skipNullElementsForUndertow ( ) throws Exception {
Undertow EmbeddedServletContainerFactory container = mock (
Undertow EmbeddedServletContain erFactory. class ) ;
this . customizer . customize ( container ) ;
verify ( container , never ( ) ) . setAccessLogEnabled ( anyBoolean ( ) ) ;
Undertow ServletWebServerFactory factory = mock (
Undertow ServletWebServ erFactory. class ) ;
this . customizer . customize ( factory ) ;
verify ( factory , never ( ) ) . setAccessLogEnabled ( anyBoolean ( ) ) ;
}
private void triggerInitializers ( Configurable EmbeddedServletContainer container ,
private void triggerInitializers ( Configurable ServletWebServerFactory factory ,
ServletContext servletContext ) throws ServletException {
verify ( container , atLeastOnce ( ) )
. addInitializers ( this . initializersCaptor . capture ( ) ) ;
verify ( factory , atLeastOnce ( ) ) . addInitializers ( this . initializersCaptor . capture ( ) ) ;
for ( Object initializers : this . initializersCaptor . getAllValues ( ) ) {
if ( initializers instanceof ServletContextInitializer ) {
( ( ServletContextInitializer ) initializers ) . onStartup ( servletContext ) ;