Search in sources :

Example 6 with InstanceInfoChangedEvent

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

the class InstanceInfoChangedEventMixinTest method verifySerializeWithEmptyInfo.

@Test
public void verifySerializeWithEmptyInfo() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    InstanceInfoChangedEvent event = new InstanceInfoChangedEvent(id, 12345678L, timestamp, Info.from(Collections.emptyMap()));
    JsonContent<InstanceInfoChangedEvent> 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("INFO_CHANGED");
    assertThat(jsonContent).extractingJsonPathMapValue("$.info").isEmpty();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instant(java.time.Instant) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 7 with InstanceInfoChangedEvent

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

the class InstanceInfoChangedEventMixinTest method verifyDeserializeWithOnlyRequiredProperties.

@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000).put("type", "INFO_CHANGED").toString();
    InstanceInfoChangedEvent event = objectMapper.readValue(json, InstanceInfoChangedEvent.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));
    assertThat(event.getInfo()).isNull();
}
Also used : JSONObject(org.json.JSONObject) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceInfoChangedEvent

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

the class InstanceInfoChangedEventMixinTest method verifySerializeWithOnlyRequiredProperties.

@Test
public void verifySerializeWithOnlyRequiredProperties() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    InstanceInfoChangedEvent event = new InstanceInfoChangedEvent(id, 0L, timestamp, null);
    JsonContent<InstanceInfoChangedEvent> 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("INFO_CHANGED");
    assertThat(jsonContent).extractingJsonPathMapValue("$.info").isNull();
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instant(java.time.Instant) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceInfoChangedEvent

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

the class InstanceInfoChangedEventMixinTest method verifyDeserialize.

@Test
public void verifyDeserialize() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "INFO_CHANGED").put("info", new JSONObject().put("build", new JSONObject().put("version", "1.0.0")).put("foo", "bar")).toString();
    InstanceInfoChangedEvent event = objectMapper.readValue(json, InstanceInfoChangedEvent.class);
    assertThat(event).isNotNull();
    assertThat(event.getInstance()).isEqualTo(InstanceId.of("test123"));
    assertThat(event.getVersion()).isEqualTo(12345678L);
    assertThat(event.getTimestamp()).isEqualTo(Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS));
    Info info = event.getInfo();
    assertThat(info).isNotNull();
    assertThat(info.getValues()).containsOnly(entry("build", Collections.singletonMap("version", "1.0.0")), entry("foo", "bar"));
}
Also used : JSONObject(org.json.JSONObject) InstanceInfoChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent) Info(de.codecentric.boot.admin.server.domain.values.Info) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)9 Test (org.junit.jupiter.api.Test)8 JSONObject (org.json.JSONObject)4 Info (de.codecentric.boot.admin.server.domain.values.Info)3 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)3 Instant (java.time.Instant)3 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 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)1 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)1 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)1 Registration (de.codecentric.boot.admin.server.domain.values.Registration)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1 HashMap (java.util.HashMap)1