Search in sources :

Example 11 with StatusInfo

use of de.codecentric.boot.admin.server.domain.values.StatusInfo 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)

Example 12 with StatusInfo

use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.

the class InstanceStatusChangedEventMixinTest method verifySerializeWithOnlyRequiredProperties.

@Test
public void verifySerializeWithOnlyRequiredProperties() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    StatusInfo statusInfo = StatusInfo.valueOf("OFFLINE");
    InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(id, 0L, timestamp, statusInfo);
    JsonContent<InstanceStatusChangedEvent> jsonContent = jsonTester.write(event);
    assertThat(jsonContent).extractingJsonPathStringValue("$.instance").isEqualTo("test123");
    assertThat(jsonContent).extractingJsonPathNumberValue("$.version").isEqualTo(0);
    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").isEmpty();
}
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 13 with StatusInfo

use of de.codecentric.boot.admin.server.domain.values.StatusInfo in project spring-boot-admin by codecentric.

the class StatusInfoMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    StatusInfo statusInfo = StatusInfo.valueOf("OFFLINE", Collections.singletonMap("foo", "bar"));
    JsonContent<StatusInfo> jsonContent = jsonTester.write(statusInfo);
    assertThat(jsonContent).extractingJsonPathStringValue("$.status").isEqualTo("OFFLINE");
    assertThat(jsonContent).extractingJsonPathMapValue("$.details").containsOnly(entry("foo", "bar"));
    assertThat(jsonContent).doesNotHaveJsonPath("$.up");
    assertThat(jsonContent).doesNotHaveJsonPath("$.offline");
    assertThat(jsonContent).doesNotHaveJsonPath("$.down");
    assertThat(jsonContent).doesNotHaveJsonPath("$.unknown");
}
Also used : StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) 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