Search in sources :

Example 1 with RegistrationApplicationListener

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

the class SpringBootAdminClientAutoConfiguration method registrationListener.

@Bean
@ConditionalOnMissingBean
public RegistrationApplicationListener registrationListener(AdminProperties admin, ApplicationRegistrator registrator) {
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, registrationTaskScheduler());
    listener.setAutoRegister(admin.isAutoRegistration());
    listener.setAutoDeregister(admin.isAutoDeregistration());
    listener.setRegisterPeriod(admin.getPeriod());
    return listener;
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 2 with RegistrationApplicationListener

use of de.codecentric.boot.admin.client.registration.RegistrationApplicationListener 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));
}
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) Test(org.junit.Test)

Example 3 with RegistrationApplicationListener

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

the class RegistrationApplicationListenerTest method test_no_deregister.

@Test
public void test_no_deregister() throws Exception {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
    verify(registrator, never()).deregister();
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 4 with RegistrationApplicationListener

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

the class RegistrationApplicationListenerTest method test_deregister.

@Test
public void test_deregister() throws Exception {
    ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
    TaskScheduler scheduler = mock(TaskScheduler.class);
    RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
    listener.setAutoDeregister(true);
    listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
    verify(registrator).deregister();
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 5 with RegistrationApplicationListener

use of de.codecentric.boot.admin.client.registration.RegistrationApplicationListener 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));
}
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) Test(org.junit.Test)

Aggregations

RegistrationApplicationListener (de.codecentric.boot.admin.client.registration.RegistrationApplicationListener)7 ApplicationRegistrator (de.codecentric.boot.admin.client.registration.ApplicationRegistrator)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 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 Bean (org.springframework.context.annotation.Bean)1