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());
}
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);
}
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();
}
}
}
Aggregations