OrganizationIdentityProvider extends IdentityProvider<User> { @Override public void onUpdateProfile(Profile profile) throws MessageException { new UpdateProfileProcess(profile).doUpdate(); } OrganizationIdentityProvider(OrganizationService organizationService); @Override String getName(); List<String> getAllUserId(); @Override User findByRemoteId(String remoteId); @Override Identity createIdentity(User user); @Override void populateProfile(Profile profile, User user); @Override void onUpdateProfile(Profile profile); final static String NAME; }
@Test public void shouldUpdateProfileWhenResetingGender() throws Exception { Mockito.when(userHandler.findUserByName(Mockito.eq("john"))).thenReturn(new UserImpl("john")); Mockito.when(organizationService.getUserHandler()).thenReturn(userHandler); UserProfileImpl existingProfile = new UserProfileImpl("john"); existingProfile.setAttribute(Profile.GENDER, "Male"); existingProfile.setAttribute(Profile.POSITION, "Product Manager"); Mockito.when(userProfileHandler.findUserProfileByName(Mockito.eq("john"))).thenReturn(existingProfile); Mockito.when(organizationService.getUserProfileHandler()).thenReturn(userProfileHandler); OrganizationIdentityProvider organizationIdentityProvider = new OrganizationIdentityProvider(organizationService); Profile updatedProfile = new Profile(new Identity("john")); updatedProfile.setProperty(Profile.USERNAME, "john"); updatedProfile.setProperty(Profile.GENDER, ""); updatedProfile.setProperty(Profile.POSITION, "Product Manager"); updatedProfile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT)); organizationIdentityProvider.onUpdateProfile(updatedProfile); ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class); Mockito.verify(userProfileHandler, Mockito.times(1)).saveUserProfile(userProfileCaptor.capture(), Mockito.eq(false)); UserProfile savedProfile = userProfileCaptor.getValue(); assertEquals("", savedProfile.getAttribute(UserProfile.PERSONAL_INFO_KEYS[4])); assertEquals("Product Manager", savedProfile.getAttribute(UserProfile.PERSONAL_INFO_KEYS[7])); }
@Test public void shouldUpdateProfileWhenResetingPosition() throws Exception { Mockito.when(userHandler.findUserByName(Mockito.eq("john"))).thenReturn(new UserImpl("john")); Mockito.when(organizationService.getUserHandler()).thenReturn(userHandler); UserProfileImpl existingProfile = new UserProfileImpl("john"); existingProfile.setAttribute(Profile.POSITION, "Product Manager"); Mockito.when(userProfileHandler.findUserProfileByName(Mockito.eq("john"))).thenReturn(existingProfile); Mockito.when(organizationService.getUserProfileHandler()).thenReturn(userProfileHandler); OrganizationIdentityProvider organizationIdentityProvider = new OrganizationIdentityProvider(organizationService); Profile updatedProfile = new Profile(new Identity("john")); updatedProfile.setProperty(Profile.USERNAME, "john"); updatedProfile.setProperty(Profile.POSITION, ""); updatedProfile.setListUpdateTypes(Arrays.asList(Profile.UpdateType.CONTACT)); organizationIdentityProvider.onUpdateProfile(updatedProfile); ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class); Mockito.verify(userProfileHandler, Mockito.times(1)).saveUserProfile(userProfileCaptor.capture(), Mockito.eq(false)); UserProfile savedProfile = userProfileCaptor.getValue(); assertEquals("", savedProfile.getAttribute(UserProfile.PERSONAL_INFO_KEYS[7])); }