use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class NotificationTriggerTest method should_notify_on_event.
@Test
public void should_notify_on_event() throws InterruptedException {
// given the notifier subscribed to the events
this.trigger.start();
await().until(this.events::wasSubscribed);
// when registered event is emitted
InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown());
this.events.next(event);
// then should notify
verify(this.notifier, times(1)).notify(event);
// when registered event is emitted but the trigger has been stopped
this.trigger.stop();
clearInvocations(this.notifier);
this.events.next(new InstanceRegisteredEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
// then should not notify
verify(this.notifier, never()).notify(event);
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class PagerdutyNotifierTest method test_onApplicationEvent_resolve.
@Test
public void test_onApplicationEvent_resolve() {
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 1, StatusInfo.ofDown()))).verifyComplete();
reset(restTemplate);
StatusInfo up = StatusInfo.ofUp();
when(repository.find(INSTANCE.getId())).thenReturn(Mono.just(INSTANCE.withStatusInfo(up)));
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 2, up))).verifyComplete();
Map<String, Object> expected = new HashMap<>();
expected.put("service_key", "--service--");
expected.put("incident_key", "App/-id-");
expected.put("event_type", "resolve");
expected.put("description", "App/-id- is UP");
Map<String, Object> details = new HashMap<>();
details.put("from", "DOWN");
details.put("to", up);
expected.put("details", details);
verify(restTemplate).postForEntity(eq(PagerdutyNotifier.DEFAULT_URI), eq(expected), eq(Void.class));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class PagerdutyNotifierTest method test_onApplicationEvent_trigger.
@Test
public void test_onApplicationEvent_trigger() {
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 1, StatusInfo.ofUp()))).verifyComplete();
reset(restTemplate);
StatusInfo down = StatusInfo.ofDown();
when(repository.find(INSTANCE.getId())).thenReturn(Mono.just(INSTANCE.withStatusInfo(down)));
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion() + 2, down))).verifyComplete();
Map<String, Object> expected = new HashMap<>();
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<>();
details.put("from", "UP");
details.put("to", down);
expected.put("details", details);
Map<String, Object> context = new HashMap<>();
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));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class SlackNotifierTest method test_onApplicationEvent_resolve.
@Test
public void test_onApplicationEvent_resolve() {
notifier.setChannel(channel);
notifier.setIcon(icon);
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))).verifyComplete();
clearInvocations(restTemplate);
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))).verifyComplete();
Object expected = expectedMessage("good", user, icon, channel, standardMessage("UP"));
verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class SlackNotifierTest method test_onApplicationEvent_resolve_without_channel_and_icon.
@Test
public void test_onApplicationEvent_resolve_without_channel_and_icon() {
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofDown()))).verifyComplete();
clearInvocations(restTemplate);
StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(INSTANCE.getId(), INSTANCE.getVersion(), StatusInfo.ofUp()))).verifyComplete();
Object expected = expectedMessage("good", user, null, null, standardMessage("UP"));
verify(restTemplate).postForEntity(any(URI.class), eq(expected), eq(Void.class));
}
Aggregations