Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LPS-84716 Fixing test #62381

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -14,11 +14,15 @@

package com.liferay.document.library.service.test;

import static com.liferay.document.library.service.test.DLAppServiceTest.addFileEntry;

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.document.library.kernel.exception.NoSuchFileEntryException;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLAppLocalServiceUtil;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.Folder;
import com.liferay.portal.kernel.service.ServiceContext;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
Expand All @@ -27,7 +31,10 @@
import com.liferay.portal.kernel.test.util.RandomTestUtil;
import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
import com.liferay.portal.kernel.test.util.TestPropsValues;
import com.liferay.portal.kernel.util.ContentTypes;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
import com.liferay.portlet.documentlibrary.service.test.BaseDLAppTestCase;
import com.liferay.subscription.model.Subscription;
import com.liferay.subscription.service.SubscriptionLocalServiceUtil;

Expand Down Expand Up @@ -96,4 +103,38 @@ public void shouldDeleteSubscriptions() throws Exception {

}

@RunWith(Arquillian.class)
public static class WhenGettingAFileEntry extends BaseDLAppTestCase {

@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new LiferayIntegrationTestRule();

@Test(expected = NoSuchFileEntryException.class)
public void shouldFailIfNotPresentInRootFolder() throws Exception {
DLAppLocalServiceUtil.getFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
StringUtil.randomString());
}

@Test
public void shouldReturnItIfExistsInRootFolder() throws Exception {
FileEntry fileEntry1 = DLAppLocalServiceUtil.addFileEntry(
TestPropsValues.getUserId(), group.getGroupId(),
DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
StringUtil.randomString(),
ContentTypes.APPLICATION_OCTET_STREAM, new byte[0],
ServiceContextTestUtil.getServiceContext(group.getGroupId()));

FileEntry fileEntry2 = DLAppLocalServiceUtil.getFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
fileEntry1.getTitle());

Assert.assertEquals(
fileEntry1.getFileEntryId(), fileEntry2.getFileEntryId());
}

}

}
Expand Up @@ -21,6 +21,7 @@
import com.liferay.document.library.kernel.exception.FileExtensionException;
import com.liferay.document.library.kernel.exception.FileNameException;
import com.liferay.document.library.kernel.exception.FileSizeException;
import com.liferay.document.library.kernel.exception.NoSuchFileEntryException;
import com.liferay.document.library.kernel.model.DLFileEntry;
import com.liferay.document.library.kernel.model.DLFileEntryConstants;
import com.liferay.document.library.kernel.model.DLFolderConstants;
Expand Down Expand Up @@ -921,6 +922,36 @@ public void shouldSkipExplicitlyTrashedChildFolder() throws Exception {

}

@RunWith(Arquillian.class)
public static class WhenGettingAFileEntry extends BaseDLAppTestCase {

@ClassRule
@Rule
public static final AggregateTestRule aggregateTestRule =
new LiferayIntegrationTestRule();

@Test(expected = NoSuchFileEntryException.class)
public void shouldFailIfNotPresentInRootFolder() throws Exception {
DLAppServiceUtil.getFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
StringUtil.randomString());
}

@Test
public void shouldReturnItIfExistsInRootFolder() throws Exception {
FileEntry fileEntry1 = addFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

FileEntry fileEntry2 = DLAppServiceUtil.getFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID,
fileEntry1.getTitle());

Assert.assertEquals(
fileEntry1.getFileEntryId(), fileEntry2.getFileEntryId());
}

}

@RunWith(Arquillian.class)
public static class WhenMovingAFileEntry extends BaseDLAppTestCase {

Expand Down
Expand Up @@ -556,15 +556,15 @@ public FileEntry getFileEntry(long groupId, long folderId, String title)
return localRepository.getFileEntry(folderId, title);
}
catch (NoSuchFileEntryException nsfee) {
if (_log.isDebugEnabled()) {
_log.debug(nsfee, nsfee);
if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
throw nsfee;
}
}

LocalRepository localRepository =
repositoryProvider.getFolderLocalRepository(folderId);
LocalRepository localRepository =
repositoryProvider.getFolderLocalRepository(folderId);

return localRepository.getFileEntry(folderId, title);
return localRepository.getFileEntry(folderId, title);
}
}

/**
Expand Down
Expand Up @@ -1127,15 +1127,14 @@ public FileEntry getFileEntry(long groupId, long folderId, String title)
return repository.getFileEntry(folderId, title);
}
catch (NoSuchFileEntryException nsfee) {
if (folderId != DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
Repository repository = repositoryProvider.getFolderRepository(
folderId);

return repository.getFileEntry(folderId, title);
}
else {
if (folderId == DLFolderConstants.DEFAULT_PARENT_FOLDER_ID) {
throw nsfee;
}

Repository repository = repositoryProvider.getFolderRepository(
folderId);

return repository.getFileEntry(folderId, title);
}
}

Expand Down