Search in sources :

Example 6 with InstanceId

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

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

the class InstanceRegisteredEventMixinTest method verifySerializeWithoutRegistration.

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

Example 8 with InstanceId

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

the class InstanceStatusChangedEventMixinTest method verifySerializeWithoutStatusInfo.

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

Example 9 with InstanceId

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

the class InstanceStatusChangedEventMixinTest method verifySerialize.

@Test
public void verifySerialize() throws IOException {
    InstanceId id = InstanceId.of("test123");
    Instant timestamp = Instant.ofEpochSecond(1587751031).truncatedTo(ChronoUnit.SECONDS);
    StatusInfo statusInfo = StatusInfo.valueOf("OFFLINE", Collections.singletonMap("foo", "bar"));
    InstanceStatusChangedEvent event = new InstanceStatusChangedEvent(id, 12345678L, timestamp, statusInfo);
    JsonContent<InstanceStatusChangedEvent> 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("STATUS_CHANGED");
    assertThat(jsonContent).extractingJsonPathValue("$.statusInfo").isNotNull();
    assertThat(jsonContent).extractingJsonPathStringValue("$.statusInfo.status").isEqualTo("OFFLINE");
    assertThat(jsonContent).extractingJsonPathMapValue("$.statusInfo.details").containsOnly(entry("foo", "bar"));
}
Also used : InstanceId(de.codecentric.boot.admin.server.domain.values.InstanceId) StatusInfo(de.codecentric.boot.admin.server.domain.values.StatusInfo) Instant(java.time.Instant) InstanceStatusChangedEvent(de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent) Test(org.junit.jupiter.api.Test)

Example 10 with InstanceId

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

InstanceId (de.codecentric.boot.admin.server.domain.values.InstanceId)32 Test (org.junit.jupiter.api.Test)28 Instant (java.time.Instant)18 Registration (de.codecentric.boot.admin.server.domain.values.Registration)13 StatusInfo (de.codecentric.boot.admin.server.domain.values.StatusInfo)8 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 StepVerifier (reactor.test.StepVerifier)7 Instance (de.codecentric.boot.admin.server.domain.entities.Instance)6 ArrayList (java.util.ArrayList)6 Mono (reactor.core.publisher.Mono)6 InstanceRepository (de.codecentric.boot.admin.server.domain.entities.InstanceRepository)5 BeforeEach (org.junit.jupiter.api.BeforeEach)5 Flux (reactor.core.publisher.Flux)5 EventsourcingInstanceRepository (de.codecentric.boot.admin.server.domain.entities.EventsourcingInstanceRepository)4 InstanceRegisteredEvent (de.codecentric.boot.admin.server.domain.events.InstanceRegisteredEvent)4 InstanceStatusChangedEvent (de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent)4 Info (de.codecentric.boot.admin.server.domain.values.Info)4 InMemoryEventStore (de.codecentric.boot.admin.server.eventstore.InMemoryEventStore)4 Collections.singletonMap (java.util.Collections.singletonMap)4 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)4