Search in sources :

Example 31 with ServletContextEvent

use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerTest method contextDestroyed_excDuringWaitUntilStopped_ExcThrown.

@Test(expected = BrokerLifecycleException.class)
public void contextDestroyed_excDuringWaitUntilStopped_ExcThrown() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    BrokerService broker = mock(BrokerService.class);
    doReturn(true).when(broker).isStarted();
    doReturn(true).when(broker).waitUntilStarted();
    doThrow(new BrokerLifecycleException()).when(broker).waitUntilStopped();
    WebBrokerInitializer i = spy(WebBrokerInitializer.class);
    doReturn(broker).when(i).createBroker(sc);
    i.contextInitialized(new ServletContextEvent(sc));
    i.contextDestroyed(new ServletContextEvent(sc));
}
Also used : ServletContext(javax.servlet.ServletContext) BrokerService(org.apache.activemq.broker.BrokerService) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 32 with ServletContextEvent

use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerTest method contextInitialized.

@Test
public void contextInitialized() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    BrokerService broker = mock(BrokerService.class);
    doReturn(true).when(broker).waitUntilStarted();
    WebBrokerInitializer i = spy(WebBrokerInitializer.class);
    doReturn(broker).when(i).createBroker(sc);
    i.contextInitialized(new ServletContextEvent(sc));
}
Also used : ServletContext(javax.servlet.ServletContext) BrokerService(org.apache.activemq.broker.BrokerService) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 33 with ServletContextEvent

use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerTest method contextInitialized_excDuringBrokerCreate_ExcThrown.

@Test(expected = BrokerLifecycleException.class)
public void contextInitialized_excDuringBrokerCreate_ExcThrown() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    WebBrokerInitializer i = spy(WebBrokerInitializer.class);
    doThrow(new BrokerLifecycleException()).when(i).createBroker(sc);
    i.contextInitialized(new ServletContextEvent(sc));
}
Also used : ServletContext(javax.servlet.ServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 34 with ServletContextEvent

use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.

the class WebBrokerInitializerTest method contextDestroyed_brokerNotStarted_doNothing.

@Test
public void contextDestroyed_brokerNotStarted_doNothing() throws Exception {
    ServletContext sc = mock(ServletContext.class);
    BrokerService broker = mock(BrokerService.class);
    doReturn(false).when(broker).isStarted();
    doReturn(true).when(broker).waitUntilStarted();
    WebBrokerInitializer i = spy(WebBrokerInitializer.class);
    doReturn(broker).when(i).createBroker(sc);
    i.contextInitialized(new ServletContextEvent(sc));
    i.contextDestroyed(new ServletContextEvent(sc));
    verify(broker, never()).stop();
}
Also used : ServletContext(javax.servlet.ServletContext) BrokerService(org.apache.activemq.broker.BrokerService) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Example 35 with ServletContextEvent

use of javax.servlet.ServletContextEvent in project hevelian-activemq by Hevelian.

the class ServletContextHolderInitializerTest method contextInitialized.

@Test
public void contextInitialized() {
    ServletContextHolderInitializer i = new ServletContextHolderInitializer();
    ServletContext sc = Mockito.mock(ServletContext.class);
    i.contextInitialized(new ServletContextEvent(sc));
    assertEquals(sc, ServletContextHolder.getServletContext());
}
Also used : ServletContext(javax.servlet.ServletContext) ServletContextEvent(javax.servlet.ServletContextEvent) Test(org.junit.Test)

Aggregations

ServletContextEvent (javax.servlet.ServletContextEvent)74 Test (org.junit.Test)43 MockServletContext (org.springframework.mock.web.test.MockServletContext)21 ServletContextListener (javax.servlet.ServletContextListener)19 ServletContext (javax.servlet.ServletContext)18 Injector (com.google.inject.Injector)10 ContextLoaderListener (org.springframework.web.context.ContextLoaderListener)10 XmlWebApplicationContext (org.springframework.web.context.support.XmlWebApplicationContext)8 SimpleWebApplicationContext (org.springframework.web.servlet.SimpleWebApplicationContext)8 Test (org.testng.annotations.Test)8 BrokerService (org.apache.activemq.broker.BrokerService)7 IOException (java.io.IOException)6 Properties (java.util.Properties)6 TestBean (org.springframework.tests.sample.beans.TestBean)6 ArrayList (java.util.ArrayList)5 SystemPropertiesHelper.overrideSystemProperties (org.eclipse.che.commons.test.SystemPropertiesHelper.overrideSystemProperties)5 File (java.io.File)4 MalformedURLException (java.net.MalformedURLException)3 HashMap (java.util.HashMap)3 ServletException (javax.servlet.ServletException)3