@Test public void save() throws IOException { final UserEntity user = new UserEntity(); user.setUserId(2L); user.setUsername("bob"); final SharedToUser join = new SharedToUser(); join.setUser(user); controller.save(join, 3); verify(sharedToUserService).save(Matchers.<SharedToUser>any()); }
@RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody public SharedToUser save( @RequestBody final SharedToUser sharedToUser, @PathVariable("searchId") final long searchId ) { final Long userId = sharedToUser.getUser().getUserId(); final String username = sharedToUser.getUser().getUsername(); if (userId == null) { final UserEntity userInDatabase = userEntityService.getOrCreate(username); sharedToUser.setUser(userInDatabase); } sharedToUser.setId(new SharedToUserPK(searchId, userId)); return sharedToUserService.save(sharedToUser); }
SharedToUserController { @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody public SharedToUser save( @RequestBody final SharedToUser sharedToUser, @PathVariable("searchId") final long searchId ) { final Long userId = sharedToUser.getUser().getUserId(); final String username = sharedToUser.getUser().getUsername(); if (userId == null) { final UserEntity userInDatabase = userEntityService.getOrCreate(username); sharedToUser.setUser(userInDatabase); } sharedToUser.setId(new SharedToUserPK(searchId, userId)); return sharedToUserService.save(sharedToUser); } }
SharedToUserController { @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody public SharedToUser save( @RequestBody final SharedToUser sharedToUser, @PathVariable("searchId") final long searchId ) { final Long userId = sharedToUser.getUser().getUserId(); final String username = sharedToUser.getUser().getUsername(); if (userId == null) { final UserEntity userInDatabase = userEntityService.getOrCreate(username); sharedToUser.setUser(userInDatabase); } sharedToUser.setId(new SharedToUserPK(searchId, userId)); return sharedToUserService.save(sharedToUser); } @Autowired  SharedToUserController(
            final SharedToUserService sharedToUserService,
            final SharedToUserRepository sharedToUserRepository,
            final UserEntityService userEntityService
    ); }
SharedToUserController { @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody public SharedToUser save( @RequestBody final SharedToUser sharedToUser, @PathVariable("searchId") final long searchId ) { final Long userId = sharedToUser.getUser().getUserId(); final String username = sharedToUser.getUser().getUsername(); if (userId == null) { final UserEntity userInDatabase = userEntityService.getOrCreate(username); sharedToUser.setUser(userInDatabase); } sharedToUser.setId(new SharedToUserPK(searchId, userId)); return sharedToUserService.save(sharedToUser); } @Autowired  SharedToUserController(
            final SharedToUserService sharedToUserService,
            final SharedToUserRepository sharedToUserRepository,
            final UserEntityService userEntityService
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = RequestMethod.GET) @ResponseBody Set<SharedToUser> getPermissionsForSearch(
            @PathVariable(SEARCH_ID_PARAM) final Long searchId,
            @RequestParam(value = USERNAME_PARAM, required = false) final String username
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody SharedToUser save(
            @RequestBody final SharedToUser sharedToUser,
            @PathVariable("searchId") final long searchId
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}/{userId}", method = RequestMethod.PUT) @ResponseBody SharedToUser save(
            @RequestBody final SharedToUser sharedToUser,
            @PathVariable("searchId") final long searchId,
            @PathVariable("userId") final long userId
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}/{userId}", method = RequestMethod.DELETE) @ResponseBody @ResponseStatus(HttpStatus.NO_CONTENT) void delete(
            @PathVariable("searchId") final long searchId,
            @PathVariable("userId") final long userId
    ); }
SharedToUserController { @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody public SharedToUser save( @RequestBody final SharedToUser sharedToUser, @PathVariable("searchId") final long searchId ) { final Long userId = sharedToUser.getUser().getUserId(); final String username = sharedToUser.getUser().getUsername(); if (userId == null) { final UserEntity userInDatabase = userEntityService.getOrCreate(username); sharedToUser.setUser(userInDatabase); } sharedToUser.setId(new SharedToUserPK(searchId, userId)); return sharedToUserService.save(sharedToUser); } @Autowired  SharedToUserController(
            final SharedToUserService sharedToUserService,
            final SharedToUserRepository sharedToUserRepository,
            final UserEntityService userEntityService
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = RequestMethod.GET) @ResponseBody Set<SharedToUser> getPermissionsForSearch(
            @PathVariable(SEARCH_ID_PARAM) final Long searchId,
            @RequestParam(value = USERNAME_PARAM, required = false) final String username
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}", method = {RequestMethod.PUT, RequestMethod.POST}) @ResponseBody SharedToUser save(
            @RequestBody final SharedToUser sharedToUser,
            @PathVariable("searchId") final long searchId
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}/{userId}", method = RequestMethod.PUT) @ResponseBody SharedToUser save(
            @RequestBody final SharedToUser sharedToUser,
            @PathVariable("searchId") final long searchId,
            @PathVariable("userId") final long userId
    ); @RequestMapping(value = PERMISSIONS_PATH + "/{searchId}/{userId}", method = RequestMethod.DELETE) @ResponseBody @ResponseStatus(HttpStatus.NO_CONTENT) void delete(
            @PathVariable("searchId") final long searchId,
            @PathVariable("userId") final long userId
    );  }