List of usage examples for org.springframework.context.event ContextRefreshedEvent ContextRefreshedEvent
public ContextRefreshedEvent(ApplicationContext source)
From source file:net.sourceforge.vulcan.spring.SpringEventPoolTest.java
public void testDoesNotHoldUnknownEvents() { assertEquals(0, pool.events.size()); pool.onApplicationEvent(new ContextRefreshedEvent(new GenericApplicationContext())); assertEquals(0, pool.events.size()); }
From source file:net.zcarioca.zcommons.config.spring.ConfigurationInjectionPostProcessorTest.java
/** * Test method for//w ww . j ava 2s. c o m * {@link net.zcarioca.zcommons.config.spring.ConfigurationInjectionPostProcessor#onApplicationEvent(org.springframework.context.ApplicationEvent)} * . */ @Test public void testOnApplicationEvent() { this.ctx.publishEvent(new ContextStartedEvent(this.ctx)); this.ctx.publishEvent(new ContextRefreshedEvent(this.ctx)); }
From source file:ch.ralscha.extdirectspring.controller.ApiControllerTest.java
@Before public void setupApiController() throws Exception { methodInfoCache.clear();//www. j a va2s. c om apiCache.clear(); wac.publishEvent(new ContextRefreshedEvent(wac)); Configuration config = new Configuration(); ReflectionTestUtils.setField(configurationService, "configuration", config); configurationService.afterPropertiesSet(); mockMvc = MockMvcBuilders.webAppContextSetup(wac).build(); }
From source file:org.geppetto.simulation.test.GeppettoManagerTest.java
/** * @throws java.lang.Exception//ww w . j ava2 s . c om */ @SuppressWarnings("deprecation") @BeforeClass public static void setUp() throws Exception { GenericWebApplicationContext context = new GenericWebApplicationContext(); BeanDefinition modelInterpreterBeanDefinition = new RootBeanDefinition(TestModelInterpreterService.class); BeanDefinition simulatorBeanDefinition = new RootBeanDefinition(TestSimulatorService.class); context.registerBeanDefinition("testModelInterpreter", modelInterpreterBeanDefinition); context.registerBeanDefinition("scopedTarget.testModelInterpreter", modelInterpreterBeanDefinition); context.registerBeanDefinition("testSimulator", simulatorBeanDefinition); context.registerBeanDefinition("scopedTarget.testSimulator", simulatorBeanDefinition); ContextRefreshedEvent event = new ContextRefreshedEvent(context); ApplicationListenerBean listener = new ApplicationListenerBean(); listener.onApplicationEvent(event); ApplicationContext retrievedContext = ApplicationListenerBean.getApplicationContext("testModelInterpreter"); Assert.assertNotNull(retrievedContext.getBean("scopedTarget.testModelInterpreter")); Assert.assertTrue(retrievedContext .getBean("scopedTarget.testModelInterpreter") instanceof TestModelInterpreterService); Assert.assertNotNull(retrievedContext.getBean("scopedTarget.testSimulator")); Assert.assertTrue(retrievedContext.getBean("scopedTarget.testSimulator") instanceof TestSimulatorService); DataManagerHelper.setDataManager(new DefaultGeppettoDataManager()); Assert.assertNotNull(ExperimentRunManager.getInstance()); }
From source file:com.amazonaws.serverless.proxy.spring.LambdaSpringApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { applicationContext.setServletContext(servletContext); dispatcherConfig = new DefaultDispatcherConfig(servletContext); applicationContext.setServletConfig(dispatcherConfig); // Configure the listener for the request handled events. All we do here is release the latch applicationContext.addApplicationListener(new ApplicationListener<ServletRequestHandledEvent>() { @Override//from w ww .j a v a 2 s . c om public void onApplicationEvent(ServletRequestHandledEvent servletRequestHandledEvent) { try { currentResponse.flushBuffer(); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException("Could not flush response buffer", e); } } }); // Manage the lifecycle of the root application context this.addListener(new ContextLoaderListener(applicationContext)); // Register and map the dispatcher servlet dispatcherServlet = new DispatcherServlet(applicationContext); if (refreshContext) { dispatcherServlet.refresh(); } dispatcherServlet.onApplicationEvent(new ContextRefreshedEvent(applicationContext)); dispatcherServlet.init(dispatcherConfig); notifyStartListeners(servletContext); }
From source file:org.jbb.lib.logging.LoggingBootstrapper.java
@PostConstruct public void configure() { prepareLogDirectory();/*from w w w . j ava 2 s . co m*/ String location = prepareLogConfigurationFile(); initLogging(location); applicationContextHolder.onApplicationEvent(new ContextRefreshedEvent(applicationContext)); applicationContextHolder.setApplicationContext(applicationContext); log.info("Reconfiguration of logger finished"); DelegatingLogbackAppenderHolder.getInstance().stop(); }
From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java
@Test public void logsDebugOnContextRefresh() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); this.initializer.initialize(context); context.register(Config.class); context.refresh();//w w w . jav a 2s . co m this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)); assertThat(this.debugLog.size(), not(equalTo(0))); }
From source file:org.springframework.boot.autoconfigure.AutoConfigurationReportLoggingInitializerTests.java
@Test public void logsOutput() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); this.initializer.initialize(context); context.register(Config.class); context.refresh();// ww w .j av a 2s .co m this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)); for (String message : this.debugLog) { System.out.println(message); } // Just basic sanity check, test is for visual inspection String l = this.debugLog.get(0); assertThat(l, containsString("not a web application (OnWebApplicationCondition)")); }
From source file:org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializerTests.java
@Test public void logsOutput() throws Exception { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); this.initializer.initialize(context); context.register(Config.class); ConditionEvaluationReport.get(context.getBeanFactory()).recordExclusions(Arrays.asList("com.foo.Bar")); context.refresh();/*from w w w.j a va 2s . c o m*/ this.initializer.onApplicationEvent(new ContextRefreshedEvent(context)); for (String message : this.debugLog) { System.out.println(message); } // Just basic sanity check, test is for visual inspection String l = this.debugLog.get(0); assertThat(l, containsString("not a web application (OnWebApplicationCondition)")); }
From source file:org.springframework.context.RefreshedContextAttacherTest.java
@Test public void testSingleOnContextInitializedCall() { final AtomicInteger counter = new AtomicInteger(0); RefreshedContextAttacher attacher = new RefreshedContextAttacher() { @Override/*w ww. ja v a 2 s . c om*/ protected void onContextInitialized(ApplicationContext context) { super.onContextInitialized(context); logger.info("onContextInitialized(" + context.getDisplayName() + ") call count: " + counter.incrementAndGet()); } }; ContextRefreshedEvent event = new ContextRefreshedEvent(applicationContext); for (int index = 1; index <= Byte.SIZE; index++) { attacher.onApplicationEvent(event); Assert.assertEquals("Mismatched number of calls at index=" + index, 1, counter.get()); } }