Status provides convenient constants for commonly used states like {@link #UP}, {@link #DOWN} or {@link #OUT_OF_SERVICE}.
Custom states can also be created and used throughout the Spring Boot Health subsystem. @author Christian Dupuis @since 1.1.0
105106107108109110111112113114115116
// Shouldn't happen because the request mapping should not be registered return new ResponseEntity<Map<String, String>>(Collections.singletonMap( "message", "This endpoint is disabled"), HttpStatus.NOT_FOUND); } Health health = getHealth(principal); Status status = health.getStatus(); if (this.statusMapping.containsKey(status.getCode())) { return new ResponseEntity<Health>(health, this.statusMapping.get(status .getCode())); } return health; }
8384858687888990
this.mvc.setStatusMapping(Collections.singletonMap("OK", HttpStatus.INTERNAL_SERVER_ERROR)); Object result = this.mvc.invoke(null); assertTrue(result instanceof ResponseEntity); ResponseEntity<Health> response = (ResponseEntity<Health>) result; assertTrue(response.getBody().getStatus().equals(new Status("OK"))); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); }