use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class TelegramNotifierTest method test_onApplicationEvent_resolve.
@Test
public void test_onApplicationEvent_resolve() {
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();
verify(restTemplate).getForObject(eq("https://telegram.com/bot--token-/sendmessage?chat_id={chat_id}&text={text}" + "&parse_mode={parse_mode}&disable_notification={disable_notification}"), eq(Void.class), eq(getParameters("UP")));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class InfoUpdateTriggerTest method should_update_on_status_changed_event.
@Test
public void should_update_on_status_changed_event() {
// when registered event is emitted
this.events.next(new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()));
// then should update
verify(this.updater, times(1)).updateInfo(this.instance.getId());
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class InfoUpdateTriggerTest method should_continue_update_after_error.
@Test
public void should_continue_update_after_error() throws InterruptedException {
// when status-change event is emitted and an error is emitted
when(this.updater.updateInfo(any())).thenReturn(Mono.error(IllegalStateException::new)).thenReturn(Mono.empty());
this.events.next(new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofDown()));
this.events.next(new InstanceStatusChangedEvent(this.instance.getId(), this.instance.getVersion(), StatusInfo.ofUp()));
// then should update
verify(this.updater, times(2)).updateInfo(this.instance.getId());
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class InstanceStatusChangedEventMixinTest method verifyDeserialize.
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "STATUS_CHANGED").put("statusInfo", new JSONObject().put("status", "OFFLINE").put("details", new JSONObject().put("foo", "bar"))).toString();
InstanceStatusChangedEvent event = objectMapper.readValue(json, InstanceStatusChangedEvent.class);
assertThat(event).isNotNull();
assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
assertThat(event.getVersion()).isEqualTo(12345678L);
assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
StatusInfo statusInfo = event.getStatusInfo();
assertThat(statusInfo).isNotNull();
assertThat(statusInfo.getStatus()).isEqualTo("OFFLINE");
assertThat(statusInfo.getDetails()).containsOnly(entry("foo", "bar"));
}
use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.
the class InstanceStatusChangedEventMixinTest method verifyDeserializeWithOnlyRequiredProperties.
@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000).put("type", "STATUS_CHANGED").put("statusInfo", new JSONObject().put("status", "OFFLINE")).toString();
InstanceStatusChangedEvent event = objectMapper.readValue(json, InstanceStatusChangedEvent.class);
assertThat(event).isNotNull();
assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
assertThat(event.getVersion()).isEqualTo(0L);
assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
StatusInfo statusInfo = event.getStatusInfo();
assertThat(statusInfo).isNotNull();
assertThat(statusInfo.getStatus()).isEqualTo("OFFLINE");
assertThat(statusInfo.getDetails()).isEmpty();
}
Aggregations