@Test
  public void testFindByMisversioned() throws Exception {
    long oldFileEntryId = _defaultRepositoryDLFileVersion.getFileEntryId();

    try {
      _defaultRepositoryDLFileVersion.setFileEntryId(RandomTestUtil.randomLong());

      DLFileVersionLocalServiceUtil.updateDLFileVersion(_defaultRepositoryDLFileVersion);

      List<DLFileEntry> dlFileEntries = DLFileEntryLocalServiceUtil.getMisversionedFileEntries();

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

      DLFileEntry dlFileEntry = dlFileEntries.get(0);

      Assert.assertEquals("FE1.txt", dlFileEntry.getTitle());
    } finally {
      _defaultRepositoryDLFileVersion.setFileEntryId(oldFileEntryId);

      DLFileVersionLocalServiceUtil.updateDLFileVersion(_defaultRepositoryDLFileVersion);
    }
  }
  @Test
  public void testUpdateFileNameWhenUpdatingFileVersionStatus() throws Exception {

    DLFileEntry dlFileEntry = addDLFileEntry(DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, false);

    ServiceContext serviceContext = ServiceContextTestUtil.getServiceContext(_group.getGroupId());

    dlFileEntry = updateStatus(dlFileEntry.getLatestFileVersion(true), serviceContext);

    DLFileVersion dlFileVersion = dlFileEntry.getLatestFileVersion(true);

    String fileName = RandomTestUtil.randomString();

    dlFileVersion.setFileName(fileName);

    DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion);

    dlFileEntry = updateStatus(dlFileVersion, serviceContext);

    Assert.assertEquals(
        DLUtil.getSanitizedFileName(fileName, dlFileEntry.getExtension()),
        dlFileEntry.getFileName());
  }
  @Test
  public void testRebuildTree() throws Exception {
    createTree();

    for (FileEntry fileEntry : _fileEntries) {
      DLFileVersion dlFileVersion =
          DLFileVersionLocalServiceUtil.getFileVersion(
              fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT);

      dlFileVersion.setTreePath(null);

      DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion);
    }

    DLFileVersionLocalServiceUtil.rebuildTree(TestPropsValues.getCompanyId());

    for (FileEntry fileEntry : _fileEntries) {
      DLFileVersion dlFileVersion =
          DLFileVersionLocalServiceUtil.getFileVersion(
              fileEntry.getFileEntryId(), DLFileEntryConstants.VERSION_DEFAULT);

      Assert.assertEquals(dlFileVersion.buildTreePath(), dlFileVersion.getTreePath());
    }
  }
  protected static Object[] setUp(
      long repositoryId, String titleSuffix, ServiceContext serviceContext) throws Exception {

    Folder folder =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            repositoryId,
            DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
            "Folder A",
            StringPool.BLANK,
            serviceContext);

    DLAppLocalServiceUtil.addFolder(
        TestPropsValues.getUserId(),
        repositoryId,
        folder.getFolderId(),
        "Folder B",
        StringPool.BLANK,
        serviceContext);

    Folder folderC =
        DLAppLocalServiceUtil.addFolder(
            TestPropsValues.getUserId(),
            repositoryId,
            folder.getFolderId(),
            "Folder C",
            StringPool.BLANK,
            serviceContext);

    DLTrashServiceUtil.moveFolderToTrash(folderC.getFolderId());

    FileEntry fileEntry =
        addFileEntry(
            _user.getUserId(),
            repositoryId,
            folder.getFolderId(),
            "FE1.txt",
            titleSuffix,
            ContentTypes.TEXT_PLAIN,
            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_BASIC_DOCUMENT);

    LiferayFileEntry liferayFileEntry = (LiferayFileEntry) fileEntry;

    DLFileEntry dlFileEntry = liferayFileEntry.getDLFileEntry();

    dlFileEntry.setExtraSettings("hello=world");
    dlFileEntry.setSmallImageId(_SMALL_IMAGE_ID);

    dlFileEntry = DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry);

    DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

    addFileEntry(
        TestPropsValues.getUserId(),
        repositoryId,
        folder.getFolderId(),
        "FE2.pdf",
        titleSuffix,
        ContentTypes.APPLICATION_PDF,
        DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);

    fileEntry =
        addFileEntry(
            TestPropsValues.getUserId(),
            repositoryId,
            folder.getFolderId(),
            "FE3.txt",
            titleSuffix,
            ContentTypes.TEXT_PLAIN,
            DLFileEntryTypeConstants.FILE_ENTRY_TYPE_ID_ALL);

    fileEntry =
        DLAppServiceUtil.updateFileEntry(
            fileEntry.getFileEntryId(),
            "FE3.txt",
            ContentTypes.TEXT_PLAIN,
            "FE3.txt".concat(titleSuffix),
            StringPool.BLANK,
            StringPool.BLANK,
            false,
            RandomTestUtil.randomBytes(TikaSafeRandomizerBumper.INSTANCE),
            serviceContext);

    dlFileEntry = ((LiferayFileEntry) fileEntry).getDLFileEntry();

    dlFileEntry.setDescription("FE3.txt");

    DLFileEntryLocalServiceUtil.updateDLFileEntry(dlFileEntry);

    DLFileVersion dlFileVersion3 = dlFileEntry.getFileVersion();

    dlFileVersion3.setExtraSettings("hello=world");

    DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion3);

    DLTrashServiceUtil.moveFileEntryToTrash(fileEntry.getFileEntryId());

    return new Object[] {folder, dlFileVersion};
  }