/** * Adds a servlet context. This method should be package scoped. * * @param servletContextImpl * @return */ protected DeploymentDescriptorBuilder addServletContext(final ServletContextImpl servletContextImpl) { servletContextImpl.setAttribute(ServerConfig.class.getName(), serverConfig); servletContextImpls.add(servletContextImpl); return this; } }
private List<ServletContextImpl> getServletContexts(final ServerConfig serverConfig) { DeploymentDescriptorBuilder deploymentDescriptorBuilder = getDeploymentDescriptorBuilder(new FileSessionStorage(serverConfig.getTempPath()), serverConfig); List<ServletContextImpl> servletContexts = deploymentDescriptorBuilder.build(); for (ServletContextImpl servletContextImpl : servletContexts) { for (Map.Entry<String, Object> entry : getAdditionalServletContextAttributes().entrySet()) { servletContextImpl.setAttribute(entry.getKey(), entry.getValue()); } } return servletContexts; }
@Before public void setUp() { ServerConfig serverConfig = mock(ServerConfig.class); sessionStorage = mock(SessionStorage.class); servletContext = new ServletContextImpl("/", Collections.<ServletMapping>emptyList(), Collections.<FilterMapping>emptyList(), Collections.<String, Object>emptyMap(), serverConfig, sessionStorage ); servletContext.setAttribute("attribute", "value"); response = new HttpServletResponseImpl(mock( Serializer.class), mock(Serializer.class), mock(StreamHelper.class), mock(OutputStream.class)); }
@Test public void shouldReturnEnumerationOfAttributeNames() { assertThat(Collections.list(servletContext.getAttributeNames()).size(), Matchers.is(1)); assertThat((String) Collections.list(servletContext.getAttributeNames()).get(0), Matchers.is("attribute")); servletContext.setAttribute("attribute", null); assertThat(Collections.list(servletContext.getAttributeNames()).size(), Matchers.is(0)); } }
@Test public void shouldGraduallyRemoveAttributeByOverwritingByNull() { assertThat((String) servletContext.getAttribute("attribute"), Matchers.is("value")); servletContext.setAttribute("attribute", null); assertThat(servletContext.getAttribute("attribute"), Matchers.is(Matchers.nullValue())); }