Example usage for javax.servlet ServletContextEvent ServletContextEvent

List of usage examples for javax.servlet ServletContextEvent ServletContextEvent

Introduction

In this page you can find the example usage for javax.servlet ServletContextEvent ServletContextEvent.

Prototype

public ServletContextEvent(ServletContext source) 

Source Link

Document

Construct a ServletContextEvent from the given context.

Usage

From source file:org.xchain.namespaces.javascript.MergeJavaScriptTest.java

@BeforeClass
public static void startXChains() throws LifecycleException, ServletException {
    Mockery servletMockery = new JUnit4Mockery();
    final String systemTemporaryDirectory = System.getProperty("java.io.tmpdir");

    // Create a mock ServletConfig and ServletContext
    final ServletConfig servletConfig = servletMockery.mock(ServletConfig.class);
    final ServletContext servletContext = servletMockery.mock(ServletContext.class);
    servletMockery.checking(new Expectations() {
        {/*from   w  w w .  ja  v  a 2 s  .  c  om*/
            allowing(servletContext).getAttribute("javax.servlet.context.tempdir");
            will(returnValue(systemTemporaryDirectory));
            allowing(servletContext).getInitParameter("ccl-policy");
            will(returnValue(null));
        }
    });

    servletMockery.checking(new Expectations() {
        {
            // Setup the base catalog to use the context class loader.
            one(servletConfig).getInitParameter(CatalogServlet.BASE_CATALOG_NAME_PARAM);
            will(returnValue("resource://context-class-loader/org/xchain/framework/servlet/webapp"));
        }
    });

    // Create and initialize the CatalogServlet.
    catalogServlet = new CatalogServlet();
    catalogServlet.init(servletConfig);

    // Create the XChainListener.
    XChainListener xchainListener = new XChainListener();
    // Since this is not running in a proper web server, there is nothing to fire
    // a ServletContextEvent when the ServletContext is initialized.  Fire the 
    // contextInitialized event manually.  This should cause the Lifecycle
    // to start running.
    xchainListener.contextInitialized(new ServletContextEvent(servletContext));
}

From source file:servletunit.frame2.MockFrame2TestCase.java

public void sendContextInitializedEvent(String key, String value) {
    if (key != null && value != null) {
        this.context.setInitParameter(key, value);
    }/*w  w  w  .ja  v  a 2 s.  c  om*/
    this.listener.contextInitialized(new ServletContextEvent(this.context));
}

From source file:servletunit.frame2.MockFrame2TestCase.java

public void sendContextDestroyedEvent() {
    this.listener.contextDestroyed(new ServletContextEvent(this.context));
}

From source file:servletunit.frame2.MockFrame2TestCase.java

public void sendContextInitializedEvent(String key1, String value1, String key2, String value2) {
    if (key1 != null && value1 != null) {
        this.context.setInitParameter(key1, value1);
    }//  w w  w  .  ja va2s  .  com

    if (key2 != null && value2 != null) {
        this.context.setInitParameter(key2, value2);
    }

    this.listener.contextInitialized(new ServletContextEvent(this.context));
}