use of de.codecentric.boot.admin.server.domain.values.Info in project spring-boot-admin by codecentric.
the class InfoMixinTest method verifySerialize.
@Test
public void verifySerialize() throws IOException {
Map<String, Object> data = new HashMap<>();
data.put("build", Collections.singletonMap("version", "1.0.0"));
data.put("foo", "bar");
Info info = Info.from(data);
JsonContent<Info> jsonContent = jsonTester.write(info);
assertThat(jsonContent).extractingJsonPathMapValue("$").containsOnlyKeys("build", "foo");
assertThat(jsonContent).extractingJsonPathStringValue("$['build'].['version']").isEqualTo("1.0.0");
assertThat(jsonContent).extractingJsonPathStringValue("$['foo']").isEqualTo("bar");
}
use of de.codecentric.boot.admin.server.domain.values.Info in project spring-boot-admin by codecentric.
the class InfoUpdaterTest method should_clear_info_on_exception.
@Test
public void should_clear_info_on_exception() {
this.updater = new InfoUpdater(this.repository, InstanceWebClient.builder().build());
// given
Instance instance = Instance.create(InstanceId.of("onl")).register(Registration.create("foo", this.wireMock.url("/health")).build()).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp()).withInfo(Info.from(singletonMap("foo", "bar")));
StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
this.wireMock.stubFor(get("/info").willReturn(okJson("{ \"foo\": \"bar\" }").withFixedDelay(1500)));
// when
StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.empty())).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.values.Info in project spring-boot-admin by codecentric.
the class InfoUpdaterTest method should_clear_info_on_http_error.
@Test
public void should_clear_info_on_http_error() {
// given
Instance instance = Instance.create(InstanceId.of("onl")).register(Registration.create("foo", this.wireMock.url("/health")).build()).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp()).withInfo(Info.from(singletonMap("foo", "bar")));
StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
this.wireMock.stubFor(get("/info").willReturn(serverError()));
// when
StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.empty())).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.values.Info in project spring-boot-admin by codecentric.
the class InfoUpdaterTest method should_update_info_for_online_with_info_endpoint_only.
@Test
public void should_update_info_for_online_with_info_endpoint_only() {
// given
Registration registration = Registration.create("foo", this.wireMock.url("/health")).build();
Instance instance = Instance.create(InstanceId.of("onl")).register(registration).withEndpoints(Endpoints.single("info", this.wireMock.url("/info"))).withStatusInfo(StatusInfo.ofUp());
StepVerifier.create(this.repository.save(instance)).expectNextCount(1).verifyComplete();
String body = "{ \"foo\": \"bar\" }";
this.wireMock.stubFor(get("/info").willReturn(okJson(body).withHeader("Content-Length", Integer.toString(body.length()))));
Instance noInfo = Instance.create(InstanceId.of("noinfo")).register(registration).withEndpoints(Endpoints.single("beans", this.wireMock.url("/beans"))).withStatusInfo(StatusInfo.ofUp());
StepVerifier.create(this.repository.save(noInfo)).expectNextCount(1).verifyComplete();
Instance offline = Instance.create(InstanceId.of("off")).register(registration).withStatusInfo(StatusInfo.ofOffline());
StepVerifier.create(this.repository.save(offline)).expectNextCount(1).verifyComplete();
Instance unknown = Instance.create(InstanceId.of("unk")).register(registration).withStatusInfo(StatusInfo.ofUnknown());
StepVerifier.create(this.repository.save(unknown)).expectNextCount(1).verifyComplete();
// when
StepVerifier.create(this.eventStore).expectSubscription().then(() -> StepVerifier.create(this.updater.updateInfo(offline.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(unknown.getId())).verifyComplete()).then(() -> StepVerifier.create(this.updater.updateInfo(noInfo.getId())).verifyComplete()).expectNoEvent(Duration.ofMillis(100L)).then(() -> StepVerifier.create(this.updater.updateInfo(instance.getId())).verifyComplete()).assertNext((event) -> assertThat(event).isInstanceOf(InstanceInfoChangedEvent.class)).thenCancel().verify();
StepVerifier.create(this.repository.find(instance.getId())).assertNext((app) -> assertThat(app.getInfo()).isEqualTo(Info.from(singletonMap("foo", "bar")))).verifyComplete();
}
use of de.codecentric.boot.admin.server.domain.values.Info in project spring-boot-admin by codecentric.
the class InstanceInfoChangedEventMixinTest method verifyDeserializeWithEmptyInfo.
@Test
public void verifyDeserializeWithEmptyInfo() throws JSONException, JsonProcessingException {
String json = new JSONObject().put("instance", "test123").put("version", 12345678L).put("timestamp", 1587751031.000000000).put("type", "INFO_CHANGED").put("info", new JSONObject()).toString();
InstanceInfoChangedEvent event = objectMapper.readValue(json, InstanceInfoChangedEvent.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));
Info info = event.getInfo();
assertThat(info).isNotNull();
assertThat(info.getValues()).isEmpty();
}
Aggregations