Search in sources :

Example 1 with InstanceRegistrationUpdatedEvent

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

the class InfoUpdateTriggerTest method should_update_on_instance_registration_update_event.

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

Example 2 with InstanceRegistrationUpdatedEvent

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

the class InstanceRegistrationUpdatedEventMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    Registration registration = Registration.create("test", "http://localhost:9080/heath").managementUrl("http://localhost:9080/").serviceUrl("http://localhost:8080/").source("http-api").metadata("PASSWORD", "qwertz123").metadata("user", "humptydumpty").build();
    InstanceRegistrationUpdatedEvent event = new InstanceRegistrationUpdatedEvent(id, 12345678L, timestamp, registration);
    JsonContent<InstanceRegistrationUpdatedEvent> 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("REGISTRATION_UPDATED");
    assertThat(jsonContent).extractingJsonPathValue("$.registration").isNotNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.name").isEqualTo("test");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.managementUrl").isEqualTo("http://localhost:9080/");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.healthUrl").isEqualTo("http://localhost:9080/heath");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.serviceUrl").isEqualTo("http://localhost:8080/");
    assertThat(jsonContent).extractingJsonPathStringValue("$.registration.source").isEqualTo("http-api");
    assertThat(jsonContent).extractingJsonPathMapValue("$.registration.metadata").containsOnly(entry("PASSWORD", "******"), entry("user", "humptydumpty"));
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Instant(java.time.Instant) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 3 with InstanceRegistrationUpdatedEvent

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

the class InstanceRegistrationUpdatedEventMixinTest method verifyDeserializeWithOnlyRequiredProperties.

@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000).put("type", "REGISTRATION_UPDATED").put("registration", new JSONObject().put("name", "test").put("healthUrl", "http://localhost:9080/heath")).toString();
    InstanceRegistrationUpdatedEvent event = objectMapper.readValue(json, InstanceRegistrationUpdatedEvent.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));
    Registration registration = event.getRegistration();
    assertThat(registration).isNotNull();
    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getManagementUrl()).isNull();
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/heath");
    assertThat(registration.getServiceUrl()).isNull();
    assertThat(registration.getSource()).isNull();
    assertThat(registration.getMetadata()).isEmpty();
}
Also used : JSONObject(org.json.JSONObject) Registration(de.codecentric.boot.admin.server.domain.values.Registration) InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with InstanceRegistrationUpdatedEvent

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

the class InstanceRegistrationUpdatedEventMixinTest method verifyDeserializeWithoutRegistration.

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

Example 5 with InstanceRegistrationUpdatedEvent

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

the class StatusUpdateTriggerTest method should_continue_update_after_error.

@Test
public void should_continue_update_after_error() throws InterruptedException {
    // when status-change event is emitted and an error is emitted
    when(this.updater.updateStatus(any())).thenReturn(Mono.error(IllegalStateException::new)).thenReturn(Mono.empty());
    this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
    this.events.next(new InstanceRegistrationUpdatedEvent(this.instance.getId(), this.instance.getVersion(), this.instance.getRegistration()));
    // then should update
    verify(this.updater, times(2)).updateStatus(this.instance.getId());
}
Also used : InstanceRegistrationUpdatedEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

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