Search in sources :

Example 21 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class SimpleJournaledEventStoreTest method test_store_capacity.

@Test
public void test_store_capacity() {
    SimpleJournaledEventStore store = new SimpleJournaledEventStore();
    store.setCapacity(2);
    Application application = Application.create("foo").withId("bar").withHealthUrl("http://health").build();
    List<ClientApplicationEvent> events = Arrays.asList(new ClientApplicationRegisteredEvent(application), new ClientApplicationDeregisteredEvent(application), new ClientApplicationDeregisteredEvent(application));
    for (ClientApplicationEvent event : events) {
        store.store(event);
    }
    assertThat(store.findAll(), is((Collection<ClientApplicationEvent>) Arrays.asList(events.get(2), events.get(1))));
}
Also used : ClientApplicationDeregisteredEvent(de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent) Collection(java.util.Collection) ClientApplicationRegisteredEvent(de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent) Application(de.codecentric.boot.admin.model.Application) ClientApplicationEvent(de.codecentric.boot.admin.event.ClientApplicationEvent) Test(org.junit.Test)

Example 22 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class ApplicationRegistryTest method getApplications.

@Test
public void getApplications() throws Exception {
    Application app = registry.register(Application.create("abc").withHealthUrl("http://localhost/health").build());
    Collection<Application> applications = registry.getApplications();
    assertEquals(1, applications.size());
    assertTrue(applications.contains(app));
}
Also used : Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 23 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class StatusUpdateApplicationListenerTest method test_newApplication.

@Test
public void test_newApplication() throws Exception {
    StatusUpdater statusUpdater = mock(StatusUpdater.class);
    ThreadPoolTaskScheduler scheduler = mock(ThreadPoolTaskScheduler.class);
    when(scheduler.submit(any(Runnable.class))).then(new Answer<Future<?>>() {

        @Override
        public Future<?> answer(InvocationOnMock invocation) throws Throwable {
            invocation.getArgumentAt(0, Runnable.class).run();
            SettableListenableFuture<?> future = new SettableListenableFuture<Void>();
            future.set(null);
            return future;
        }
    });
    StatusUpdateApplicationListener listener = new StatusUpdateApplicationListener(statusUpdater, scheduler);
    Application application = Application.create("test").withHealthUrl("http://example.com").build();
    listener.onClientApplicationRegistered(new ClientApplicationRegisteredEvent(application));
    verify(statusUpdater).updateStatus(eq(application));
}
Also used : SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) ClientApplicationRegisteredEvent(de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent) ThreadPoolTaskScheduler(org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ScheduledFuture(java.util.concurrent.ScheduledFuture) SettableListenableFuture(org.springframework.util.concurrent.SettableListenableFuture) Future(java.util.concurrent.Future) SpringApplication(org.springframework.boot.SpringApplication) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 24 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class StatusUpdaterTest method test_update_statusChanged.

@Test
public void test_update_statusChanged() {
    when(applicationOps.getHealth(isA(Application.class))).thenReturn(ResponseEntity.ok().body(Collections.<String, Serializable>singletonMap("status", "UP")));
    when(applicationOps.getInfo(isA(Application.class))).thenReturn(ResponseEntity.ok().body(Collections.<String, Serializable>singletonMap("foo", "bar")));
    updater.updateStatus(Application.create("foo").withId("id").withHealthUrl("health").build());
    Application app = store.find("id");
    assertThat(app.getStatusInfo().getStatus(), CoreMatchers.is("UP"));
    assertThat((Map<String, ? extends Serializable>) app.getInfo().getValues(), hasEntry("foo", (Serializable) "bar"));
    verify(publisher).publishEvent(argThat(CoreMatchers.isA(ClientApplicationStatusChangedEvent.class)));
}
Also used : Serializable(java.io.Serializable) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 25 with Application

use of de.codecentric.boot.admin.model.Application in project spring-boot-admin by codecentric.

the class StatusUpdaterTest method test_update_offline.

@Test
public void test_update_offline() {
    when(applicationOps.getHealth(any(Application.class))).thenThrow(new ResourceAccessException("error"));
    Application app = Application.create("foo").withId("id").withHealthUrl("health").withStatusInfo(StatusInfo.ofUp()).build();
    updater.updateStatus(app);
    StatusInfo statusInfo = store.find("id").getStatusInfo();
    assertThat(statusInfo.getStatus(), CoreMatchers.is("OFFLINE"));
    assertThat(statusInfo.getDetails(), hasEntry("message", (Serializable) "error"));
    assertThat(statusInfo.getDetails(), hasEntry("exception", (Serializable) "org.springframework.web.client.ResourceAccessException"));
}
Also used : Serializable(java.io.Serializable) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) Application(de.codecentric.boot.admin.model.Application) ResourceAccessException(org.springframework.web.client.ResourceAccessException) Test(org.junit.Test)

Aggregations

Application (de.codecentric.boot.admin.model.Application)36 Test (org.junit.Test)27 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)7 ServiceInstance (org.springframework.cloud.client.ServiceInstance)7 ClientApplicationRegisteredEvent (de.codecentric.boot.admin.event.ClientApplicationRegisteredEvent)5 ClientApplicationDeregisteredEvent (de.codecentric.boot.admin.event.ClientApplicationDeregisteredEvent)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)3 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)3 Collection (java.util.Collection)3 Map (java.util.Map)3 EurekaServiceInstance (org.springframework.cloud.netflix.eureka.EurekaDiscoveryClient.EurekaServiceInstance)3 HttpHeaders (org.springframework.http.HttpHeaders)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 Collections.singletonMap (java.util.Collections.singletonMap)2 HttpEntity (org.springframework.http.HttpEntity)2 RequestContext (com.netflix.zuul.context.RequestContext)1 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)1