@Test public void deleteExisting() throws Exception { store.put("doc1", jsonNode1); mockMvc .perform(delete("/doc1")) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.message", is("Document 'doc1' was deleted."))); assertThat(store.containsKey("doc1"), is(false)); }
@DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) public JsonNode delete(@PathVariable String id) throws DocumentNotFoundException { return Optional .ofNullable(store.remove(id)) .map(x -> messageResponse(String.format("Document '%s' was deleted.", id))) .orElseThrow(documentNotFound(id)); }
RootController { @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) public JsonNode delete(@PathVariable String id) throws DocumentNotFoundException { return Optional .ofNullable(store.remove(id)) .map(x -> messageResponse(String.format("Document '%s' was deleted.", id))) .orElseThrow(documentNotFound(id)); } }
RootController { @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) public JsonNode delete(@PathVariable String id) throws DocumentNotFoundException { return Optional .ofNullable(store.remove(id)) .map(x -> messageResponse(String.format("Document '%s' was deleted.", id))) .orElseThrow(documentNotFound(id)); } @Autowired  RootController(@Value("#{store}") Map<String, JsonNode> store, PatchProcessor patchProcessor); }
RootController { @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) public JsonNode delete(@PathVariable String id) throws DocumentNotFoundException { return Optional .ofNullable(store.remove(id)) .map(x -> messageResponse(String.format("Document '%s' was deleted.", id))) .orElseThrow(documentNotFound(id)); } @Autowired  RootController(@Value("#{store}") Map<String, JsonNode> store, PatchProcessor patchProcessor); @GetMapping(path = "/", produces = APPLICATION_JSON_VALUE) Map<String, JsonNode> get(); @GetMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) JsonNode get(@PathVariable String id); @PostMapping(path = "/", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) JsonNode post(@RequestBody PatchSet patchSet); @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) JsonNode delete(@PathVariable String id); @ExceptionHandler ResponseEntity<JsonNode> handle(DocumentNotFoundException e); @ExceptionHandler ResponseEntity<JsonNode> handle(PatchApplicationException e); }
RootController { @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) public JsonNode delete(@PathVariable String id) throws DocumentNotFoundException { return Optional .ofNullable(store.remove(id)) .map(x -> messageResponse(String.format("Document '%s' was deleted.", id))) .orElseThrow(documentNotFound(id)); } @Autowired  RootController(@Value("#{store}") Map<String, JsonNode> store, PatchProcessor patchProcessor); @GetMapping(path = "/", produces = APPLICATION_JSON_VALUE) Map<String, JsonNode> get(); @GetMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) JsonNode get(@PathVariable String id); @PostMapping(path = "/", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE) JsonNode post(@RequestBody PatchSet patchSet); @DeleteMapping(path = "/{id}", produces = APPLICATION_JSON_VALUE) JsonNode delete(@PathVariable String id); @ExceptionHandler ResponseEntity<JsonNode> handle(DocumentNotFoundException e); @ExceptionHandler ResponseEntity<JsonNode> handle(PatchApplicationException e);  }