use of de.codecentric.boot.admin.server.domain.values.StatusInfo 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.values.StatusInfo in project spring-boot-admin by codecentric.
the class StatusInfoMixinTest method verifyDeserialize.
@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("status", "OFFLINE").put("details", new JSONObject().put("foo", "bar")).toString();
StatusInfo statusInfo = objectMapper.readValue(json, StatusInfo.class);
assertThat(statusInfo).isNotNull();
assertThat(statusInfo.getStatus()).isEqualTo("OFFLINE");
assertThat(statusInfo.getDetails()).containsOnly(entry("foo", "bar"));
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.
the class InstanceRegistryTest method refresh.
@Test
public void refresh() {
// Given instance is already reegistered and has status and info.
StatusInfo status = StatusInfo.ofUp();
Info info = Info.from(singletonMap("foo", "bar"));
Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
InstanceId id = idGenerator.generateId(registration);
Instance app = Instance.create(id).register(registration).withStatusInfo(status).withInfo(info);
StepVerifier.create(repository.save(app)).expectNextCount(1).verifyComplete();
// When instance registers second time
InstanceId refreshId = registry.register(Registration.create("abc", "http://localhost:8080/health").build()).block();
assertThat(refreshId).isEqualTo(id);
StepVerifier.create(registry.getInstance(id)).assertNext((registered) -> {
// Then info and status are retained
assertThat(registered.getInfo()).isEqualTo(info);
assertThat(registered.getStatusInfo()).isEqualTo(status);
}).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo 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");
}
use of de.codecentric.boot.admin.server.domain.values.StatusInfo 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));
}
Aggregations