RootController { @GetMapping(path = "/", produces = APPLICATION_JSON_VALUE) public Map<String, JsonNode> get() throws JsonProcessingException { return store; } @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);  }
@Test public void getAll() throws Exception { store.put("doc1", jsonNode1); store.put("doc2", jsonNode2); mockMvc .perform(get("/")) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.doc1", is(map1))) .andExpect(jsonPath("$.doc2", is(map2))) .andReturn(); }
@Test public void getId() throws Exception { store.put("doc1", jsonNode1); mockMvc .perform(get("/doc1")) .andExpect(status().isOk()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$", is(map1))); }
@Test public void getIdNotExists() throws Exception { mockMvc .perform(get("/doc1")) .andExpect(status().isNotFound()) .andExpect(content().contentType(APPLICATION_JSON_UTF8)) .andExpect(jsonPath("$.message", is("Document 'doc1' was not found."))); }