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