Search in sources :

Example 1 with ApplicationRegistrator

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

the class ApplicationRegistratorTest method setup.

@Before
public void setup() {
    restTemplate = mock(RestTemplate.class);
    adminProps = new AdminProperties();
    adminProps.setUrl(new String[] { "http://sba:8080", "http://sba2:8080" });
    ApplicationFactory factory = mock(ApplicationFactory.class);
    when(factory.createApplication()).thenReturn(Application.create("AppName").withManagementUrl("http://localhost:8080/mgmt").withHealthUrl("http://localhost:8080/health").withServiceUrl("http://localhost:8080").build());
    registrator = new ApplicationRegistrator(restTemplate, adminProps, factory);
    headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);
    headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
}
Also used : AdminProperties(de.codecentric.boot.admin.client.config.AdminProperties) HttpHeaders(org.springframework.http.HttpHeaders) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) RestTemplate(org.springframework.web.client.RestTemplate) ApplicationFactory(de.codecentric.boot.admin.client.registration.ApplicationFactory) Before(org.junit.Before)

Example 2 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.

@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 ApplicationRegistrator

use of de.codecentric.boot.admin.client.registration.ApplicationRegistrator 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 ApplicationRegistrator

use of de.codecentric.boot.admin.client.registration.ApplicationRegistrator 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 ApplicationRegistrator

use of de.codecentric.boot.admin.client.registration.ApplicationRegistrator 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

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