@Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.fetchByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertEquals(existingDDLRecordVersion, newDDLRecordVersion);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DDLRecordVersion ddlRecordVersion = _persistence.create(pk);

    Assert.assertNotNull(ddlRecordVersion);

    Assert.assertEquals(ddlRecordVersion.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    _persistence.remove(newDDLRecordVersion);

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.fetchByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertNull(existingDDLRecordVersion);
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newDDLRecordVersion.getPrimaryKey());

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion, ddlRecordVersions.get(newDDLRecordVersion.getPrimaryKey()));
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(DDLRecordVersion.class, _dynamicQueryClassLoader);

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq("recordVersionId", newDDLRecordVersion.getRecordVersionId()));

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

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

    DDLRecordVersion existingDDLRecordVersion = result.get(0);

    Assert.assertEquals(existingDDLRecordVersion, newDDLRecordVersion);
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    _persistence.clearCache();

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.findByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertEquals(
        Long.valueOf(existingDDLRecordVersion.getRecordId()),
        ReflectionTestUtil.<Long>invoke(
            existingDDLRecordVersion, "getOriginalRecordId", new Class<?>[0]));
    Assert.assertTrue(
        Validator.equals(
            existingDDLRecordVersion.getVersion(),
            ReflectionTestUtil.invoke(
                existingDDLRecordVersion, "getOriginalVersion", new Class<?>[0])));
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newDDLRecordVersion.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion, ddlRecordVersions.get(newDDLRecordVersion.getPrimaryKey()));
  }
  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }

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

    DDLRecordVersion ddlRecordVersion = (DDLRecordVersion) obj;

    long primaryKey = ddlRecordVersion.getPrimaryKey();

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

    if (getPrimaryKey() < primaryKey) {
      return -1;
    } else if (getPrimaryKey() > primaryKey) {
      return 1;
    } else {
      return 0;
    }
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    DDLRecordVersion newDDLRecordVersion = addDDLRecordVersion();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(DDLRecordVersion.class, _dynamicQueryClassLoader);

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

    Object newRecordVersionId = newDDLRecordVersion.getRecordVersionId();

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

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

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

    Object existingRecordVersionId = result.get(0);

    Assert.assertEquals(existingRecordVersionId, newRecordVersionId);
  }
  @Override
  public AssetRenderer<DDLRecord> getAssetRenderer(long classPK, int type) throws PortalException {

    DDLRecord record = null;
    DDLRecordVersion recordVersion = null;

    if (type == TYPE_LATEST) {
      recordVersion = DDLRecordVersionLocalServiceUtil.getRecordVersion(classPK);

      record = recordVersion.getRecord();
    } else {
      record = DDLRecordLocalServiceUtil.getRecord(classPK);

      recordVersion = record.getRecordVersion();
    }

    DDLRecordAssetRenderer ddlRecordAssetRenderer =
        new DDLRecordAssetRenderer(record, recordVersion);

    ddlRecordAssetRenderer.setAssetRendererType(type);
    ddlRecordAssetRenderer.setServletContext(_servletContext);

    return ddlRecordAssetRenderer;
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    DDLRecordVersion newDDLRecordVersion1 = addDDLRecordVersion();
    DDLRecordVersion newDDLRecordVersion2 = addDDLRecordVersion();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newDDLRecordVersion1.getPrimaryKey());
    primaryKeys.add(newDDLRecordVersion2.getPrimaryKey());

    Map<Serializable, DDLRecordVersion> ddlRecordVersions =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, ddlRecordVersions.size());
    Assert.assertEquals(
        newDDLRecordVersion1, ddlRecordVersions.get(newDDLRecordVersion1.getPrimaryKey()));
    Assert.assertEquals(
        newDDLRecordVersion2, ddlRecordVersions.get(newDDLRecordVersion2.getPrimaryKey()));
  }
 @Override
 public Long get(DDLRecordVersion ddlRecordVersion) {
   return ddlRecordVersion.getRecordVersionId();
 }
  protected DDLRecordVersion addDDLRecordVersion() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DDLRecordVersion ddlRecordVersion = _persistence.create(pk);

    ddlRecordVersion.setGroupId(RandomTestUtil.nextLong());

    ddlRecordVersion.setCompanyId(RandomTestUtil.nextLong());

    ddlRecordVersion.setUserId(RandomTestUtil.nextLong());

    ddlRecordVersion.setUserName(RandomTestUtil.randomString());

    ddlRecordVersion.setCreateDate(RandomTestUtil.nextDate());

    ddlRecordVersion.setDDMStorageId(RandomTestUtil.nextLong());

    ddlRecordVersion.setRecordSetId(RandomTestUtil.nextLong());

    ddlRecordVersion.setRecordId(RandomTestUtil.nextLong());

    ddlRecordVersion.setVersion(RandomTestUtil.randomString());

    ddlRecordVersion.setDisplayIndex(RandomTestUtil.nextInt());

    ddlRecordVersion.setStatus(RandomTestUtil.nextInt());

    ddlRecordVersion.setStatusByUserId(RandomTestUtil.nextLong());

    ddlRecordVersion.setStatusByUserName(RandomTestUtil.randomString());

    ddlRecordVersion.setStatusDate(RandomTestUtil.nextDate());

    _ddlRecordVersions.add(_persistence.update(ddlRecordVersion));

    return ddlRecordVersion;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    DDLRecordVersion newDDLRecordVersion = _persistence.create(pk);

    newDDLRecordVersion.setGroupId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setCompanyId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setUserId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setUserName(RandomTestUtil.randomString());

    newDDLRecordVersion.setCreateDate(RandomTestUtil.nextDate());

    newDDLRecordVersion.setDDMStorageId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setRecordSetId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setRecordId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setVersion(RandomTestUtil.randomString());

    newDDLRecordVersion.setDisplayIndex(RandomTestUtil.nextInt());

    newDDLRecordVersion.setStatus(RandomTestUtil.nextInt());

    newDDLRecordVersion.setStatusByUserId(RandomTestUtil.nextLong());

    newDDLRecordVersion.setStatusByUserName(RandomTestUtil.randomString());

    newDDLRecordVersion.setStatusDate(RandomTestUtil.nextDate());

    _ddlRecordVersions.add(_persistence.update(newDDLRecordVersion));

    DDLRecordVersion existingDDLRecordVersion =
        _persistence.findByPrimaryKey(newDDLRecordVersion.getPrimaryKey());

    Assert.assertEquals(
        existingDDLRecordVersion.getRecordVersionId(), newDDLRecordVersion.getRecordVersionId());
    Assert.assertEquals(existingDDLRecordVersion.getGroupId(), newDDLRecordVersion.getGroupId());
    Assert.assertEquals(
        existingDDLRecordVersion.getCompanyId(), newDDLRecordVersion.getCompanyId());
    Assert.assertEquals(existingDDLRecordVersion.getUserId(), newDDLRecordVersion.getUserId());
    Assert.assertEquals(existingDDLRecordVersion.getUserName(), newDDLRecordVersion.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDDLRecordVersion.getCreateDate()),
        Time.getShortTimestamp(newDDLRecordVersion.getCreateDate()));
    Assert.assertEquals(
        existingDDLRecordVersion.getDDMStorageId(), newDDLRecordVersion.getDDMStorageId());
    Assert.assertEquals(
        existingDDLRecordVersion.getRecordSetId(), newDDLRecordVersion.getRecordSetId());
    Assert.assertEquals(existingDDLRecordVersion.getRecordId(), newDDLRecordVersion.getRecordId());
    Assert.assertEquals(existingDDLRecordVersion.getVersion(), newDDLRecordVersion.getVersion());
    Assert.assertEquals(
        existingDDLRecordVersion.getDisplayIndex(), newDDLRecordVersion.getDisplayIndex());
    Assert.assertEquals(existingDDLRecordVersion.getStatus(), newDDLRecordVersion.getStatus());
    Assert.assertEquals(
        existingDDLRecordVersion.getStatusByUserId(), newDDLRecordVersion.getStatusByUserId());
    Assert.assertEquals(
        existingDDLRecordVersion.getStatusByUserName(), newDDLRecordVersion.getStatusByUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingDDLRecordVersion.getStatusDate()),
        Time.getShortTimestamp(newDDLRecordVersion.getStatusDate()));
  }
  /**
   * 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 DDLRecordVersion toModel(DDLRecordVersionSoap soapModel) {
    if (soapModel == null) {
      return null;
    }

    DDLRecordVersion model = new DDLRecordVersionImpl();

    model.setRecordVersionId(soapModel.getRecordVersionId());
    model.setGroupId(soapModel.getGroupId());
    model.setCompanyId(soapModel.getCompanyId());
    model.setUserId(soapModel.getUserId());
    model.setUserName(soapModel.getUserName());
    model.setCreateDate(soapModel.getCreateDate());
    model.setDDMStorageId(soapModel.getDDMStorageId());
    model.setRecordSetId(soapModel.getRecordSetId());
    model.setRecordId(soapModel.getRecordId());
    model.setVersion(soapModel.getVersion());
    model.setDisplayIndex(soapModel.getDisplayIndex());
    model.setStatus(soapModel.getStatus());
    model.setStatusByUserId(soapModel.getStatusByUserId());
    model.setStatusByUserName(soapModel.getStatusByUserName());
    model.setStatusDate(soapModel.getStatusDate());

    return model;
  }