Search in sources :

Example 11 with StatusInfo

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

the class SlackNotifierTest method test_onApplicationEvent_resolve_with_given_message.

@Test
public void test_onApplicationEvent_resolve_with_given_message() {
    StatusInfo infoDown = StatusInfo.ofDown();
    StatusInfo infoUp = StatusInfo.ofUp();
    notifier.setMessage(message);
    notifier.setChannel(channel);
    notifier.setIcon(icon);
    notifier.notify(getEvent(infoDown, infoUp));
    Object expected = expectedMessage("good", user, icon, channel, message);
    verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) URI(java.net.URI) Test(org.junit.Test)

Example 12 with StatusInfo

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

the class ApplicationRegistryTest method refresh.

@Test
public void refresh() throws Exception {
    // Given application is already reegistered and has status and info.
    StatusInfo status = StatusInfo.ofUp();
    Info info = Info.from(singletonMap("foo", "bar"));
    Application app = Application.create("abc").withHealthUrl("http://localhost:8080/health").withStatusInfo(status).withInfo(info).build();
    String id = idGenerator.generateId(app);
    store.save(Application.copyOf(app).withId(id).build());
    // When application registers second time
    Application registered = registry.register(Application.create("abc").withHealthUrl("http://localhost:8080/health").build());
    // Then info and status are retained
    assertThat(registered.getInfo(), sameInstance(info));
    assertThat(registered.getStatusInfo(), sameInstance(status));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) Info(de.codecentric.boot.admin.model.Info) Application(de.codecentric.boot.admin.model.Application) Test(org.junit.Test)

Example 13 with StatusInfo

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

the class HipchatNotifierTest method test_onApplicationEvent_resolve.

@Test
public void test_onApplicationEvent_resolve() {
    StatusInfo infoDown = StatusInfo.ofDown();
    StatusInfo infoUp = StatusInfo.ofUp();
    @SuppressWarnings("unchecked") ArgumentCaptor<HttpEntity<Map<String, Object>>> httpRequest = ArgumentCaptor.forClass((Class<HttpEntity<Map<String, Object>>>) (Class<?>) HttpEntity.class);
    when(restTemplate.postForEntity(isA(String.class), httpRequest.capture(), eq(Void.class))).thenReturn(ResponseEntity.ok((Void) null));
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), infoDown, infoUp));
    assertThat(httpRequest.getValue().getHeaders()).containsEntry("Content-Type", asList("application/json"));
    Map<String, Object> body = httpRequest.getValue().getBody();
    assertThat(body).containsEntry("color", "green");
    assertThat(body).containsEntry("message", "<strong>App</strong>/-id- is <strong>UP</strong>");
    assertThat(body).containsEntry("notify", Boolean.TRUE);
    assertThat(body).containsEntry("message_format", "html");
}
Also used : HttpEntity(org.springframework.http.HttpEntity) StatusInfo(de.codecentric.boot.admin.model.StatusInfo) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 14 with StatusInfo

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

the class LetsChatNotifierTest method test_onApplicationEvent_resolve_with_custom_message.

@Test
public void test_onApplicationEvent_resolve_with_custom_message() {
    StatusInfo infoDown = StatusInfo.ofDown();
    StatusInfo infoUp = StatusInfo.ofUp();
    notifier.setMessage("TEST");
    notifier.notify(getEvent(infoDown, infoUp));
    HttpEntity<?> expected = expectedMessage("TEST");
    verify(restTemplate).exchange(eq(URI.create(String.format("%s/rooms/%s/messages", host, room))), eq(HttpMethod.POST), eq(expected), eq(Void.class));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) Test(org.junit.Test)

Example 15 with StatusInfo

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

the class LetsChatNotifierTest method test_onApplicationEvent_resolve.

@Test
public void test_onApplicationEvent_resolve() {
    StatusInfo infoDown = StatusInfo.ofDown();
    StatusInfo infoUp = StatusInfo.ofUp();
    notifier.notify(getEvent(infoDown, infoUp));
    HttpEntity<?> expected = expectedMessage(standardMessage(infoUp.getStatus(), appName, id));
    verify(restTemplate).exchange(eq(URI.create(String.format("%s/rooms/%s/messages", host, room))), eq(HttpMethod.POST), eq(expected), eq(Void.class));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) Test(org.junit.Test)

Aggregations

StatusInfo (de.codecentric.boot.admin.model.StatusInfo)16 Test (org.junit.Test)15 ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)5 Application (de.codecentric.boot.admin.model.Application)5 URI (java.net.URI)5 Serializable (java.io.Serializable)3 HashMap (java.util.HashMap)2 HttpEntity (org.springframework.http.HttpEntity)2 Info (de.codecentric.boot.admin.model.Info)1 Map (java.util.Map)1 ResourceAccessException (org.springframework.web.client.ResourceAccessException)1