@Test public void createRoad() throws Exception { String roadJson = mapper.writeValueAsString(road); mockMvc .perform(post(CONTEXT_PATH + "/roads").contentType(APPLICATION_JSON_UTF8).content(roadJson)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(content().json("{\"success\":true}")); verify(paverService).createRoad( new BasicRoadModel(road.getName(), road.getDescription(), road.getTeamName(), road.getContactEmail(), road.isEnabled(), road.getPartitionPath(), road.getAuthorisation(), road.getMetadata())); }
@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 public StandardResponse createRoad(@RequestBody BasicRoadModel road) { service.createRoad(road); return StandardResponse.successResponse(String.format("Request to create road \"%s\" received", road.getName())); }
RoadController { @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 public StandardResponse createRoad(@RequestBody BasicRoadModel road) { service.createRoad(road); return StandardResponse.successResponse(String.format("Request to create road \"%s\" received", road.getName())); } }
RoadController { @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 public StandardResponse createRoad(@RequestBody BasicRoadModel road) { service.createRoad(road); return StandardResponse.successResponse(String.format("Request to create road \"%s\" received", road.getName())); }  }
RoadController { @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 public StandardResponse createRoad(@RequestBody BasicRoadModel road) { service.createRoad(road); return StandardResponse.successResponse(String.format("Request to create road \"%s\" received", road.getName())); }  @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); }
RoadController { @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 public StandardResponse createRoad(@RequestBody BasicRoadModel road) { service.createRoad(road); return StandardResponse.successResponse(String.format("Request to create road \"%s\" received", road.getName())); }  @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);  }