@ -31,6 +31,8 @@ import org.springframework.boot.context.embedded.ConfigurableEmbeddedServletCont
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer ;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory ;
import static org.hamcrest.Matchers.equalTo ;
import static org.hamcrest.Matchers.is ;
import static org.hamcrest.core.IsInstanceOf.instanceOf ;
import static org.junit.Assert.assertEquals ;
import static org.junit.Assert.assertFalse ;
@ -197,9 +199,26 @@ public class ServerPropertiesTests {
@Test
public void customTomcatCompression ( ) throws Exception {
assertThat ( "on" , is ( equalTo ( configureCompression ( "on" ) ) ) ) ;
}
@Test
public void disableTomcatCompressionWithYaml ( ) throws Exception {
// YAML interprets "off" as false, check that it's mapped back to off
assertThat ( "off" , is ( equalTo ( configureCompression ( "false" ) ) ) ) ;
}
@Test
public void enableTomcatCompressionWithYaml ( ) throws Exception {
// YAML interprets "on" as true, check that it's mapped back to on
assertThat ( "on" , is ( equalTo ( configureCompression ( "true" ) ) ) ) ;
}
@Test
public void customTomcatCompressableMimeTypes ( ) throws Exception {
Map < String , String > map = new HashMap < String , String > ( ) ;
map . put ( "server.port" , "0" ) ;
map . put ( "server.tomcat.compression" , "on" ) ;
map . put ( "server.tomcat.compress ableMimeTypes", "application/foo ") ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory ( ) ;
@ -211,18 +230,23 @@ public class ServerPropertiesTests {
try {
AbstractHttp11Protocol < ? > protocol = ( AbstractHttp11Protocol < ? > ) container
. getTomcat ( ) . getConnector ( ) . getProtocolHandler ( ) ;
assertEquals ( " on", protocol . getCompress ion ( ) ) ;
assertEquals ( " applicati on/foo ", protocol . getCompress ableMimeTypes ( ) ) ;
}
finally {
container . stop ( ) ;
}
}
@Test
public void customTomcatCompressableMimeTypes ( ) throws Exception {
private void bindProperties ( Map < String , String > map ) {
new RelaxedDataBinder ( this . properties , "server" ) . bind ( new MutablePropertyValues (
map ) ) ;
}
private String configureCompression ( String compression ) {
Map < String , String > map = new HashMap < String , String > ( ) ;
map . put ( "server.port" , "0" ) ;
map . put ( "server.tomcat.compressableMimeTypes" , "application/foo" ) ;
// YAML interprets "on" as true
map . put ( "server.tomcat.compression" , compression ) ;
bindProperties ( map ) ;
TomcatEmbeddedServletContainerFactory factory = new TomcatEmbeddedServletContainerFactory ( ) ;
@ -234,16 +258,11 @@ public class ServerPropertiesTests {
try {
AbstractHttp11Protocol < ? > protocol = ( AbstractHttp11Protocol < ? > ) container
. getTomcat ( ) . getConnector ( ) . getProtocolHandler ( ) ;
assertEquals ( "application/foo" , protocol . getCompressableMimeTypes ( ) ) ;
return protocol . getCompression ( ) ;
}
finally {
container . stop ( ) ;
}
}
private void bindProperties ( Map < String , String > map ) {
new RelaxedDataBinder ( this . properties , "server" ) . bind ( new MutablePropertyValues (
map ) ) ;
}
}