HttpSessionEventPublisher need not implement ServletContextListener any longer

This commit is contained in:
Ray Krueger 2006-11-20 19:35:11 +00:00
parent 74e8efc4e9
commit 1a486e584b
2 changed files with 3 additions and 39 deletions

View File

@ -38,7 +38,7 @@ import javax.servlet.http.HttpSessionListener;
*
* @author Ray Krueger
*/
public class HttpSessionEventPublisher implements HttpSessionListener, ServletContextListener {
public class HttpSessionEventPublisher implements HttpSessionListener {
//~ Static fields/initializers =====================================================================================
private static final Log log = LogFactory.getLog(HttpSessionEventPublisher.class);
@ -47,25 +47,6 @@ public class HttpSessionEventPublisher implements HttpSessionListener, ServletCo
//~ Methods ========================================================================================================
/**
* Not implemented
*
* @param event
*/
public void contextDestroyed(ServletContextEvent event) {}
/**
* Handled internally by a call to {@link WebApplicationContextUtils#getWebApplicationContext(javax.servlet.ServletContext)}.
*
* @param event the ServletContextEvent passed in by the container, event.getServletContext() will be used to get
* the WebApplicationContext
*/
public void contextInitialized(ServletContextEvent event) {
if (log.isDebugEnabled()) {
log.debug("Received ServletContextEvent: " + event);
}
}
ApplicationContext getContext(ServletContext servletContext) {
return WebApplicationContextUtils.getWebApplicationContext(servletContext);
}

View File

@ -16,13 +16,10 @@
package org.acegisecurity.ui.session;
import junit.framework.TestCase;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockServletContext;
import org.springframework.web.context.support.StaticWebApplicationContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.http.HttpSessionEvent;
@ -35,18 +32,7 @@ import javax.servlet.http.HttpSessionEvent;
public class HttpSessionEventPublisherTests extends TestCase {
//~ Methods ========================================================================================================
public void testDelayedContextInitializationSucceeds() {
HttpSessionEventPublisher publisher = new HttpSessionEventPublisher();
MockServletContext servletContext = new MockServletContext();
// shouldn't fail, even with null context
publisher.contextInitialized(new ServletContextEvent(servletContext));
StaticWebApplicationContext context = new StaticWebApplicationContext();
context.setServletContext(servletContext);
}
/**
/**
* It's not that complicated so we'll just run it straight through here.
*/
public void testPublisher() {
@ -61,13 +47,11 @@ public class HttpSessionEventPublisherTests extends TestCase {
context.registerSingleton("listener", TestListener.class, null);
context.refresh();
publisher.contextInitialized(new ServletContextEvent(servletContext));
MockHttpSession session = new MockHttpSession(servletContext);
TestListener listener = (TestListener) context.getBean("listener");
HttpSessionEvent event = new HttpSessionEvent(session);
publisher.sessionCreated(event);
assertNotNull(listener.getCreatedEvent());
@ -82,6 +66,5 @@ public class HttpSessionEventPublisherTests extends TestCase {
assertNull(listener.getCreatedEvent());
assertEquals(session, listener.getDestroyedEvent().getSession());
publisher.contextDestroyed(new ServletContextEvent(servletContext));
}
}