Search in sources :

Example 1 with StatusInfo

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"));
}
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 2 with StatusInfo

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

Example 3 with StatusInfo

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();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Info(de.codecentric.boot.admin.server.domain.values.Info) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Test(org.junit.jupiter.api.Test)

Example 4 with StatusInfo

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

Example 5 with StatusInfo

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

Aggregations

StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)13 Test (org.junit.jupiter.api.Test)11 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)9 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)4 HashMap (java.util.HashMap)3 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)2 Info (de.codecentric.boot.admin.server.domain.values.Info)2 Registration (de.codecentric.boot.admin.server.domain.values.Registration)2 Instant (java.time.Instant)2 HttpEntity (org.springframework.http.HttpEntity)2 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)1 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)1 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 Endpoint (de.codecentric.boot.admin.server.domain.values.Endpoint)1