RoadController { @ApiOperation(value = "Returns the details of a road") @ApiResponses({ @ApiResponse(code = 200, message = "Details of a road returned successfully.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid request or road name.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class) }) @GetMapping("/{name}") public RoadModel getRoad(@ApiParam(name = "name", value = "road name", required = true) @PathVariable String name) throws UnknownRoadException { return service.getRoad(name); }  @ApiOperation(value = "Lists all road names") // The array of api responses is required. Without it, documentation is not generated correctly in paths.md file. @ApiResponses({ @ApiResponse(code = 200, message = "List of all road names", response = StandardResponse.class) }) @GetMapping SortedSet<String> listRoads(HttpServletRequest req); @ApiOperation(value = "Creates a new road") @ApiResponses({ @ApiResponse(code = 200, message = "Request to create a road received.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid request or road name.", response = StandardResponse.class), @ApiResponse(code = 415, message = "Unsupported media type. Only 'application/json' content type is supported.", response = StandardResponse.class), @ApiResponse(code = 409, message = "Road already exists.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PostMapping StandardResponse createRoad(@RequestBody BasicRoadModel road); @ApiOperation(value = "Returns the details of a road") @ApiResponses({ @ApiResponse(code = 200, message = "Details of a road returned successfully.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid request or road name.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class) }) @GetMapping("/{name}") RoadModel getRoad(@ApiParam(name = "name", value = "road name", required = true) @PathVariable String name); @ApiOperation(value = "Applies JSON Patch modifications to a road") @ApiResponses({ @ApiResponse(code = 200, message = "Patch applied successfully", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid patch", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @RequestMapping(value = "/{name}", method = { RequestMethod.PATCH, RequestMethod.PUT }, consumes = "application/json-patch+json") StandardResponse patchRoad(
      @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name,
      @RequestBody List<PatchOperation> patchSet); @ApiOperation(value = "Deletes a road") @ApiResponses({ @ApiResponse(code = 200, message = "Delete a road returned successfully.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid request or road name.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @DeleteMapping("/{name}") StandardResponse delete(@ApiParam(name = "name", value = "road name", required = true) @PathVariable String name);  }
@Test public void getRoad() throws Exception { when(paverService.getRoad(NAME)).thenReturn(road); mockMvc .perform(get(CONTEXT_PATH + "/roads/road1")) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.name", is(NAME))); }
@Test public void getRoad_RoadDoesNotExist() throws Exception { doThrow(new UnknownRoadException("road1")).when(paverService).getRoad(NAME); mockMvc .perform(get(CONTEXT_PATH + "/roads/road1")) .andExpect(status().isNotFound()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.message", is("Road \"road1\" does not exist."))); }
@Test public void updateRoad() throws Exception { when(paverService.getRoad(NAME)).thenReturn(road); String patchJson = mapper.writeValueAsString(singletonList(PatchOperation.replace("/enabled", Boolean.TRUE))); mockMvc .perform(patch(CONTEXT_PATH + "/roads/road1").contentType("application/json-patch+json").content(patchJson)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(content().json("{\"success\":true}")); verify(paverService).applyPatch(NAME, singletonList(PatchOperation.replace("/enabled", Boolean.TRUE))); }