HiveDestinationController { @ApiOperation(value = "Deletes an existing Hive destination") @ApiResponses({ @ApiResponse(code = 200, message = "Deletion of existing Hive destination requested.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or Hive destination not found.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @DeleteMapping public StandardResponse delete(@PathVariable String name) throws UnknownRoadException, UnknownDestinationException { hiveDestinationService.deleteHiveDestination(name); return StandardResponse .successResponse(String.format("Request to delete Hive destination for \"%s\" received.", name)); }  @ApiOperation(value = "Returns details of a Hive destination") @ApiResponses({ @ApiResponse(code = 200, message = "Details of a Hive destination.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or Hive destination not found.", response = StandardResponse.class) }) @GetMapping HiveDestinationModel get(@PathVariable String name); @ApiOperation(value = "Creates a new Hive destination") @ApiResponses({ @ApiResponse(code = 200, message = "Creation of a new Hive destination requested.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class), @ApiResponse(code = 409, message = "Hive destination already exists.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PostMapping StandardResponse post(@PathVariable String name, @RequestBody HiveDestinationModel hiveDestinationModel); @ApiOperation(value = "Updates an existing Hive destination") @ApiResponses({ @ApiResponse(code = 200, message = "Update of existing Hive destination requested.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or Hive destination not found.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PutMapping StandardResponse put(@PathVariable String name, @RequestBody HiveDestinationModel hiveDestinationModel); @ApiOperation(value = "Deletes an existing Hive destination") @ApiResponses({ @ApiResponse(code = 200, message = "Deletion of existing Hive destination requested.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or Hive destination not found.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @DeleteMapping StandardResponse delete(@PathVariable String name); @ExceptionHandler(UnknownRoadException.class) ResponseEntity<StandardResponse> unknownRoadExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(UnknownDestinationException.class) ResponseEntity<StandardResponse> unknownDestinationExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(AlreadyExistsException.class) ResponseEntity<StandardResponse> alreadyExistsExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(IllegalArgumentException.class) ResponseEntity<StandardResponse> illegalArgumentExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(InvalidLandingIntervalException.class) ResponseEntity<StandardResponse> invalidLandingIntervalExceptionHandler(
      HttpServletRequest request,
      Exception e);  }
@Test public void delete_UnknownRoad() throws Exception { doThrow(new UnknownRoadException(NAME)).when(service).deleteHiveDestination(NAME); mockMvc .perform(delete(HIVE_DESTINATION_ENDPOINT).contentType(APPLICATION_JSON_UTF8).content(DESTINATION_JSON)) .andExpect(status().isNotFound()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.timestamp", isA(Long.TYPE))) .andExpect(jsonPath("$.success", is(false))) .andExpect(jsonPath("$.message", is("Road \"road1\" does not exist."))); }
@Test public void delete_UnknownDestination() throws Exception { doThrow(new UnknownDestinationException("Hive", NAME)).when(service).deleteHiveDestination(NAME); mockMvc .perform(delete(HIVE_DESTINATION_ENDPOINT).contentType(APPLICATION_JSON_UTF8).content(DESTINATION_JSON)) .andExpect(status().isNotFound()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.timestamp", isA(Long.TYPE))) .andExpect(jsonPath("$.success", is(false))) .andExpect(jsonPath("$.message", is("Hive destination for Road \"road1\" does not exist."))); }
@Test public void delete_Ok() throws Exception { mockMvc .perform(delete(HIVE_DESTINATION_ENDPOINT).contentType(APPLICATION_JSON_UTF8).content(DESTINATION_JSON)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.timestamp", isA(Long.TYPE))) .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.message", is("Request to delete Hive destination for \"road1\" received."))); verify(service).deleteHiveDestination(NAME); }