Search in sources :

Example 6 with InstanceEndpointsDetectedEvent

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

the class InfoUpdateTriggerTest method should_update_on_endpoints_detectes_event.

@Test
public void should_update_on_endpoints_detectes_event() {
    // when registered event is emitted
    this.events.next(new InstanceEndpointsDetectedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getEndpoints()));
    // then should update
    verify(this.updater, times(1)).updateInfo(this.instance.getId());
}
Also used : InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Test(org.junit.jupiter.api.Test)

Example 7 with InstanceEndpointsDetectedEvent

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

the class InstanceEndpointsDetectedEventMixinTest 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", "ENDPOINTS_DETECTED").put("endpoints", new JSONArray().put(new JSONObject().put("id", "info").put("url", "http://localhost:8080/info")).put(new JSONObject().put("id", "health").put("url", "http://localhost:8080/health"))).toString();
    InstanceEndpointsDetectedEvent event = objectMapper.readValue(json, InstanceEndpointsDetectedEvent.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));
    assertThat(event.getEndpoints()).containsExactlyInAnyOrder(Endpoint.of("info", "http://localhost:8080/info"), Endpoint.of("health", "http://localhost:8080/health"));
}
Also used : JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Test(org.junit.jupiter.api.Test)

Example 8 with InstanceEndpointsDetectedEvent

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

the class InstanceEndpointsDetectedEventMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    Endpoints endpoints = Endpoints.single("info", "http://localhost:8080/info").withEndpoint("health", "http://localhost:8080/health");
    InstanceEndpointsDetectedEvent event = new InstanceEndpointsDetectedEvent(id, 12345678L, timestamp, endpoints);
    JsonContent<InstanceEndpointsDetectedEvent> 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("ENDPOINTS_DETECTED");
    assertThat(jsonContent).extractingJsonPathArrayValue("$.endpoints").hasSize(2);
    assertThat(jsonContent).extractingJsonPathStringValue("$.endpoints[0].id").isIn("info", "health");
    assertThat(jsonContent).extractingJsonPathStringValue("$.endpoints[0].url").isIn("http://localhost:8080/info", "http://localhost:8080/health");
    assertThat(jsonContent).extractingJsonPathStringValue("$.endpoints[1].id").isIn("info", "health");
    assertThat(jsonContent).extractingJsonPathStringValue("$.endpoints[1].url").isIn("http://localhost:8080/info", "http://localhost:8080/health");
}
Also used : Endpoints(de.codecentric.boot.admin.server.domain.values.Endpoints) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instant(java.time.Instant) InstanceEndpointsDetectedEvent(de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent) Test(org.junit.jupiter.api.Test)

Example 9 with InstanceEndpointsDetectedEvent

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

the class InstanceEndpointsDetectedEventMixinTest method verifySerializeWithOnlyRequiredProperties.

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

Aggregations

InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)9 Test (org.junit.jupiter.api.Test)7 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)3 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)3 Instant (java.time.Instant)3 JSONObject (org.json.JSONObject)3 JSONArray (org.json.JSONArray)2 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)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 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)1 Info (de.codecentric.boot.admin.server.domain.values.Info)1 Registration (de.codecentric.boot.admin.server.domain.values.Registration)1 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)1