Search in sources :

Example 6 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent 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 7 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent_throw_doesnt_propagate.

@Test
public void test_onApplicationEvent_throw_doesnt_propagate() {
    Notifier notifier = new AbstractStatusChangeNotifier() {

        @Override
        protected void doNotify(ClientApplicationEvent event) throws Exception {
            throw new IllegalStateException("test");
        }
    };
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofOffline(), StatusInfo.ofUp()));
}
Also used : ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) ClientApplicationEvent(de.codecentric.boot.admin.event.ClientApplicationEvent) Test(org.junit.Test)

Example 8 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent_disbaled.

// The following tests are rather for AbstractNotifier
@Test
public void test_onApplicationEvent_disbaled() {
    notifier.setEnabled(false);
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo.ofUp()));
    verifyNoMoreInteractions(sender);
}
Also used : ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 9 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class MailNotifierTest method test_onApplicationEvent.

@Test
public void test_onApplicationEvent() {
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), StatusInfo.ofDown(), StatusInfo.ofUp()));
    SimpleMailMessage expected = new SimpleMailMessage();
    expected.setTo(new String[] { "foo@bar.com" });
    expected.setCc(new String[] { "bar@foo.com" });
    expected.setFrom("SBA <no-reply@example.com>");
    expected.setText("App (-id-)\nstatus changed from DOWN to UP\n\nhttp://health");
    expected.setSubject("-id- is UP");
    verify(sender).send(eq(expected));
}
Also used : SimpleMailMessage(org.springframework.mail.SimpleMailMessage) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Example 10 with ClientApplicationStatusChangedEvent

use of de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent in project spring-boot-admin by codecentric.

the class PagerdutyNotifierTest method test_onApplicationEvent_trigger.

@Test
public void test_onApplicationEvent_trigger() {
    StatusInfo infoDown = StatusInfo.ofDown();
    StatusInfo infoUp = StatusInfo.ofUp();
    notifier.notify(new ClientApplicationStatusChangedEvent(Application.create("App").withId("-id-").withHealthUrl("http://health").build(), infoUp, infoDown));
    Map<String, Object> expected = new HashMap<String, Object>();
    expected.put("service_key", "--service--");
    expected.put("incident_key", "App/-id-");
    expected.put("event_type", "trigger");
    expected.put("description", "App/-id- is DOWN");
    expected.put("client", "TestClient");
    expected.put("client_url", URI.create("http://localhost"));
    Map<String, Object> details = new HashMap<String, Object>();
    details.put("from", infoUp);
    details.put("to", infoDown);
    expected.put("details", details);
    Map<String, Object> context = new HashMap<String, Object>();
    context.put("type", "link");
    context.put("href", "http://health");
    context.put("text", "Application health-endpoint");
    expected.put("contexts", Arrays.asList(context));
    verify(restTemplate).postForEntity(eq(PagerdutyNotifier.DEFAULT_URI), eq(expected), eq(Void.class));
}
Also used : StatusInfo(de.codecentric.boot.admin.model.StatusInfo) HashMap(java.util.HashMap) ClientApplicationStatusChangedEvent(de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent) Test(org.junit.Test)

Aggregations

ClientApplicationStatusChangedEvent (de.codecentric.boot.admin.event.ClientApplicationStatusChangedEvent)11 Test (org.junit.Test)9 StatusInfo (de.codecentric.boot.admin.model.StatusInfo)5 HashMap (java.util.HashMap)2 HttpEntity (org.springframework.http.HttpEntity)2 ClientApplicationEvent (de.codecentric.boot.admin.event.ClientApplicationEvent)1 Application (de.codecentric.boot.admin.model.Application)1 SimpleMailMessage (org.springframework.mail.SimpleMailMessage)1