InitializeSessionManagement implements ServletContainerInitializer { @Override public void onStartup(Set<Class<?>> classes, ServletContext context) throws ServletException { if (disabled || Boolean.parseBoolean(context.getInitParameter(DISABLED_SESSION))) { logger.warn("Session management disabled for {}, {}, {}", context.getContextPath(), disabled, context.getInitParameter(DISABLED_SESSION)); return; } setupProviders(context); initSessionManagement(context); }  @Override void onStartup(Set<Class<?>> classes, ServletContext context);  }
@Test public void testNotEnabled() throws ServletException { InitializeSessionManagement ism = new InitializeSessionManagement(); ServletContext context = mock(ServletContext.class); when(context.getInitParameter(SessionConfiguration.DISABLED_SESSION)).thenReturn("true"); ism.onStartup(null, context); verify(context, never()).addFilter(eq("com.amdeus.session.filter"), any(SessionFilter.class)); }
@Test public void testDefaultWithNullClasses() throws ServletException { InitializeSessionManagement ism = new InitializeSessionManagement(); ServletContext context = mock(ServletContext.class); when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader()); Dynamic dynamic = mock(Dynamic.class); when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic); ism.onStartup(null, context); verify(context).addFilter(eq("com.amdeus.session.filter"), any(SessionFilter.class)); }
@Test public void testDefault() throws ServletException { InitializeSessionManagement ism = new InitializeSessionManagement(); Set<Class<?>> classes = Collections.emptySet(); ServletContext context = mock(ServletContext.class); Dynamic dynamic = mock(Dynamic.class); when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic); when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader()); ism.onStartup(classes, context); verify(context).addFilter(eq("com.amdeus.session.filter"), any(SessionFilter.class)); }
@Test public void testWithProviders() throws ServletException { InitializeSessionManagement ism = new InitializeSessionManagement(); ServletContext context = mock(ServletContext.class); Dynamic dynamic = mock(Dynamic.class); when(context.addFilter(any(String.class), any(Filter.class))).thenReturn(dynamic); when(context.getClassLoader()).thenReturn(this.getClass().getClassLoader()); ism.onStartup(null, context); @SuppressWarnings("rawtypes") ArgumentCaptor<HashMap> arg = ArgumentCaptor.forClass(HashMap.class); verify(context).setAttribute(eq(PROVIDERS), arg.capture()); assertTrue(arg.getValue().containsKey("redis")); assertEquals(JedisSessionRepositoryFactory.class.getName(), arg.getValue().get("redis")); assertTrue(arg.getValue().containsKey("in-memory")); assertEquals(InMemoryRepositoryFactory.class.getName(), arg.getValue().get("in-memory")); }