@Test
public void loadUserByUsernameSuccess() throws Exception {

  AmbariKerberosAuthenticationProperties properties = new AmbariKerberosAuthenticationProperties();
  Configuration configuration = createMock(Configuration.class);
  expect(configuration.getKerberosAuthenticationProperties()).andReturn(properties).once();
  User user = createMock(User.class);
  expect(user.getUserName()).andReturn("user1").once();
  expect(user.getUserType()).andReturn(UserType.LDAP).once();
  Collection<AmbariGrantedAuthority> userAuthorities = Collections.singletonList(createNiceMock(AmbariGrantedAuthority.class));
  Users users = createMock(Users.class);
  expect(users.getUser("user1", UserType.LDAP)).andReturn(user).once();
  expect(users.getUserAuthorities("user1", UserType.LDAP)).andReturn(userAuthorities).once();
  replayAll();
  UserDetailsService userdetailsService = new AmbariAuthToLocalUserDetailsService(configuration, users);
  UserDetails userDetails = userdetailsService.loadUserByUsername("user1@EXAMPLE.COM");
  verifyAll();
  Assert.assertNotNull(userDetails);
  Assert.assertEquals("user1", userDetails.getUsername());
  Assert.assertEquals(userAuthorities.size(), userDetails.getAuthorities().size());
  Assert.assertEquals("", userDetails.getPassword());
}