@Test void canHandleGenieRuntimeExceptions() { final Map<GenieRuntimeException, HttpStatus> exceptions = Maps.newHashMap(); exceptions.put(new GenieApplicationNotFoundException(), HttpStatus.NOT_FOUND); exceptions.put(new GenieClusterNotFoundException(), HttpStatus.NOT_FOUND); exceptions.put(new GenieCommandNotFoundException(), HttpStatus.NOT_FOUND); exceptions.put(new GenieJobNotFoundException(), HttpStatus.NOT_FOUND); exceptions.put(new GenieJobSpecificationNotFoundException(), HttpStatus.NOT_FOUND); exceptions.put(new GenieIdAlreadyExistsException(), HttpStatus.CONFLICT); exceptions.put(new GenieRuntimeException(), HttpStatus.INTERNAL_SERVER_ERROR); for (final Map.Entry<GenieRuntimeException, HttpStatus> exception : exceptions.entrySet()) { final ResponseEntity<GenieRuntimeException> response = this.mapper.handleGenieRuntimeException(exception.getKey()); Assertions.assertThat(response.getStatusCode()).isEqualByComparingTo(exception.getValue()); } }
@ExceptionHandler(GenieRuntimeException.class) public ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e) { this.countExceptionAndLog(e); if ( e instanceof GenieApplicationNotFoundException || e instanceof GenieCommandNotFoundException || e instanceof GenieClusterNotFoundException || e instanceof GenieJobNotFoundException || e instanceof GenieJobSpecificationNotFoundException ) { return new ResponseEntity<>(e, HttpStatus.NOT_FOUND); } else if (e instanceof GenieIdAlreadyExistsException) { return new ResponseEntity<>(e, HttpStatus.CONFLICT); } else { return new ResponseEntity<>(e, HttpStatus.INTERNAL_SERVER_ERROR); } }
GenieExceptionMapper { @ExceptionHandler(GenieRuntimeException.class) public ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e) { this.countExceptionAndLog(e); if ( e instanceof GenieApplicationNotFoundException || e instanceof GenieCommandNotFoundException || e instanceof GenieClusterNotFoundException || e instanceof GenieJobNotFoundException || e instanceof GenieJobSpecificationNotFoundException ) { return new ResponseEntity<>(e, HttpStatus.NOT_FOUND); } else if (e instanceof GenieIdAlreadyExistsException) { return new ResponseEntity<>(e, HttpStatus.CONFLICT); } else { return new ResponseEntity<>(e, HttpStatus.INTERNAL_SERVER_ERROR); } } }
GenieExceptionMapper { @ExceptionHandler(GenieRuntimeException.class) public ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e) { this.countExceptionAndLog(e); if ( e instanceof GenieApplicationNotFoundException || e instanceof GenieCommandNotFoundException || e instanceof GenieClusterNotFoundException || e instanceof GenieJobNotFoundException || e instanceof GenieJobSpecificationNotFoundException ) { return new ResponseEntity<>(e, HttpStatus.NOT_FOUND); } else if (e instanceof GenieIdAlreadyExistsException) { return new ResponseEntity<>(e, HttpStatus.CONFLICT); } else { return new ResponseEntity<>(e, HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  GenieExceptionMapper(final MeterRegistry registry); }
GenieExceptionMapper { @ExceptionHandler(GenieRuntimeException.class) public ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e) { this.countExceptionAndLog(e); if ( e instanceof GenieApplicationNotFoundException || e instanceof GenieCommandNotFoundException || e instanceof GenieClusterNotFoundException || e instanceof GenieJobNotFoundException || e instanceof GenieJobSpecificationNotFoundException ) { return new ResponseEntity<>(e, HttpStatus.NOT_FOUND); } else if (e instanceof GenieIdAlreadyExistsException) { return new ResponseEntity<>(e, HttpStatus.CONFLICT); } else { return new ResponseEntity<>(e, HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  GenieExceptionMapper(final MeterRegistry registry); @ExceptionHandler(GenieException.class) ResponseEntity<GenieException> handleGenieException(final GenieException e); @ExceptionHandler(GenieRuntimeException.class) ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e); @ExceptionHandler(GenieCheckedException.class) ResponseEntity<GenieCheckedException> handleGenieCheckedException(final GenieCheckedException e); @ExceptionHandler(ConstraintViolationException.class) ResponseEntity<GeniePreconditionException> handleConstraintViolation(
        final ConstraintViolationException cve
    ); @ExceptionHandler(MethodArgumentNotValidException.class) ResponseEntity<GeniePreconditionException> handleMethodArgumentNotValidException(
        final MethodArgumentNotValidException e
    ); }
GenieExceptionMapper { @ExceptionHandler(GenieRuntimeException.class) public ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e) { this.countExceptionAndLog(e); if ( e instanceof GenieApplicationNotFoundException || e instanceof GenieCommandNotFoundException || e instanceof GenieClusterNotFoundException || e instanceof GenieJobNotFoundException || e instanceof GenieJobSpecificationNotFoundException ) { return new ResponseEntity<>(e, HttpStatus.NOT_FOUND); } else if (e instanceof GenieIdAlreadyExistsException) { return new ResponseEntity<>(e, HttpStatus.CONFLICT); } else { return new ResponseEntity<>(e, HttpStatus.INTERNAL_SERVER_ERROR); } } @Autowired  GenieExceptionMapper(final MeterRegistry registry); @ExceptionHandler(GenieException.class) ResponseEntity<GenieException> handleGenieException(final GenieException e); @ExceptionHandler(GenieRuntimeException.class) ResponseEntity<GenieRuntimeException> handleGenieRuntimeException(final GenieRuntimeException e); @ExceptionHandler(GenieCheckedException.class) ResponseEntity<GenieCheckedException> handleGenieCheckedException(final GenieCheckedException e); @ExceptionHandler(ConstraintViolationException.class) ResponseEntity<GeniePreconditionException> handleConstraintViolation(
        final ConstraintViolationException cve
    ); @ExceptionHandler(MethodArgumentNotValidException.class) ResponseEntity<GeniePreconditionException> handleMethodArgumentNotValidException(
        final MethodArgumentNotValidException e
    );  }