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");
}
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()));
}
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);
}
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));
}
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));
}
Aggregations