@Test public void addABookmarkFailsBecauseDescriptionIsNull() throws Exception { Bookmark value = new Bookmark(null, "http: mvc.perform( post("/bookmarks") .contentType(MediaType.APPLICATION_JSON_UTF8) .content(mapper.writeValueAsString(value)) .with(csrf()) ).andDo(print()) .andExpect(status().isBadRequest()) .andExpect(jsonPath("$[0].field").value("description")); Mockito.verify(bookmarkService, never()).addBookmark(Mockito.any(Bookmark.class)); }
@PostMapping @PreAuthorize("hasRole('ADMIN')") public ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark){ UUID uuid = bookmarkService.addBookmark(bookmark); return ResponseEntity.created( BasicLinkBuilder.linkToCurrentMapping() .slash("bookmark") .slash(uuid) .toUri()) .build(); }
BookmarksController { @PostMapping @PreAuthorize("hasRole('ADMIN')") public ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark){ UUID uuid = bookmarkService.addBookmark(bookmark); return ResponseEntity.created( BasicLinkBuilder.linkToCurrentMapping() .slash("bookmark") .slash(uuid) .toUri()) .build(); } }
BookmarksController { @PostMapping @PreAuthorize("hasRole('ADMIN')") public ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark){ UUID uuid = bookmarkService.addBookmark(bookmark); return ResponseEntity.created( BasicLinkBuilder.linkToCurrentMapping() .slash("bookmark") .slash(uuid) .toUri()) .build(); }  }
BookmarksController { @PostMapping @PreAuthorize("hasRole('ADMIN')") public ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark){ UUID uuid = bookmarkService.addBookmark(bookmark); return ResponseEntity.created( BasicLinkBuilder.linkToCurrentMapping() .slash("bookmark") .slash(uuid) .toUri()) .build(); }  @PostMapping @PreAuthorize("hasRole('ADMIN')") ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark); @GetMapping Resources<Resource<Bookmark>> findAllBookmarks(HttpServletRequest request); }
BookmarksController { @PostMapping @PreAuthorize("hasRole('ADMIN')") public ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark){ UUID uuid = bookmarkService.addBookmark(bookmark); return ResponseEntity.created( BasicLinkBuilder.linkToCurrentMapping() .slash("bookmark") .slash(uuid) .toUri()) .build(); }  @PostMapping @PreAuthorize("hasRole('ADMIN')") ResponseEntity<Void> addBookmark(@RequestBody @Valid Bookmark bookmark); @GetMapping Resources<Resource<Bookmark>> findAllBookmarks(HttpServletRequest request);  }