Search in sources :

Example 46 with InstanceStatusChangedEvent

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")));
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 47 with InstanceStatusChangedEvent

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());
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 48 with InstanceStatusChangedEvent

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());
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 49 with InstanceStatusChangedEvent

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"));
}
Also used : JSONObject(org.json.JSONObject) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 50 with InstanceStatusChangedEvent

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();
}
Also used : JSONObject(org.json.JSONObject) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)51 Test (org.junit.jupiter.api.Test)47 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)9 HttpEntity (org.springframework.http.HttpEntity)6 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)5 URI (java.net.URI)5 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 HashMap (java.util.HashMap)4 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)3 Message (de.codecentric.boot.admin.server.notify.MicrosoftTeamsNotifier.Message)3 Instant (java.time.Instant)3 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 Registration (de.codecentric.boot.admin.server.domain.values.Registration)2 MimeMessage (javax.mail.internet.MimeMessage)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.get (com.github.tomakehurst.wiremock.client.WireMock.get)1 WireMock.ok (com.github.tomakehurst.wiremock.client.WireMock.ok)1