UserController extends AbstractCrudController<User> { protected void updateUserGroups( String pvUid, User parsed, User currentUser ) { User user = userService.getUser( pvUid ); if ( currentUser != null && currentUser.getId() == user.getId() ) { currentUser = currentUserService.getCurrentUser(); } userGroupService.updateUserGroups( user, IdentifiableObjectUtils.getUids( parsed.getGroups() ), currentUser ); }  @Override @RequestMapping( method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) void postXmlObject( HttpServletRequest request, HttpServletResponse response ); @Override @RequestMapping( method = RequestMethod.POST, consumes = "application/json" ) void postJsonObject( HttpServletRequest request, HttpServletResponse response ); @RequestMapping( value = INVITE_PATH, method = RequestMethod.POST, consumes = "application/json" ) void postJsonInvite( HttpServletRequest request, HttpServletResponse response ); @RequestMapping( value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = "application/json" ) @ResponseStatus( HttpStatus.NO_CONTENT ) void postJsonInvites( HttpServletRequest request, HttpServletResponse response ); @RequestMapping( value = INVITE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) void postXmlInvite( HttpServletRequest request, HttpServletResponse response ); @RequestMapping( value = BULK_INVITE_PATH, method = RequestMethod.POST, consumes = { "application/xml", "text/xml" } ) @ResponseStatus( HttpStatus.NO_CONTENT ) void postXmlInvites( HttpServletRequest request, HttpServletResponse response ); @RequestMapping( value = "/{id}" + INVITE_PATH, method = RequestMethod.POST ) @ResponseStatus( HttpStatus.NO_CONTENT ) void resendInvite( @PathVariable String id, HttpServletRequest request ); @SuppressWarnings( "unchecked" ) @PreAuthorize( "hasRole('ALL') or hasRole('F_REPLICATE_USER')" ) @RequestMapping( value = "/{uid}/replica", method = RequestMethod.POST ) void replicateUser( @PathVariable String uid,
        HttpServletRequest request, HttpServletResponse response ); @RequestMapping(value = "/{uid}/enabled", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) void enableUser( @PathVariable("uid") String uid ); @RequestMapping(value = "/{uid}/disabled", method = RequestMethod.POST) @ResponseStatus(value = HttpStatus.NO_CONTENT) void disableUser( @PathVariable("uid") String uid ); @Override @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" } ) void putXmlObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ); @Override @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" ) void putJsonObject( @PathVariable( "uid" ) String pvUid, HttpServletRequest request, HttpServletResponse response ); static final String INVITE_PATH; static final String BULK_INVITE_PATH; }
@Test @SuppressWarnings( "unchecked" ) public void updateUserGroups() { Mockito.when( userService.getUser( "def2" ) ).thenReturn( user ); final TypeReport typeReport = new TypeReport( User.class ); typeReport.getStats().incUpdated(); final ImportReport importReport = new ImportReport(); importReport.setStatus( Status.OK ); importReport.addTypeReport( typeReport ); if ( importReport.getStatus() == Status.OK && importReport.getStats().getUpdated() == 1 ) { userController.updateUserGroups( "def2", parsedUser, currentUser ); } Mockito.verifyNoInteractions( currentUserService ); Mockito.verify( userGroupService ).updateUserGroups( Mockito.same( user ), (Collection<String>) argThat( Matchers.containsInAnyOrder( "abc1", "abc2" ) ), Mockito.same( currentUser ) ); }
@Test public void updateUserGroupsNotOk() { final TypeReport typeReport = new TypeReport( User.class ); typeReport.getStats().incUpdated(); final ImportReport importReport = new ImportReport(); importReport.setStatus( Status.ERROR ); importReport.addTypeReport( typeReport ); if ( importReport.getStatus() == Status.OK && importReport.getStats().getUpdated() == 1 ) { userController.updateUserGroups( "def2", parsedUser, currentUser ); } Mockito.verifyNoInteractions( currentUserService ); Mockito.verifyNoInteractions( userService ); Mockito.verifyNoInteractions( userGroupService ); }
@Test public void updateUserGroupsNotUpdated() { final TypeReport typeReport = new TypeReport( User.class ); typeReport.getStats().incCreated(); final ImportReport importReport = new ImportReport(); importReport.setStatus( Status.OK ); importReport.addTypeReport( typeReport ); if ( importReport.getStatus() == Status.OK && importReport.getStats().getUpdated() == 1 ) { userController.updateUserGroups( "def2", parsedUser, currentUser ); } Mockito.verifyNoInteractions( currentUserService ); Mockito.verifyNoInteractions( userService ); Mockito.verifyNoInteractions( userGroupService ); }
@Test @SuppressWarnings( "unchecked" ) public void updateUserGroupsSameUser() { currentUser.setId( 1001 ); currentUser.setUid( "def2" ); User currentUser2 = new User(); currentUser2.setId( 1001 ); currentUser2.setUid( "def2" ); Mockito.when( userService.getUser( "def2" ) ).thenReturn( user ); Mockito.when( currentUserService.getCurrentUser() ).thenReturn( currentUser2 ); final TypeReport typeReport = new TypeReport( User.class ); typeReport.getStats().incUpdated(); final ImportReport importReport = new ImportReport(); importReport.setStatus( Status.OK ); importReport.addTypeReport( typeReport ); if ( importReport.getStatus() == Status.OK && importReport.getStats().getUpdated() == 1 ) { userController.updateUserGroups( "def2", parsedUser, currentUser ); } Mockito.verify( currentUserService ).getCurrentUser(); Mockito.verifyNoMoreInteractions( currentUserService ); Mockito.verify( userGroupService ).updateUserGroups( Mockito.same( user ), (Collection<String>) argThat( Matchers.containsInAnyOrder( "abc1", "abc2" ) ), Mockito.same( currentUser2 ) ); }