use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_register.
@Test
public void test_register() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_no_register_after_close.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_no_register_after_close() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, 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.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(task).cancel(true);
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot by spring-projects.
the class SpringApplicationAdminMXBeanRegistrarTests method eventsFromOtherContextsAreIgnored.
@Test
public void eventsFromOtherContextsAreIgnored() throws MalformedObjectNameException {
SpringApplicationAdminMXBeanRegistrar registrar = new SpringApplicationAdminMXBeanRegistrar(OBJECT_NAME);
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
registrar.setApplicationContext(context);
registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, mock(ConfigurableApplicationContext.class)));
assertThat(isApplicationReady(registrar)).isFalse();
registrar.onApplicationEvent(new ApplicationReadyEvent(new SpringApplication(), null, context));
assertThat(isApplicationReady(registrar)).isTrue();
}
use of org.springframework.boot.context.event.ApplicationReadyEvent in project spring-boot by spring-projects.
the class RestartApplicationListenerTests method testInitialize.
private void testInitialize(boolean failed) {
Restarter.clearInstance();
RestartApplicationListener listener = new RestartApplicationListener();
SpringApplication application = new SpringApplication();
ConfigurableApplicationContext context = mock(ConfigurableApplicationContext.class);
listener.onApplicationEvent(new ApplicationStartingEvent(application, ARGS));
assertThat(Restarter.getInstance()).isNotEqualTo(nullValue());
assertThat(Restarter.getInstance().isFinished()).isFalse();
listener.onApplicationEvent(new ApplicationPreparedEvent(application, ARGS, context));
if (failed) {
listener.onApplicationEvent(new ApplicationFailedEvent(application, ARGS, context, new RuntimeException()));
} else {
listener.onApplicationEvent(new ApplicationReadyEvent(application, ARGS, context));
}
}
Aggregations