@Test
  public void testResetOriginalValues() throws Exception {
    if (!PropsValues.HIBERNATE_CACHE_USE_SECOND_LEVEL_CACHE) {
      return;
    }

    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    _persistence.clearCache();

    PasswordPolicyModelImpl existingPasswordPolicyModelImpl =
        (PasswordPolicyModelImpl) _persistence.findByPrimaryKey(newPasswordPolicy.getPrimaryKey());

    Assert.assertEquals(
        existingPasswordPolicyModelImpl.getCompanyId(),
        existingPasswordPolicyModelImpl.getOriginalCompanyId());
    Assert.assertEquals(
        existingPasswordPolicyModelImpl.getDefaultPolicy(),
        existingPasswordPolicyModelImpl.getOriginalDefaultPolicy());

    Assert.assertEquals(
        existingPasswordPolicyModelImpl.getCompanyId(),
        existingPasswordPolicyModelImpl.getOriginalCompanyId());
    Assert.assertTrue(
        Validator.equals(
            existingPasswordPolicyModelImpl.getName(),
            existingPasswordPolicyModelImpl.getOriginalName()));
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    PasswordPolicy existingPasswordPolicy =
        _persistence.fetchByPrimaryKey(newPasswordPolicy.getPrimaryKey());

    Assert.assertEquals(existingPasswordPolicy, newPasswordPolicy);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PasswordPolicy passwordPolicy = _persistence.create(pk);

    Assert.assertNotNull(passwordPolicy);

    Assert.assertEquals(passwordPolicy.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    _persistence.remove(newPasswordPolicy);

    PasswordPolicy existingPasswordPolicy =
        _persistence.fetchByPrimaryKey(newPasswordPolicy.getPrimaryKey());

    Assert.assertNull(existingPasswordPolicy);
  }
  public int compare(Object obj1, Object obj2) {
    PasswordPolicy passwordPolicy1 = (PasswordPolicy) obj1;
    PasswordPolicy passwordPolicy2 = (PasswordPolicy) obj2;

    int value = passwordPolicy1.getName().compareTo(passwordPolicy2.getName());

    if (_ascending) {
      return value;
    } else {
      return -value;
    }
  }
  public static PasswordPolicy addPasswordPolicyRel(
      Organization organization, ServiceContext serviceContext) throws Exception {

    PasswordPolicy passwordPolicy = PasswordPolicyTestUtil.addPasswordPolicy(serviceContext);

    PasswordPolicyRelLocalServiceUtil.addPasswordPolicyRel(
        passwordPolicy.getPasswordPolicyId(),
        organization.getModelClassName(),
        organization.getOrganizationId());

    return passwordPolicy;
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            PasswordPolicy.class, PasswordPolicy.class.getClassLoader());

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("passwordPolicyId", newPasswordPolicy.getPasswordPolicyId()));

    List<PasswordPolicy> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    PasswordPolicy existingPasswordPolicy = result.get(0);

    Assert.assertEquals(existingPasswordPolicy, newPasswordPolicy);
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

    if (!(obj instanceof PasswordPolicy)) {
      return false;
    }

    PasswordPolicy passwordPolicy = (PasswordPolicy) obj;

    long primaryKey = passwordPolicy.getPrimaryKey();

    if (getPrimaryKey() == primaryKey) {
      return true;
    } else {
      return false;
    }
  }
  @Override
  public int compareTo(PasswordPolicy passwordPolicy) {
    long primaryKey = passwordPolicy.getPrimaryKey();

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    PasswordPolicy newPasswordPolicy = addPasswordPolicy();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(
            PasswordPolicy.class, PasswordPolicy.class.getClassLoader());

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("passwordPolicyId"));

    Object newPasswordPolicyId = newPasswordPolicy.getPasswordPolicyId();

    dynamicQuery.add(
        RestrictionsFactoryUtil.in("passwordPolicyId", new Object[] {newPasswordPolicyId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingPasswordPolicyId = result.get(0);

    Assert.assertEquals(existingPasswordPolicyId, newPasswordPolicyId);
  }
  @Override
  protected void doImportStagedModel(
      PortletDataContext portletDataContext, PasswordPolicy passwordPolicy) throws Exception {

    long userId = portletDataContext.getUserId(passwordPolicy.getUserUuid());

    ServiceContext serviceContext =
        portletDataContext.createServiceContext(
            passwordPolicy, PasswordPolicyPortletDataHandler.NAMESPACE);

    PasswordPolicy existingPasswordPolicy =
        PasswordPolicyLocalServiceUtil.fetchPasswordPolicyByUuidAndCompanyId(
            passwordPolicy.getUuid(), portletDataContext.getCompanyId());

    if (existingPasswordPolicy == null) {
      existingPasswordPolicy =
          PasswordPolicyLocalServiceUtil.fetchPasswordPolicy(
              portletDataContext.getCompanyId(), passwordPolicy.getName());
    }

    PasswordPolicy importedPasswordPolicy = null;

    if (existingPasswordPolicy == null) {
      serviceContext.setUuid(passwordPolicy.getUuid());

      importedPasswordPolicy =
          PasswordPolicyLocalServiceUtil.addPasswordPolicy(
              userId,
              passwordPolicy.isDefaultPolicy(),
              passwordPolicy.getName(),
              passwordPolicy.getDescription(),
              passwordPolicy.getChangeable(),
              passwordPolicy.isChangeRequired(),
              passwordPolicy.getMinAge(),
              passwordPolicy.getCheckSyntax(),
              passwordPolicy.isAllowDictionaryWords(),
              passwordPolicy.getMinAlphanumeric(),
              passwordPolicy.getMinLength(),
              passwordPolicy.getMinLowerCase(),
              passwordPolicy.getMinNumbers(),
              passwordPolicy.getMinSymbols(),
              passwordPolicy.getMinUpperCase(),
              passwordPolicy.getRegex(),
              passwordPolicy.isHistory(),
              passwordPolicy.getHistoryCount(),
              passwordPolicy.isExpireable(),
              passwordPolicy.getMaxAge(),
              passwordPolicy.getWarningTime(),
              passwordPolicy.getGraceLimit(),
              passwordPolicy.isLockout(),
              passwordPolicy.getMaxFailure(),
              passwordPolicy.getLockoutDuration(),
              passwordPolicy.getResetFailureCount(),
              passwordPolicy.getResetTicketMaxAge(),
              serviceContext);
    } else {
      importedPasswordPolicy =
          PasswordPolicyLocalServiceUtil.updatePasswordPolicy(
              existingPasswordPolicy.getPasswordPolicyId(),
              passwordPolicy.getName(),
              passwordPolicy.getDescription(),
              passwordPolicy.isChangeable(),
              passwordPolicy.isChangeRequired(),
              passwordPolicy.getMinAge(),
              passwordPolicy.isCheckSyntax(),
              passwordPolicy.isAllowDictionaryWords(),
              passwordPolicy.getMinAlphanumeric(),
              passwordPolicy.getMinLength(),
              passwordPolicy.getMinLowerCase(),
              passwordPolicy.getMinNumbers(),
              passwordPolicy.getMinSymbols(),
              passwordPolicy.getMinUpperCase(),
              passwordPolicy.getRegex(),
              passwordPolicy.isHistory(),
              passwordPolicy.getHistoryCount(),
              passwordPolicy.isExpireable(),
              passwordPolicy.getMaxAge(),
              passwordPolicy.getWarningTime(),
              passwordPolicy.getGraceLimit(),
              passwordPolicy.isLockout(),
              passwordPolicy.getMaxFailure(),
              passwordPolicy.getLockoutDuration(),
              passwordPolicy.getResetFailureCount(),
              passwordPolicy.getResetTicketMaxAge(),
              serviceContext);
    }

    portletDataContext.importClassedModel(
        passwordPolicy, importedPasswordPolicy, PasswordPolicyPortletDataHandler.NAMESPACE);
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PasswordPolicy newPasswordPolicy = _persistence.create(pk);

    newPasswordPolicy.setCompanyId(ServiceTestUtil.nextLong());

    newPasswordPolicy.setUserId(ServiceTestUtil.nextLong());

    newPasswordPolicy.setUserName(ServiceTestUtil.randomString());

    newPasswordPolicy.setCreateDate(ServiceTestUtil.nextDate());

    newPasswordPolicy.setModifiedDate(ServiceTestUtil.nextDate());

    newPasswordPolicy.setDefaultPolicy(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setName(ServiceTestUtil.randomString());

    newPasswordPolicy.setDescription(ServiceTestUtil.randomString());

    newPasswordPolicy.setChangeable(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setChangeRequired(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setMinAge(ServiceTestUtil.nextLong());

    newPasswordPolicy.setCheckSyntax(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setAllowDictionaryWords(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setMinAlphanumeric(ServiceTestUtil.nextInt());

    newPasswordPolicy.setMinLength(ServiceTestUtil.nextInt());

    newPasswordPolicy.setMinLowerCase(ServiceTestUtil.nextInt());

    newPasswordPolicy.setMinNumbers(ServiceTestUtil.nextInt());

    newPasswordPolicy.setMinSymbols(ServiceTestUtil.nextInt());

    newPasswordPolicy.setMinUpperCase(ServiceTestUtil.nextInt());

    newPasswordPolicy.setHistory(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setHistoryCount(ServiceTestUtil.nextInt());

    newPasswordPolicy.setExpireable(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setMaxAge(ServiceTestUtil.nextLong());

    newPasswordPolicy.setWarningTime(ServiceTestUtil.nextLong());

    newPasswordPolicy.setGraceLimit(ServiceTestUtil.nextInt());

    newPasswordPolicy.setLockout(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setMaxFailure(ServiceTestUtil.nextInt());

    newPasswordPolicy.setLockoutDuration(ServiceTestUtil.nextLong());

    newPasswordPolicy.setRequireUnlock(ServiceTestUtil.randomBoolean());

    newPasswordPolicy.setResetFailureCount(ServiceTestUtil.nextLong());

    newPasswordPolicy.setResetTicketMaxAge(ServiceTestUtil.nextLong());

    _persistence.update(newPasswordPolicy, false);

    PasswordPolicy existingPasswordPolicy =
        _persistence.findByPrimaryKey(newPasswordPolicy.getPrimaryKey());

    Assert.assertEquals(
        existingPasswordPolicy.getPasswordPolicyId(), newPasswordPolicy.getPasswordPolicyId());
    Assert.assertEquals(existingPasswordPolicy.getCompanyId(), newPasswordPolicy.getCompanyId());
    Assert.assertEquals(existingPasswordPolicy.getUserId(), newPasswordPolicy.getUserId());
    Assert.assertEquals(existingPasswordPolicy.getUserName(), newPasswordPolicy.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingPasswordPolicy.getCreateDate()),
        Time.getShortTimestamp(newPasswordPolicy.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingPasswordPolicy.getModifiedDate()),
        Time.getShortTimestamp(newPasswordPolicy.getModifiedDate()));
    Assert.assertEquals(
        existingPasswordPolicy.getDefaultPolicy(), newPasswordPolicy.getDefaultPolicy());
    Assert.assertEquals(existingPasswordPolicy.getName(), newPasswordPolicy.getName());
    Assert.assertEquals(
        existingPasswordPolicy.getDescription(), newPasswordPolicy.getDescription());
    Assert.assertEquals(existingPasswordPolicy.getChangeable(), newPasswordPolicy.getChangeable());
    Assert.assertEquals(
        existingPasswordPolicy.getChangeRequired(), newPasswordPolicy.getChangeRequired());
    Assert.assertEquals(existingPasswordPolicy.getMinAge(), newPasswordPolicy.getMinAge());
    Assert.assertEquals(
        existingPasswordPolicy.getCheckSyntax(), newPasswordPolicy.getCheckSyntax());
    Assert.assertEquals(
        existingPasswordPolicy.getAllowDictionaryWords(),
        newPasswordPolicy.getAllowDictionaryWords());
    Assert.assertEquals(
        existingPasswordPolicy.getMinAlphanumeric(), newPasswordPolicy.getMinAlphanumeric());
    Assert.assertEquals(existingPasswordPolicy.getMinLength(), newPasswordPolicy.getMinLength());
    Assert.assertEquals(
        existingPasswordPolicy.getMinLowerCase(), newPasswordPolicy.getMinLowerCase());
    Assert.assertEquals(existingPasswordPolicy.getMinNumbers(), newPasswordPolicy.getMinNumbers());
    Assert.assertEquals(existingPasswordPolicy.getMinSymbols(), newPasswordPolicy.getMinSymbols());
    Assert.assertEquals(
        existingPasswordPolicy.getMinUpperCase(), newPasswordPolicy.getMinUpperCase());
    Assert.assertEquals(existingPasswordPolicy.getHistory(), newPasswordPolicy.getHistory());
    Assert.assertEquals(
        existingPasswordPolicy.getHistoryCount(), newPasswordPolicy.getHistoryCount());
    Assert.assertEquals(existingPasswordPolicy.getExpireable(), newPasswordPolicy.getExpireable());
    Assert.assertEquals(existingPasswordPolicy.getMaxAge(), newPasswordPolicy.getMaxAge());
    Assert.assertEquals(
        existingPasswordPolicy.getWarningTime(), newPasswordPolicy.getWarningTime());
    Assert.assertEquals(existingPasswordPolicy.getGraceLimit(), newPasswordPolicy.getGraceLimit());
    Assert.assertEquals(existingPasswordPolicy.getLockout(), newPasswordPolicy.getLockout());
    Assert.assertEquals(existingPasswordPolicy.getMaxFailure(), newPasswordPolicy.getMaxFailure());
    Assert.assertEquals(
        existingPasswordPolicy.getLockoutDuration(), newPasswordPolicy.getLockoutDuration());
    Assert.assertEquals(
        existingPasswordPolicy.getRequireUnlock(), newPasswordPolicy.getRequireUnlock());
    Assert.assertEquals(
        existingPasswordPolicy.getResetFailureCount(), newPasswordPolicy.getResetFailureCount());
    Assert.assertEquals(
        existingPasswordPolicy.getResetTicketMaxAge(), newPasswordPolicy.getResetTicketMaxAge());
  }
  protected PasswordPolicy addPasswordPolicy() throws Exception {
    long pk = ServiceTestUtil.nextLong();

    PasswordPolicy passwordPolicy = _persistence.create(pk);

    passwordPolicy.setCompanyId(ServiceTestUtil.nextLong());

    passwordPolicy.setUserId(ServiceTestUtil.nextLong());

    passwordPolicy.setUserName(ServiceTestUtil.randomString());

    passwordPolicy.setCreateDate(ServiceTestUtil.nextDate());

    passwordPolicy.setModifiedDate(ServiceTestUtil.nextDate());

    passwordPolicy.setDefaultPolicy(ServiceTestUtil.randomBoolean());

    passwordPolicy.setName(ServiceTestUtil.randomString());

    passwordPolicy.setDescription(ServiceTestUtil.randomString());

    passwordPolicy.setChangeable(ServiceTestUtil.randomBoolean());

    passwordPolicy.setChangeRequired(ServiceTestUtil.randomBoolean());

    passwordPolicy.setMinAge(ServiceTestUtil.nextLong());

    passwordPolicy.setCheckSyntax(ServiceTestUtil.randomBoolean());

    passwordPolicy.setAllowDictionaryWords(ServiceTestUtil.randomBoolean());

    passwordPolicy.setMinAlphanumeric(ServiceTestUtil.nextInt());

    passwordPolicy.setMinLength(ServiceTestUtil.nextInt());

    passwordPolicy.setMinLowerCase(ServiceTestUtil.nextInt());

    passwordPolicy.setMinNumbers(ServiceTestUtil.nextInt());

    passwordPolicy.setMinSymbols(ServiceTestUtil.nextInt());

    passwordPolicy.setMinUpperCase(ServiceTestUtil.nextInt());

    passwordPolicy.setHistory(ServiceTestUtil.randomBoolean());

    passwordPolicy.setHistoryCount(ServiceTestUtil.nextInt());

    passwordPolicy.setExpireable(ServiceTestUtil.randomBoolean());

    passwordPolicy.setMaxAge(ServiceTestUtil.nextLong());

    passwordPolicy.setWarningTime(ServiceTestUtil.nextLong());

    passwordPolicy.setGraceLimit(ServiceTestUtil.nextInt());

    passwordPolicy.setLockout(ServiceTestUtil.randomBoolean());

    passwordPolicy.setMaxFailure(ServiceTestUtil.nextInt());

    passwordPolicy.setLockoutDuration(ServiceTestUtil.nextLong());

    passwordPolicy.setRequireUnlock(ServiceTestUtil.randomBoolean());

    passwordPolicy.setResetFailureCount(ServiceTestUtil.nextLong());

    passwordPolicy.setResetTicketMaxAge(ServiceTestUtil.nextLong());

    _persistence.update(passwordPolicy, false);

    return passwordPolicy;
  }
  /**
   * Converts the soap model instance into a normal model instance.
   *
   * @param soapModel the soap model instance to convert
   * @return the normal model instance
   */
  public static PasswordPolicy toModel(PasswordPolicySoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    PasswordPolicy model = new PasswordPolicyImpl();

    model.setMvccVersion(soapModel.getMvccVersion());
    model.setUuid(soapModel.getUuid());
    model.setPasswordPolicyId(soapModel.getPasswordPolicyId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setModifiedDate(soapModel.getModifiedDate());
    model.setDefaultPolicy(soapModel.getDefaultPolicy());
    model.setName(soapModel.getName());
    model.setDescription(soapModel.getDescription());
    model.setChangeable(soapModel.getChangeable());
    model.setChangeRequired(soapModel.getChangeRequired());
    model.setMinAge(soapModel.getMinAge());
    model.setCheckSyntax(soapModel.getCheckSyntax());
    model.setAllowDictionaryWords(soapModel.getAllowDictionaryWords());
    model.setMinAlphanumeric(soapModel.getMinAlphanumeric());
    model.setMinLength(soapModel.getMinLength());
    model.setMinLowerCase(soapModel.getMinLowerCase());
    model.setMinNumbers(soapModel.getMinNumbers());
    model.setMinSymbols(soapModel.getMinSymbols());
    model.setMinUpperCase(soapModel.getMinUpperCase());
    model.setRegex(soapModel.getRegex());
    model.setHistory(soapModel.getHistory());
    model.setHistoryCount(soapModel.getHistoryCount());
    model.setExpireable(soapModel.getExpireable());
    model.setMaxAge(soapModel.getMaxAge());
    model.setWarningTime(soapModel.getWarningTime());
    model.setGraceLimit(soapModel.getGraceLimit());
    model.setLockout(soapModel.getLockout());
    model.setMaxFailure(soapModel.getMaxFailure());
    model.setLockoutDuration(soapModel.getLockoutDuration());
    model.setRequireUnlock(soapModel.getRequireUnlock());
    model.setResetFailureCount(soapModel.getResetFailureCount());
    model.setResetTicketMaxAge(soapModel.getResetTicketMaxAge());

    return model;
  }