SchemaController { @ApiOperation(value = "Adds a new schema to a road") @ApiResponses({ @ApiResponse(code = 200, message = "Request to add a new schema received.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class), @ApiResponse(code = 409, message = "Schema is not compatible with previous schemas.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PostMapping public StandardResponse addNewSchema( @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name, @RequestBody Schema schema) throws UnknownRoadException, InvalidKeyPathException { service.addSchema(name, schema); return StandardResponse.successResponse("Request to add a new schema received."); }  @ApiOperation(value = "Returns all schemas keyed by version number") @ApiResponses({ @ApiResponse(code = 200, message = "List of schemas returned successfully.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class) }) @GetMapping Map<Integer, Schema> getSchemas(@PathVariable String name); @ApiOperation(value = "Adds a new schema to a road") @ApiResponses({ @ApiResponse(code = 200, message = "Request to add a new schema received.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class), @ApiResponse(code = 409, message = "Schema is not compatible with previous schemas.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PostMapping StandardResponse addNewSchema(
      @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name,
      @RequestBody Schema schema); @ApiOperation(value = "Adds a new schema with a specific version to a road") @ApiResponses({ @ApiResponse(code = 200, message = "Request to add a new schema received.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid Schema Version. The requested version must be greater than the largest registered version.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road not found.", response = StandardResponse.class), @ApiResponse(code = 409, message = "Schema is not compatible with previous schemas.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @PostMapping("/{version}") StandardResponse addNewSchema(
      @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name,
      @PathVariable int version,
      @RequestBody Schema schema); @ApiOperation(value = "Returns a specific version of a schema") @ApiResponses({ @ApiResponse(code = 200, message = "Requested schema returned successfully.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or schema not found.", response = StandardResponse.class) }) @GetMapping("/{version}") Schema getSchema(
      @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name,
      @PathVariable String version); @ApiOperation(value = "Deletes the latest version of a schema") @ApiResponses({ @ApiResponse(code = 200, message = "Request to delete a schema received.", response = StandardResponse.class), @ApiResponse(code = 400, message = "Invalid Schema Version. Only the latest schema can be deleted.", response = StandardResponse.class), @ApiResponse(code = 404, message = "Road or Schema not found.", response = StandardResponse.class) }) @PreAuthorize("@paverAuthorisation.isAuthorised(authentication)") @DeleteMapping("/{version}") ResponseEntity<StandardResponse> deleteLatestSchema(
      @ApiParam(name = "name", value = "road name", required = true) @PathVariable String name,
      @PathVariable String version); @ExceptionHandler(AvroTypeException.class) ResponseEntity<StandardResponse> avroTypeExceptionExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(SchemaParseException.class) ResponseEntity<StandardResponse> schemaParseException(HttpServletRequest request, Exception e); @ExceptionHandler(NumberFormatException.class) ResponseEntity<StandardResponse> numberFormatExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(InvalidSchemaException.class) ResponseEntity<StandardResponse> invalidSchemaExceptionHandler(HttpServletRequest request, Exception e); @ExceptionHandler(InvalidSchemaVersionException.class) ResponseEntity<StandardResponse> invalidSchemaVersionException(HttpServletRequest request, Exception e); @ExceptionHandler(InvalidPiiAnnotationException.class) ResponseEntity<StandardResponse> invalidPiiAnnotationException(HttpServletRequest request, Exception e);  }
@Test public void addNewSchema() throws Exception { SchemaVersion schemaVersion = new SchemaVersion(schema, 1, false); when(paverService.addSchema(ROAD_NAME, schema)).thenReturn(schemaVersion); when(paverService.getRoad(ROAD_NAME)).thenReturn(road); mockMvc .perform(post(CONTEXT_PATH + "/roads/road1/schemas").contentType(APPLICATION_JSON_UTF8).content(schemaJson)) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.success", is(true))) .andExpect(jsonPath("$.message", is("Request to add a new schema received."))); verify(paverService).addSchema(ROAD_NAME, schema); }