Search in sources :

Example 1 with Session

use of cn.taketoday.framework.web.servlet.server.Session in project today-infrastructure by TAKETODAY.

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(cn.taketoday.framework.web.servlet.server.ConfigurableServletWebServerFactory) HashMap(java.util.HashMap) File(java.io.File) Session(cn.taketoday.framework.web.servlet.server.Session) Test(org.junit.jupiter.api.Test)

Example 2 with Session

use of cn.taketoday.framework.web.servlet.server.Session in project today-infrastructure by TAKETODAY.

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);
    Session.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 : ConfigurableServletWebServerFactory(cn.taketoday.framework.web.servlet.server.ConfigurableServletWebServerFactory) HashMap(java.util.HashMap) Session(cn.taketoday.framework.web.servlet.server.Session) Test(org.junit.jupiter.api.Test)

Aggregations

ConfigurableServletWebServerFactory (cn.taketoday.framework.web.servlet.server.ConfigurableServletWebServerFactory)2 Session (cn.taketoday.framework.web.servlet.server.Session)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1