/** * Create a copy of this StatusDetail, updates the message, changes the status to OK, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toOk(final String message) { return statusDetail(name, OK, message, details); }
/** * Create a copy of this StatusDetail, updates the message, changes the status to WARNING, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toWarning(final String message) { return statusDetail(name, WARNING, message, details); }
/** * Create a copy of this StatusDetail, updates the message, changes the status to WARNING, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toWarning(final String message) { return statusDetail(name, WARNING, message, details); }
/** * Create a copy of this StatusDetail, updates the message, changes the status to ERROR, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toError(final String message) { return statusDetail(name, ERROR, message, details); }
/** * Create a copy of this StatusDetail, updates the message, changes the status to OK, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toOk(final String message) { return statusDetail(name, OK, message, details); }
/** * Create a copy of this StatusDetail, updates the message, changes the status to ERROR, * and return the new StatusDetail. * * @param message the new message * @return StatusDetail */ public StatusDetail toError(final String message) { return statusDetail(name, ERROR, message, details); }
/** * Create a copy of this StatusDetail, add a detail and return the new StatusDetail. * * @param key the key of the additional detail * @param value the value of the additional detail * @return StatusDetail */ public StatusDetail withDetail(final String key, final String value) { final LinkedHashMap<String, String> newDetails = new LinkedHashMap<>(details); newDetails.put(key, value); return statusDetail(name,status,message, newDetails); }
/** * Create a copy of this StatusDetail, add a detail and return the new StatusDetail. * * @param key the key of the additional detail * @param value the value of the additional detail * @return StatusDetail */ public StatusDetail withDetail(final String key, final String value) { final LinkedHashMap<String, String> newDetails = new LinkedHashMap<>(details); newDetails.put(key, value); return statusDetail(name,status,message, newDetails); }
/** * Create a copy of this StatusDetail, remove a detail and return the new StatusDetail. * * @param key the key of the additional detail * @return StatusDetail */ public StatusDetail withoutDetail(final String key) { final LinkedHashMap<String, String> newDetails = new LinkedHashMap<>(details); newDetails.remove(key); return statusDetail(name,status,message, newDetails); }
/** * Create a copy of this StatusDetail, remove a detail and return the new StatusDetail. * * @param key the key of the additional detail * @return StatusDetail */ public StatusDetail withoutDetail(final String key) { final LinkedHashMap<String, String> newDetails = new LinkedHashMap<>(details); newDetails.remove(key); return statusDetail(name,status,message, newDetails); }
@Test public void shouldHaveStatusErrorIfDetailsContainWarnings() { // given final ApplicationStatus applicationStatus = applicationStatus(mock(ApplicationInfo.class), null, mock(SystemInfo.class), mock(VersionInfo.class), mock(TeamInfo.class), asList( statusDetail("bar", OK, "a message"), statusDetail("foobar", ERROR, "another message"), statusDetail("foobar", WARNING, "yet another message")) ); // then assertThat(applicationStatus.status, is(ERROR)); }
@Test public void shouldHaveStatusWarningIfDetailsContainWarnings() { // given final ApplicationStatus applicationStatus = applicationStatus(mock(ApplicationInfo.class), null, mock(SystemInfo.class), mock(VersionInfo.class), mock(TeamInfo.class), asList( statusDetail("bar", OK, "a message"), statusDetail("foobar", WARNING, "another message")) ); // then assertThat(applicationStatus.status, is(WARNING)); }
@Test public void shouldAggregateStatusDetails() { final StatusDetailIndicator first = new MutableStatusDetailIndicator(statusDetail("firstIndicator", OK, "a message")); final StatusDetailIndicator second = new MutableStatusDetailIndicator(statusDetail("secondIndicator", ERROR, "a message")); final CompositeStatusDetailIndicator composite = new CompositeStatusDetailIndicator(asList(first, second)); assertThat(composite.statusDetails().get(0), is(statusDetail("firstIndicator", OK, "a message"))); assertThat(composite.statusDetails().get(1), is(statusDetail("secondIndicator", ERROR, "a message"))); }
@Test public void shouldHaveStatusOkIfDetailsAreOk() { // given final ApplicationStatus applicationStatus = applicationStatus(mock(ApplicationInfo.class), null, mock(SystemInfo.class), mock(VersionInfo.class), mock(TeamInfo.class), singletonList( statusDetail("bar", OK, "a message")) ); // then assertThat(applicationStatus.status, is(OK)); }
@Test public void shouldReturnStatusDetailOfSingleIndicator() { final StatusDetailIndicator indicator = new MutableStatusDetailIndicator(statusDetail("bar", ERROR, "a message")); final CompositeStatusDetailIndicator composite = new CompositeStatusDetailIndicator(asList(indicator)); final StatusDetail statusDetail = composite.statusDetails().get(0); assertThat(statusDetail, is(statusDetail("bar", ERROR, "a message"))); }
@Test public void shouldHaveAdditionalAttributes() { // given final StatusDetail statusDetail = statusDetail("foo", ERROR, "message", singletonMap("foo", "bar")); // when final Map<String,String> theMap = statusDetail.getDetails(); // then assertThat(theMap, hasEntry("foo", "bar")); }
@Test public void shouldFailToUpdateStatusWithDifferentName() { // given final MutableStatusDetailIndicator indicator = new MutableStatusDetailIndicator(statusDetail("foo", OK, "message")); // when / then assertThrows(IllegalArgumentException.class, () -> { indicator.update(statusDetail("bar", OK, "message")); }); } }
@Test public void shouldResultInOk() { // given StatusDetail statusDetail = statusDetail("foo", WARNING, "message", singletonMap("foo", "bar")); // when statusDetail = statusDetail.toOk("different message"); // then assertThat(statusDetail.getName(), is("foo")); assertThat(statusDetail.getMessage(), is("different message")); assertThat(statusDetail.getStatus(), is(OK)); assertThat(statusDetail.getDetails(), hasEntry("foo", "bar")); }
@Test public void shouldRemoveDetail() { // given StatusDetail statusDetail = statusDetail("foo", WARNING, "message", singletonMap("foo", "bar")); // when statusDetail = statusDetail.withoutDetail("foo"); // then assertThat(statusDetail.getName(), is("foo")); assertThat(statusDetail.getMessage(), is("message")); assertThat(statusDetail.getStatus(), is(WARNING)); assertThat(statusDetail.getDetails(), not(hasEntry("foo", "bar"))); }
@Test public void shouldOverwriteDetail() { // given StatusDetail statusDetail = statusDetail("foo", WARNING, "message", singletonMap("foo", "bar")); // when statusDetail = statusDetail.withDetail("foo","baz"); // then assertThat(statusDetail.getName(), is("foo")); assertThat(statusDetail.getMessage(), is("message")); assertThat(statusDetail.getStatus(), is(WARNING)); assertThat(statusDetail.getDetails(), hasEntry("foo", "baz")); }