ProjectController { @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/projects/{projectId}/likes", method = RequestMethod.POST) public void likeProject(@PathVariable("projectId") String projectId, Principal principal) { projectService.likeProject(projectId, userByPrincipal(principal)); }  @Secured({Roles.ROLE_USER}) @RequestMapping(value = "/projects", method = RequestMethod.GET) @JsonView(Project.ProjectSummaryView.class) List<Project> getProjects(Authentication auth); @Secured({Roles.ROLE_USER}) @RequestMapping(value = "/project/{projectId}", method = RequestMethod.GET) Project getProject(@PathVariable String projectId, Authentication auth); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/project", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) Project addProject(@RequestBody @Valid Project project, Principal principal); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.CREATED) @RequestMapping(value = "/project/{projectId}/pledges", method = RequestMethod.POST) void pledgeProject(@PathVariable String projectId, @RequestBody @Valid Pledge pledge, Principal principal); @Secured(Roles.ROLE_ADMIN) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/project/{projectId}/status", method = RequestMethod.PATCH) Project modifyProjectStatus(@PathVariable("projectId") String projectId, @RequestBody @Valid @NotNull ProjectStatusUpdate newStatus, Principal principal); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/project/{projectId}", method = RequestMethod.PUT) Project modifyProjectMasterdata(@PathVariable("projectId") String projectId, @RequestBody @Valid @NotNull Project modifiedProject, Principal principal); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/projects/{projectId}/likes", method = RequestMethod.POST) void likeProject(@PathVariable("projectId") String projectId, Principal principal); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/projects/{projectId}/likes", method = RequestMethod.DELETE) void unlikeProject(@PathVariable("projectId") String projectId, Principal principal); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.OK) @RequestMapping(value = "/projects/{projectId}/attachments", method = RequestMethod.POST) Attachment addProjectAttachment(@PathVariable("projectId") String projectId, @RequestParam("file") MultipartFile file, Principal principal); @Secured({Roles.ROLE_TRUSTED_ANONYMOUS, Roles.ROLE_USER}) @RequestMapping(value = "/projects/{projectId}/attachments/{fileReference}", method = RequestMethod.GET) ResponseEntity<InputStreamResource> serveProjectAttachment(@PathVariable("projectId") String projectId, @PathVariable("fileReference") String fileReference); @Secured(Roles.ROLE_USER) @ResponseStatus(HttpStatus.NO_CONTENT) @RequestMapping(value = "/projects/{projectId}/attachments/{fileReference}", method = RequestMethod.DELETE) void deleteProjectAttachment(@PathVariable("projectId") String projectId, @PathVariable("fileReference") String fileReference, Principal principal);  }
@Test public void likeProject_shouldCallLikeMethodFromService() throws Exception { final String email = "some@mail.com"; final UserEntity user = userEntity(email, Roles.ROLE_USER, Roles.ROLE_ADMIN); mockMvc.perform(post("/projects/{projectId}/likes", "some_id") .principal(authentication(user)) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()); verify(projectService, only()).likeProject(eq("some_id"), any(UserEntity.class)); }