use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.
the class StatusUpdateApplicationListenerTest method test_start_stop.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() throws Exception {
StatusUpdater statusUpdater = mock(StatusUpdater.class);
ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class);
StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(statusUpdater, scheduler);
ScheduledFuture task = mock(ScheduledFuture.class);
when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(10_000L))).thenReturn(task);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
listener.onContextClosed(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(task).cancel(true);
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_no_register.
@Test
public void test_no_register() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
listener.setAutoRegister(false);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler, never()).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project zipkin by openzipkin.
the class RegisterZipkinHealthIndicators method onApplicationEvent.
@Override
public void onApplicationEvent(ApplicationEvent event) {
if (!(event instanceof ApplicationReadyEvent))
return;
ConfigurableListableBeanFactory beanFactory = ((ApplicationReadyEvent) event).getApplicationContext().getBeanFactory();
ZipkinHealthIndicator healthIndicator = beanFactory.getBean(ZipkinHealthIndicator.class);
for (Component component : beanFactory.getBeansOfType(Component.class).values()) {
healthIndicator.addComponent(component);
}
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot by spring-projects.
the class ApplicationPidFileWriterTests method createReadyEvent.
private SpringApplicationEvent createReadyEvent(String propName, String propValue) {
ConfigurableEnvironment environment = createEnvironment(propName, propValue);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
given(context.getEnvironment()).willReturn(environment);
return new ApplicationReadyEvent(new SpringApplication(), new String[] {}, context);
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.
the class DefaultApplicationFactoryTest method publishApplicationReadyEvent.
private void publishApplicationReadyEvent(DefaultApplicationFactory factory, Integer serverport, Integer managementport) {
MockEnvironment env = new MockEnvironment();
if (serverport != null) {
env.setProperty("local.server.port", serverport.toString());
}
if (managementport != null) {
env.setProperty("local.management.port", managementport.toString());
}
ConfigurableWebApplicationContext context = mock(ConfigurableWebApplicationContext.class);
when(context.getEnvironment()).thenReturn(env);
factory.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), new String[] {}, context));
}
Aggregations