Search in sources :

Example 11 with InstanceStatusChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.

the class InstanceStatusChangedEventMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    StatusInfo statusInfo = StatusInfo.valueOf("OFFLINE", Collections.singletonMap("foo", "bar"));
    InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(id, 12345678L, timestamp, statusInfo);
    JsonContent<InstanceStatusChangedEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(12345678);
    assertThat(jsonContent).extractingJsonPathNumberValue("$.timestamp").isEqualTo(1587751031.000000000);
    assertThat(jsonContent).extractingJsonPathStringValue("$.type").isEqualTo("STATUS_CHANGED");
    assertThat(jsonContent).extractingJsonPathValue("$.statusInfo").isNotNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.statusInfo.status").isEqualTo("OFFLINE");
    assertThat(jsonContent).extractingJsonPathMapValue("$.statusInfo.details").containsOnly(entry("foo", "bar"));
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Instant(java.time.Instant) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 12 with InstanceStatusChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.

the class AbstractEventStoreTest method should_shorten_log_on_exceeded_capacity.

@Test
public void should_shorten_log_on_exceeded_capacity() {
    InstanceEventStore store = createStore(2);
    InstanceEvent event1 = new InstanceRegisteredEvent(id, 0L, registration);
    InstanceEvent event2 = new InstanceStatusChangedEvent(id, 1L, StatusInfo.ofDown());
    InstanceEvent event3 = new InstanceStatusChangedEvent(id, 2L, StatusInfo.ofUp());
    StepVerifier.create(store.append(asList(event1, event2, event3))).verifyComplete();
    StepVerifier.create(store.findAll()).expectNext(event1, event3).verifyComplete();
}
Also used : InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) InstanceEvent(de.codecentric.boot.admin.server.domain.events.InstanceEvent) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 13 with InstanceStatusChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.

the class DiscordNotifierTest method test_onApplicationEvent_resolve_minimum_configuration.

@Test
public void test_onApplicationEvent_resolve_minimum_configuration() {
    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(null, false, null, standardMessage("UP"));
    verify(restTemplate).postForEntity(eq(webhookUri), eq(expected), eq(Void.class));
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 14 with InstanceStatusChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.

the class DiscordNotifierTest method test_onApplicationEvent_resolve.

@Test
public void test_onApplicationEvent_resolve() {
    notifier.setUsername(username);
    notifier.setAvatarUrl(avatarUrl);
    notifier.setTts(true);
    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(username, true, avatarUrl, standardMessage("UP"));
    verify(restTemplate).postForEntity(eq(webhookUri), eq(expected), eq(Void.class));
}
Also used : InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 15 with InstanceStatusChangedEvent

use of de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent in project spring-boot-admin by codecentric.

the class HipchatNotifierTest method test_onApplicationEvent_trigger.

@Test
public void test_onApplicationEvent_trigger() {
    StatusInfo infoDown = StatusInfo.ofDown();
    @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().build());
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), StatusInfo.ofUp()))).verifyComplete();
    StepVerifier.create(notifier.notify(new InstanceStatusChangedEvent(instance.getId(), instance.getVersion(), infoDown))).verifyComplete();
    assertThat(httpRequest.getValue().getHeaders()).containsEntry("Content-Type", Collections.singletonList("application/json"));
    Map<String, Object> body = httpRequest.getValue().getBody();
    assertThat(body).containsEntry("color", "red");
    assertThat(body).containsEntry("message", "<strong>App</strong>/-id- is <strong>DOWN</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.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