Search in sources :

Example 46 with Registration

use of de.codecentric.boot.admin.server.domain.values.Registration 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 47 with Registration

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

Example 48 with Registration

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

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

Example 49 with Registration

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

the class InstanceRegistrationUpdatedEventMixinTest 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", "REGISTRATION_UPDATED").put("registration", new JSONObject().put("name", "test").put("managementUrl", "http://localhost:9080/").put("healthUrl", "http://localhost:9080/heath").put("serviceUrl", "http://localhost:8080/").put("source", "http-api").put("metadata", new JSONObject().put("PASSWORD", "******").put("user", "humptydumpty"))).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));
    Registration registration = event.getRegistration();
    assertThat(registration).isNotNull();
    assertThat(registration.getName()).isEqualTo("test");
    assertThat(registration.getManagementUrl()).isEqualTo("http://localhost:9080/");
    assertThat(registration.getHealthUrl()).isEqualTo("http://localhost:9080/heath");
    assertThat(registration.getServiceUrl()).isEqualTo("http://localhost:8080/");
    assertThat(registration.getSource()).isEqualTo("http-api");
    assertThat(registration.getMetadata()).containsOnly(entry("PASSWORD", "******"), entry("user", "humptydumpty"));
}
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 50 with Registration

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

the class RegistrationDeserializerTest method test_1_2_json_format.

@Test
public void test_1_2_json_format() throws Exception {
    String json = new JSONObject().put("name", "test").put("url", "http://test").toString();
    Registration value = objectMapper.readValue(json, Registration.class);
    assertThat(value.getName()).isEqualTo("test");
    assertThat(value.getManagementUrl()).isEqualTo("http://test");
    assertThat(value.getHealthUrl()).isEqualTo("http://test/health");
    assertThat(value.getServiceUrl()).isNull();
}
Also used : JSONObject(org.json.JSONObject) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Aggregations

Registration (de.codecentric.boot.admin.server.domain.values.Registration)53 Test (org.junit.jupiter.api.Test)46 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)15 InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)12 ServiceInstance (org.springframework.cloud.client.ServiceInstance)9 JSONObject (org.json.JSONObject)8 DefaultServiceInstance (org.springframework.cloud.client.DefaultServiceInstance)8 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)7 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)6 Info (de.codecentric.boot.admin.server.domain.values.Info)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 StepVerifier (reactor.test.StepVerifier)6 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)5 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)5 InstanceRegistrationUpdatedEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegistrationUpdatedEvent)5 Endpoints (de.codecentric.boot.admin.server.domain.values.Endpoints)5 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Collections.singletonMap (java.util.Collections.singletonMap)4 InstanceInfo (com.netflix.appinfo.InstanceInfo)3