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"));
}
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();
}
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();
}
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"));
}
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();
}
Aggregations