use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldCreateNewProfileAndDeleteOlderOnes.
@Test
public void shouldCreateNewProfileAndDeleteOlderOnes() throws NotUniqueUserProfileException {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
List<UserProfile> userProfiles = spy(new ArrayList<UserProfile>());
UserProfile userProfileOne = mock(UserProfile.class);
UserProfile userProfileTwo = mock(UserProfile.class);
UserProfile userProfileThree = mock(UserProfile.class);
userProfiles.add(userProfileOne);
userProfiles.add(userProfileTwo);
userProfiles.add(userProfileThree);
given(userProfilesDao.getProfiles()).willReturn(userProfiles);
given(userProfileOne.getLastSelectedDate()).willReturn(getDate(10));
given(userProfileTwo.getLastSelectedDate()).willReturn(getDate(31));
given(userProfileThree.getLastSelectedDate()).willReturn(getDate(30));
//When
devicePrintService.createNewProfile(devicePrint);
//Then
verify(userProfilesDao).removeProfile(anyString());
verify(userProfiles).remove(userProfileTwo);
verify(userProfiles).remove(userProfileThree);
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
verify(userProfilesDao).addProfile(userProfileCaptor.capture());
UserProfile userProfile = userProfileCaptor.getValue();
assertEquals(userProfile.getDevicePrint(), devicePrint);
verify(userProfilesDao).saveProfiles();
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldCreateNewProfile.
@Test
public void shouldCreateNewProfile() throws NotUniqueUserProfileException {
//Given
DevicePrint devicePrint = mock(DevicePrint.class);
given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
//When
devicePrintService.createNewProfile(devicePrint);
//Then
verify(userProfilesDao).removeProfile(anyString());
ArgumentCaptor<UserProfile> userProfileCaptor = ArgumentCaptor.forClass(UserProfile.class);
verify(userProfilesDao).addProfile(userProfileCaptor.capture());
UserProfile userProfile = userProfileCaptor.getValue();
assertEquals(userProfile.getDevicePrint(), devicePrint);
verify(userProfilesDao).saveProfiles();
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldUpdateUserProfileWhenHasValidPreviousProfile.
/**
* 9) fourth call, 3 - save profile, having a valid previous profile - should update previous profile, return ISAuthConstants.LOGIN_SUCCEED
*/
@Test
public void shouldUpdateUserProfileWhenHasValidPreviousProfile() throws AuthLoginException {
//Given
NameCallback devicePrintCallback = mock(NameCallback.class);
Callback[] callbacks = new Callback[] { devicePrintCallback };
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
UserProfile validStoredMatchingProfile = mock(UserProfile.class);
UserProfile selectedUserProfile = validStoredMatchingProfile;
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(true);
given(devicePrintService.getBestMatchingUserProfile(devicePrint)).willReturn(selectedUserProfile);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
verify(devicePrintService).updateProfile(selectedUserProfile, devicePrint);
assertEquals(nextState, ISAuthConstants.LOGIN_SUCCEED);
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile in project OpenAM by OpenRock.
the class DevicePrintServiceTest method shouldUpdateProfile.
@Test
public void shouldUpdateProfile() throws NotUniqueUserProfileException {
//Given
UserProfile userProfile = mock(UserProfile.class);
DevicePrint devicePrint = mock(DevicePrint.class);
given(userProfile.getUuid()).willReturn("USER_PROFILE_UUID");
given(userProfilesDao.getProfiles()).willReturn(new ArrayList<UserProfile>());
//When
devicePrintService.updateProfile(userProfile, devicePrint);
//Then
verify(userProfile).setSelectionCounter(anyLong());
verify(userProfile).setLastSelectedDate(Matchers.<Date>anyObject());
verify(userProfile).setDevicePrint(devicePrint);
verify(userProfilesDao).removeProfile(anyString());
verify(userProfilesDao).addProfile(userProfile);
verify(userProfilesDao).saveProfiles();
}
use of org.forgerock.openam.authentication.modules.deviceprint.model.UserProfile in project OpenAM by OpenRock.
the class DevicePrintAuthenticationServiceTest method shouldGotoOTPStateWhenNoValidMatchingStoredDevicePrintProfilesFound.
/**
* 2) first call ISAuthConstants.LOGIN_START - device print attr populated, with invalid stored profiles using SMS_OTP - should return 2
*/
@Test
public void shouldGotoOTPStateWhenNoValidMatchingStoredDevicePrintProfilesFound() throws AuthLoginException {
//Given
Callback[] callbacks = new Callback[1];
NameCallback devicePrintCallback = mock(NameCallback.class);
int state = ISAuthConstants.LOGIN_START;
DevicePrint devicePrint = mock(DevicePrint.class);
UserProfile selectedUserProfile = null;
callbacks[0] = devicePrintCallback;
given(devicePrintCallback.getName()).willReturn("DEVICE_PRINT_INFO");
given(devicePrintService.getDevicePrint(request)).willReturn(devicePrint);
given(devicePrintService.hasRequiredAttributes(devicePrint)).willReturn(true);
given(devicePrintService.getBestMatchingUserProfile(devicePrint)).willReturn(selectedUserProfile);
//When
int nextState = devicePrintAuthenticationService.process(callbacks, state);
//Then
assertEquals(nextState, 2);
}
Aggregations