Search in sources :

Example 16 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_5_json_format.

@Test
public void test_1_5_json_format() throws Exception {
    String json = new JSONObject().put("name", "test").put("managementUrl", "http://test").put("healthUrl", "http://health").put("serviceUrl", "http://service").put("metadata", new JSONObject().put("labels", "foo,bar")).toString();
    Registration value = objectMapper.readValue(json, Registration.class);
    assertThat(value.getName()).isEqualTo("test");
    assertThat(value.getManagementUrl()).isEqualTo("http://test");
    assertThat(value.getHealthUrl()).isEqualTo("http://health");
    assertThat(value.getServiceUrl()).isEqualTo("http://service");
    assertThat(value.getMetadata()).isEqualTo(singletonMap("labels", "foo,bar"));
}
Also used : JSONObject(org.json.JSONObject) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 17 with Registration

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

the class RegistrationDeserializerTest method test_onlyHealthUrl.

@Test
public void test_onlyHealthUrl() throws Exception {
    String json = new JSONObject().put("name", "test").put("healthUrl", "http://test").toString();
    Registration value = objectMapper.readValue(json, Registration.class);
    assertThat(value.getName()).isEqualTo("test");
    assertThat(value.getHealthUrl()).isEqualTo("http://test");
    assertThat(value.getManagementUrl()).isNull();
    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)

Example 18 with Registration

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

the class InstanceRegisteredEventMixinTest 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", "REGISTERED").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();
    InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.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) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 19 with Registration

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

the class InstanceRegisteredEventMixinTest method verifyDeserializeWithOnlyRequiredProperties.

@Test
public void verifyDeserializeWithOnlyRequiredProperties() throws JSONException, JsonProcessingException {
    String json = new JSONObject().put("instance", "test123").put("timestamp", 1587751031.000000000).put("type", "REGISTERED").put("registration", new JSONObject().put("name", "test").put("healthUrl", "http://localhost:9080/heath")).toString();
    InstanceRegisteredEvent event = objectMapper.readValue(json, InstanceRegisteredEvent.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) InstanceRegisteredEvent(de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Test(org.junit.jupiter.api.Test)

Example 20 with Registration

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

the class InstanceRegistryTest method refresh.

@Test
public void refresh() {
    // Given instance is already reegistered and has status and info.
    StatusInfo status = StatusInfo.ofUp();
    Info info = Info.from(singletonMap("foo", "bar"));
    Registration registration = Registration.create("abc", "http://localhost:8080/health").build();
    InstanceId id = idGenerator.generateId(registration);
    Instance app = Instance.create(id).register(registration).withStatusInfo(status).withInfo(info);
    StepVerifier.create(repository.save(app)).expectNextCount(1).verifyComplete();
    // When instance registers second time
    InstanceId refreshId = registry.register(Registration.create("abc", "http://localhost:8080/health").build()).block();
    assertThat(refreshId).isEqualTo(id);
    StepVerifier.create(registry.getInstance(id)).assertNext((registered) -> {
        // Then info and status are retained
        assertThat(registered.getInfo()).isEqualTo(info);
        assertThat(registered.getStatusInfo()).isEqualTo(status);
    }).verifyComplete();
}
Also used : Registration(de.codecentric.boot.admin.server.domain.values.Registration) BeforeEach(org.junit.jupiter.api.BeforeEach) StepVerifier(reactor.test.StepVerifier) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Info(de.codecentric.boot.admin.server.domain.values.Info) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) EventsourcingInstanceRepository(de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Collections.singletonMap(java.util.Collections.singletonMap) InMemoryEventStore(de.codecentric.boot.admin.server.eventstore.InMemoryEventStore) InstanceRepository(de.codecentric.boot.admin.server.domain.entities.InstanceRepository) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) Instance(de.codecentric.boot.admin.server.domain.entities.Instance) Registration(de.codecentric.boot.admin.server.domain.values.Registration) Info(de.codecentric.boot.admin.server.domain.values.Info) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) 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