public void testSetPassword() throws Exception {

    gov.nih.nci.security.authorization.domainobjects.User csmUser =
        new gov.nih.nci.security.authorization.domainobjects.User();
    String userName = "******";
    String password = "******";
    csmUser.setLoginName(userName);
    user = new LocalPersonUser();
    user.setLoginId(userName);

    expect(csmUserRepositoryImpl.getUserByName(userName)).andReturn(user).anyTimes();
    expect(csmUserRepositoryImpl.userHasPassword(user, password)).andReturn(false).anyTimes();
    expect(csmUserRepositoryImpl.userHadPassword(user, password)).andReturn(false).anyTimes();
    expect(csmUserRepositoryImpl.getUsernameById(userName)).andReturn(userName).anyTimes();
    expect(passwordPolicyDao.getById(1)).andReturn(passwordPolicy).anyTimes();
    csmUserRepositoryImpl.userChangePassword(user, password, 3);
    userDao.save(user);

    replayMocks();
    try {
      passwordManagerService.addUserToken(userName);
      passwordManagerService.setPassword(userName, password, user.getToken());
    } catch (Exception e) {
      e.printStackTrace();
      fail("Not expecting any exception");
    }
    verifyMocks();
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    csmUserRepositoryImpl = registerMockFor(CSMUserRepositoryImpl.class);
    passwordPolicyDao = registerDaoMockFor(PasswordPolicyDao.class);
    userDao = registerDaoMockFor(UserDao.class);
    passwordManagerService = new PasswordManagerServiceImpl();
    passwordPolicyService = new PasswordPolicyServiceImpl();

    passwordPolicyService.setCsmUserRepository(csmUserRepositoryImpl);
    passwordPolicyService.setPasswordPolicyDao(passwordPolicyDao);
    passwordManagerService.setCsmUserRepository(csmUserRepositoryImpl);
    passwordManagerService.setPasswordPolicyService(passwordPolicyService);
    passwordManagerService.setUserDao(userDao);

    passwordPolicy = new PasswordPolicy();
    combinationPolicy = new CombinationPolicy();
    passwordCreationPolicy = new PasswordCreationPolicy();
    passwordPolicy.setPasswordCreationPolicy(passwordCreationPolicy);
    passwordCreationPolicy.setMinPasswordLength(7);
    passwordCreationPolicy.setMinPasswordAge(180);
    passwordCreationPolicy.setPasswordHistorySize(3);
    passwordCreationPolicy.setCombinationPolicy(combinationPolicy);
    combinationPolicy.setBaseTenDigitRequired(true);
    combinationPolicy.setLowerCaseAlphabetRequired(true);
    combinationPolicy.setMaxSubstringLength(3);
    combinationPolicy.setNonAlphaNumericRequired(true);
    combinationPolicy.setUpperCaseAlphabetRequired(false);
  }
  public void testAddToken() throws Exception {

    String userName = "******";
    user = new LocalPersonUser();
    user.setLoginId(userName);

    expect(csmUserRepositoryImpl.getUserByName(userName)).andReturn(user).anyTimes();
    userDao.save(user);

    replayMocks();
    assertNull(user.getToken());
    passwordManagerService.addUserToken(userName);
    assertNotNull(user.getToken());
  }