@Test
public void testSuccessfulAuth() {

  Users users = createMock(Users.class);
  UserDAO userDAO = createMock(UserDAO.class);
  Authentication authentication = createMock(Authentication.class);
  UserEntity userEntity = combineUserEntity();
  expect(authentication.getName()).andReturn(TEST_USER_NAME);
  expect(userDAO.findLocalUserByName(TEST_USER_NAME)).andReturn(userEntity);
  expect(authentication.getCredentials()).andReturn(TEST_USER_PASS).anyTimes();
  expect(users.getUserAuthorities(userEntity.getUserName(), userEntity.getUserType())).andReturn(null);
  replay(users, userDAO, authentication);
  AmbariLocalUserProvider ambariLocalUserProvider = new AmbariLocalUserProvider(userDAO, users, passwordEncoder);
  Authentication resultedAuth = ambariLocalUserProvider.authenticate(authentication);
  verify(users, userDAO, authentication);
  assertNotNull(resultedAuth);
  assertEquals(true, resultedAuth.isAuthenticated());
  assertTrue(resultedAuth instanceof AmbariUserAuthentication);
  assertEquals(1, ((User) resultedAuth.getPrincipal()).getUserId());
}