BayeuxServerImpl bayeuxServer = injector.getInstance(BayeuxServerImpl.class);
bayeuxServer.start();
// Configure services
// Guice does not handle @PostConstruct and @PreDestroy, so we need to handle them
ServerAnnotationProcessor processor = new ServerAnnotationProcessor(bayeuxServer);
GuiceBayeuxService service = injector.getInstance(GuiceBayeuxService.class);
Assert.assertTrue(processor.process(service));
// At this point we're configured properly
// The code above should be put into a ServletContextListener.contextInitialized()
// method, so that it is triggered by the web application lifecycle handling
// and the BayeuxServer instance can be put into the ServletContext
// Test that we're configured properly
Assert.assertNotNull(service);
assertNotNull(service.dependency);
assertNotNull(service.bayeuxServer);
assertNotNull(service.serverSession);
assertTrue(service.active);
assertEquals(1, service.bayeuxServer.getChannel(GuiceBayeuxService.CHANNEL).getSubscribers().size());
// Deconfigure services
// The code below should be put into a ServletContextListener.contextDestroyed()
// method, so that it is triggered by the web application lifecycle handling
Assert.assertTrue(processor.deprocess(service));
// Manually stop the BayeuxServer
bayeuxServer.stop();
assertFalse(service.active);
}