Search in sources :

Example 26 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryCustomizerTests method testCustomizeDefaultServlet.

@Test
void testCustomizeDefaultServlet() {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.properties.getServlet().setRegisterDefaultServlet(false);
    this.customizer.customize(factory);
    then(factory).should().setRegisterDefaultServlet(false);
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 27 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryCustomizerTests method testCustomizeTomcatPort.

@Test
void testCustomizeTomcatPort() {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.properties.setPort(8080);
    this.customizer.customize(factory);
    then(factory).should().setPort(8080);
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 28 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryCustomizerTests method testCustomizeDisplayName.

@Test
void testCustomizeDisplayName() {
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.properties.getServlet().setApplicationDisplayName("TestName");
    this.customizer.customize(factory);
    then(factory).should().setDisplayName("TestName");
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) Test(org.junit.jupiter.api.Test)

Example 29 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryCustomizerTests method customizeSessionProperties.

@Test
void customizeSessionProperties() {
    Map<String, String> map = new HashMap<>();
    map.put("server.servlet.session.timeout", "123");
    map.put("server.servlet.session.tracking-modes", "cookie,url");
    map.put("server.servlet.session.cookie.name", "testname");
    map.put("server.servlet.session.cookie.domain", "testdomain");
    map.put("server.servlet.session.cookie.path", "/testpath");
    map.put("server.servlet.session.cookie.comment", "testcomment");
    map.put("server.servlet.session.cookie.http-only", "true");
    map.put("server.servlet.session.cookie.secure", "true");
    map.put("server.servlet.session.cookie.max-age", "60");
    bindProperties(map);
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.customizer.customize(factory);
    ArgumentCaptor<Session> sessionCaptor = ArgumentCaptor.forClass(Session.class);
    then(factory).should().setSession(sessionCaptor.capture());
    assertThat(sessionCaptor.getValue().getTimeout()).hasSeconds(123);
    Cookie cookie = sessionCaptor.getValue().getCookie();
    assertThat(cookie.getName()).isEqualTo("testname");
    assertThat(cookie.getDomain()).isEqualTo("testdomain");
    assertThat(cookie.getPath()).isEqualTo("/testpath");
    assertThat(cookie.getComment()).isEqualTo("testcomment");
    assertThat(cookie.getHttpOnly()).isTrue();
    assertThat(cookie.getMaxAge()).hasSeconds(60);
}
Also used : Cookie(org.springframework.boot.web.servlet.server.Session.Cookie) ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) HashMap(java.util.HashMap) Session(org.springframework.boot.web.servlet.server.Session) Test(org.junit.jupiter.api.Test)

Example 30 with ConfigurableServletWebServerFactory

use of org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory in project spring-boot by spring-projects.

the class ServletWebServerFactoryCustomizerTests method sessionStoreDir.

@Test
void sessionStoreDir() {
    Map<String, String> map = new HashMap<>();
    map.put("server.servlet.session.store-dir", "mydirectory");
    bindProperties(map);
    ConfigurableServletWebServerFactory factory = mock(ConfigurableServletWebServerFactory.class);
    this.customizer.customize(factory);
    ArgumentCaptor<Session> sessionCaptor = ArgumentCaptor.forClass(Session.class);
    then(factory).should().setSession(sessionCaptor.capture());
    assertThat(sessionCaptor.getValue().getStoreDir()).isEqualTo(new File("mydirectory"));
}
Also used : ConfigurableServletWebServerFactory(org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory) HashMap(java.util.HashMap) File(java.io.File) Session(org.springframework.boot.web.servlet.server.Session) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableServletWebServerFactory (org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory)32 Test (org.junit.jupiter.api.Test)10 File (java.io.File)9 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 Session (org.springframework.boot.web.servlet.server.Session)2 ServletContext (javax.servlet.ServletContext)1 SessionCookieConfig (javax.servlet.SessionCookieConfig)1 KeycloakAuthenticatorValve (org.keycloak.adapters.tomcat.KeycloakAuthenticatorValve)1 JettyServletWebServerFactory (org.springframework.boot.web.embedded.jetty.JettyServletWebServerFactory)1 TomcatServletWebServerFactory (org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory)1 UndertowServletWebServerFactory (org.springframework.boot.web.embedded.undertow.UndertowServletWebServerFactory)1 MimeMappings (org.springframework.boot.web.server.MimeMappings)1 Shutdown (org.springframework.boot.web.server.Shutdown)1 Ssl (org.springframework.boot.web.server.Ssl)1 WebServerFactoryCustomizer (org.springframework.boot.web.server.WebServerFactoryCustomizer)1 Jsp (org.springframework.boot.web.servlet.server.Jsp)1 Cookie (org.springframework.boot.web.servlet.server.Session.Cookie)1 Bean (org.springframework.context.annotation.Bean)1