use of io.dropwizard.health.HealthStateView in project dropwizard by dropwizard.
the class JsonHealthResponseProviderTest method shouldThrowExceptionWhenJsonProcessorExceptionOccurs.
@Test
void shouldThrowExceptionWhenJsonProcessorExceptionOccurs() throws IOException {
// given
final ObjectMapper mapperMock = mock(ObjectMapper.class);
this.jsonHealthResponseProvider = new JsonHealthResponseProvider(healthStatusChecker, healthStateAggregator, mapperMock);
final HealthStateView view = new HealthStateView("foo", true, HealthCheckType.READY, true);
final Map<String, Collection<String>> queryParams = Collections.singletonMap(JsonHealthResponseProvider.NAME_QUERY_PARAM, Collections.singleton(view.getName()));
final JsonMappingException exception = JsonMappingException.fromUnexpectedIOE(new IOException("uh oh"));
// when
when(healthStateAggregator.healthStateView(view.getName())).thenReturn(Optional.of(view));
when(mapperMock.writeValueAsString(any())).thenThrow(exception);
// then
assertThatThrownBy(() -> jsonHealthResponseProvider.healthResponse(queryParams)).isInstanceOf(RuntimeException.class).hasCauseReference(exception);
verifyNoInteractions(healthStatusChecker);
}
use of io.dropwizard.health.HealthStateView in project dropwizard by dropwizard.
the class JsonHealthResponseProviderTest method shouldHandleMultipleHealthStateViewsCorrectly.
@Test
void shouldHandleMultipleHealthStateViewsCorrectly() throws IOException {
// given
final HealthStateView fooView = new HealthStateView("foo", true, HealthCheckType.READY, true);
final HealthStateView barView = new HealthStateView("bar", true, HealthCheckType.ALIVE, true);
final HealthStateView bazView = new HealthStateView("baz", false, HealthCheckType.READY, false);
final Collection<String> names = new ArrayList<>();
names.add(fooView.getName());
names.add(barView.getName());
names.add(bazView.getName());
final Map<String, Collection<String>> queryParams = Collections.singletonMap(JsonHealthResponseProvider.NAME_QUERY_PARAM, names);
// when
when(healthStateAggregator.healthStateView(fooView.getName())).thenReturn(Optional.of(fooView));
when(healthStateAggregator.healthStateView(barView.getName())).thenReturn(Optional.of(barView));
when(healthStateAggregator.healthStateView(bazView.getName())).thenReturn(Optional.of(bazView));
when(healthStatusChecker.isHealthy(isNull())).thenReturn(true);
final HealthResponse response = jsonHealthResponseProvider.healthResponse(queryParams);
// then
assertThat(response.isHealthy()).isTrue();
assertThat(response.getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
assertThat(response.getMessage()).isEqualToIgnoringWhitespace(fixture("/json/multiple-healthy-responses.json"));
}
use of io.dropwizard.health.HealthStateView in project dropwizard by dropwizard.
the class JsonHealthResponseProviderTest method shouldHandleSingleHealthStateViewCorrectly.
@Test
void shouldHandleSingleHealthStateViewCorrectly() throws IOException {
// given
final HealthStateView view = new HealthStateView("foo", true, HealthCheckType.READY, true);
final Map<String, Collection<String>> queryParams = Collections.singletonMap(JsonHealthResponseProvider.NAME_QUERY_PARAM, Collections.singleton(view.getName()));
// when
when(healthStateAggregator.healthStateView(view.getName())).thenReturn(Optional.of(view));
when(healthStatusChecker.isHealthy(isNull())).thenReturn(true);
final HealthResponse response = jsonHealthResponseProvider.healthResponse(queryParams);
// then
assertThat(response.isHealthy()).isTrue();
assertThat(response.getContentType()).isEqualTo(MediaType.APPLICATION_JSON);
assertThat(response.getMessage()).isEqualToIgnoringWhitespace(fixture("/json/single-healthy-response.json"));
}
Aggregations