Search in sources :

Example 1 with ContainerInitialized

use of org.jboss.weld.environment.se.events.ContainerInitialized in project core by weld.

the class EventsTest method testEventQualifiersCorrect.

// forum post check
@Test
public void testEventQualifiersCorrect(Event<Object> event) {
    Foo.reset();
    event.select(ContainerInitialized.class).fire(new ContainerInitialized());
    assertFalse(Foo.isObservedEventTest());
}
Also used : ContainerInitialized(org.jboss.weld.environment.se.events.ContainerInitialized) Test(org.junit.Test)

Example 2 with ContainerInitialized

use of org.jboss.weld.environment.se.events.ContainerInitialized in project core by weld.

the class WeldContainer method fireContainerInitializedEvent.

private void fireContainerInitializedEvent() {
    WeldSELogger.LOG.weldContainerInitialized(id);
    beanManager().fireEvent(new ContainerInitialized(id), Initialized.Literal.APPLICATION);
}
Also used : ContainerInitialized(org.jboss.weld.environment.se.events.ContainerInitialized)

Example 3 with ContainerInitialized

use of org.jboss.weld.environment.se.events.ContainerInitialized in project core by weld.

the class BootstrapNotNeededTest method testBootstrapNotNeeded.

@Test
public void testBootstrapNotNeeded() throws Exception {
    String id = UUID.randomUUID().toString();
    // First boostrap Weld SE
    try (WeldContainer container = new Weld(id).initialize()) {
        TestBean testBean = container.instance().select(TestBean.class).get();
        assertNotNull(testBean);
        // @Initialized(ApplicationScoped.class) ContainerInitialized
        List<Object> initEvents = testBean.getInitEvents();
        assertEquals(1, initEvents.size());
        Object event = initEvents.get(0);
        assertTrue(event instanceof ContainerInitialized);
        assertEquals(id, ((ContainerInitialized) event).getContainerId());
        // Test CDIProvider
        CDI<Object> cdi = CDI.current();
        assertTrue(cdi instanceof WeldContainer);
        // Then start Jetty
        Server server = new Server(InetSocketAddress.createUnresolved("localhost", 8080));
        try {
            ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
            context.setContextPath("/");
            server.setHandler(context);
            context.addServlet(TestServlet.class, "/test");
            context.setAttribute(WeldServletLifecycle.BEAN_MANAGER_ATTRIBUTE_NAME, container.getBeanManager());
            context.addEventListener(new Listener());
            server.start();
            // @Initialized(ApplicationScoped.class) ServletContext not fired
            assertEquals(1, initEvents.size());
            WebClient webClient = new WebClient();
            webClient.setThrowExceptionOnFailingStatusCode(true);
            Page page = webClient.getPage("http://localhost:8080/test");
            assertEquals(testBean.getId(), page.getWebResponse().getContentAsString().trim());
        } finally {
            server.stop();
        }
    }
}
Also used : Listener(org.jboss.weld.environment.servlet.Listener) Server(org.eclipse.jetty.server.Server) WeldContainer(org.jboss.weld.environment.se.WeldContainer) Page(com.gargoylesoftware.htmlunit.Page) ContainerInitialized(org.jboss.weld.environment.se.events.ContainerInitialized) WebClient(com.gargoylesoftware.htmlunit.WebClient) Weld(org.jboss.weld.environment.se.Weld) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) Test(org.junit.Test)

Aggregations

ContainerInitialized (org.jboss.weld.environment.se.events.ContainerInitialized)3 Test (org.junit.Test)2 Page (com.gargoylesoftware.htmlunit.Page)1 WebClient (com.gargoylesoftware.htmlunit.WebClient)1 Server (org.eclipse.jetty.server.Server)1 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)1 Weld (org.jboss.weld.environment.se.Weld)1 WeldContainer (org.jboss.weld.environment.se.WeldContainer)1 Listener (org.jboss.weld.environment.servlet.Listener)1