Test that PostLoginActivities are executed for user after auth success

This commit is contained in:
Sankaranarayanan Viswanathan
2014-10-08 22:39:32 -04:00
parent 64b5d64709
commit 8a172170ea

View File

@@ -137,6 +137,41 @@ public class UserServiceTest {
Assert.assertFalse(authenticatedUser.isPresent());
}
@Test public void
calling_login_should_execute_post_login_activities_for_user_on_successful_authentication() {
// Make a user who is not disabled
User user = new User();
user.setDisabled(false);
// Set the encryptedPassword on the user
byte[] encryptedPassword = new byte[]{1,2,3};
user.setPassword(encryptedPassword);
// Set a salt for this user
byte[] salt = new byte[]{4,5,6};
user.setSalt(salt);
// Mock DAO to return the user
UserDAO dao = mock(UserDAO.class);
when(dao.findByName("test")).thenReturn(user);
// Mock PasswordEncryptionService
PasswordEncryptionService encryptionService = mock(PasswordEncryptionService.class);
when(encryptionService.authenticate(anyString(), any(byte[].class), any(byte[].class))).thenReturn(true);
// Mock PostLoginActivities to do nothing
PostLoginActivities postLoginActivities = mock(PostLoginActivities.class);
doNothing().when(postLoginActivities).executeFor(any(User.class));
// Create service with mocks
UserService service = new UserService(null, dao, null, encryptionService, null, postLoginActivities);
// Try to login as the user
service.login("test", "password");
verify(postLoginActivities).executeFor(user);
}
@Test public void
calling_login_should_return_user_object_on_successful_authentication() {
// Make a user who is not disabled