@After
  @Override
  public void tearDown() throws Exception {
    if (_fileEntry != null) {
      DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());
    }

    super.tearDown();
  }
  protected void searchFile(boolean rootFolder) throws Exception {
    FileEntry fileEntry = addFileEntry(rootFolder);

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    search(fileEntry, rootFolder, "title", true);
    search(fileEntry, rootFolder, "content", true);

    DLAppServiceUtil.deleteFileEntry(fileEntry.getFileEntryId());
  }
  public void tearDown() throws Exception {
    if (_fileEntry != null) {
      DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());
    }

    if (_folder != null) {
      DLAppServiceUtil.deleteFolder(_folder.getFolderId());
    }

    super.tearDown();
  }
  @Test
  public void testAddFileEntryWithDuplicateName() throws Exception {
    addFileEntry(false);

    try {
      addFileEntry(false);

      Assert.fail("Able to add two files of the same name");
    } catch (DuplicateFileException dfe) {
    }

    try {
      addFileEntry(true);

      DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());
    } catch (DuplicateFileException dfe) {
      Assert.fail("Unable to add two files of the same name in different " + "folders");
    }

    _fileEntry = null;
  }
  @Test
  public void testAsstTags() throws Exception {
    long folderId = parentFolder.getFolderId();
    String name = "TestTags.txt";
    String description = StringPool.BLANK;
    String changeLog = StringPool.BLANK;
    byte[] bytes = CONTENT.getBytes();

    ServiceContext serviceContext = new ServiceContext();

    serviceContext.setAddGroupPermissions(true);
    serviceContext.setAddGuestPermissions(true);
    serviceContext.setScopeGroupId(group.getGroupId());

    String[] assetTagNames = new String[] {"hello", "world"};

    serviceContext.setAssetTagNames(assetTagNames);

    FileEntry fileEntry =
        DLAppServiceUtil.addFileEntry(
            group.getGroupId(),
            folderId,
            name,
            ContentTypes.TEXT_PLAIN,
            name,
            description,
            changeLog,
            bytes,
            serviceContext);

    AssetEntry assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", false);

    assetTagNames = new String[] {"hello", "world", "liferay"};

    serviceContext.setAssetTagNames(assetTagNames);

    fileEntry =
        DLAppServiceUtil.updateFileEntry(
            fileEntry.getFileEntryId(),
            name,
            ContentTypes.TEXT_PLAIN,
            name,
            description,
            changeLog,
            false,
            bytes,
            serviceContext);

    assetEntry =
        AssetEntryLocalServiceUtil.fetchEntry(
            DLFileEntryConstants.getClassName(), fileEntry.getFileEntryId());

    AssertUtils.assertEqualsSorted(assetTagNames, assetEntry.getTagNames());

    Thread.sleep(1000 * TestPropsValues.JUNIT_DELAY_FACTOR);

    _fileEntry = fileEntry;

    search(_fileEntry, false, "hello", true);
    search(_fileEntry, false, "world", true);
    search(_fileEntry, false, "liferay", true);

    DLAppServiceUtil.deleteFileEntry(_fileEntry.getFileEntryId());

    _fileEntry = null;
  }