Search in sources :

Example 6 with ApplicationRegistrator

use of de.codecentric.boot.admin.client.registration.ApplicationRegistrator 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);
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 7 with ApplicationRegistrator

use of de.codecentric.boot.admin.client.registration.ApplicationRegistrator in project spring-boot-admin by codecentric.

the class RegistrationApplicationListenerTest method test_start_stop.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() 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.startRegisterTask();
    verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
    listener.stopRegisterTask();
    verify(task).cancel(true);
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

Aggregations

ApplicationRegistrator (de.codecentric.boot.admin.client.registration.ApplicationRegistrator)7 RegistrationApplicationListener (de.codecentric.boot.admin.client.registration.RegistrationApplicationListener)6 Test (org.junit.Test)6 TaskScheduler (org.springframework.scheduling.TaskScheduler)6 ApplicationReadyEvent (org.springframework.boot.context.event.ApplicationReadyEvent)3 ContextClosedEvent (org.springframework.context.event.ContextClosedEvent)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 AdminProperties (de.codecentric.boot.admin.client.config.AdminProperties)1 ApplicationFactory (de.codecentric.boot.admin.client.registration.ApplicationFactory)1 Before (org.junit.Before)1 HttpHeaders (org.springframework.http.HttpHeaders)1 RestTemplate (org.springframework.web.client.RestTemplate)1