Search in sources :

Example 21 with InstanceRegisteredEvent

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

the class InstanceRegisteredEventMixinTest 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();
    InstanceRegisteredEvent event = new InstanceRegisteredEvent(id, 12345678L, timestamp, registration);
    JsonContent<InstanceRegisteredEvent> 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("REGISTERED");
    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) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Instant(java.time.Instant) Test(org.junit.jupiter.api.Test)

Example 22 with InstanceRegisteredEvent

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

the class InstanceRegisteredEventMixinTest method verifySerializeWithOnlyRequiredProperties.

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

Aggregations

InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)22 Test (org.junit.jupiter.api.Test)20 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)5 Registration (de.codecentric.boot.admin.server.domain.values.Registration)5 InstanceDeregisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceDeregisteredEvent)4 InstanceEvent (de.codecentric.boot.admin.server.domain.events.InstanceEvent)4 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)4 Instant (java.time.Instant)4 JSONObject (org.json.JSONObject)3 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)2 HttpEntity (org.springframework.http.HttpEntity)2 InstanceEndpointsDetectedEvent (de.codecentric.boot.admin.server.domain.events.InstanceEndpointsDetectedEvent)1 InstanceInfoChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceInfoChangedEvent)1 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)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 StandardEvaluationContext (org.springframework.expression.spel.support.StandardEvaluationContext)1 HttpHeaders (org.springframework.http.HttpHeaders)1