Skip to content

Commit

Permalink
LPD-27912 Migrate to integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adolfopa authored and brianchandotcom committed Sep 20, 2024
1 parent 2004d65 commit bd83dba
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 98 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,30 @@
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.document.library.app.service.test.util.DLAppServiceTestUtil;
import com.liferay.document.library.kernel.exception.NoSuchFileEntryException;
import com.liferay.document.library.kernel.model.DLFileEntry;
import com.liferay.document.library.kernel.model.DLFileVersion;
import com.liferay.document.library.kernel.model.DLFolderConstants;
import com.liferay.document.library.kernel.service.DLFileEntryLocalServiceUtil;
import com.liferay.document.library.kernel.service.DLFileVersionLocalServiceUtil;
import com.liferay.document.library.test.util.BaseDLAppTestCase;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.model.role.RoleConstants;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.repository.model.FileVersion;
import com.liferay.portal.kernel.service.RoleLocalServiceUtil;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
import com.liferay.portal.kernel.test.util.UserTestUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

import java.util.Date;

import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -32,6 +48,53 @@ public class DLAppServiceWhenGettingAFileEntryTest extends BaseDLAppTestCase {
public static final AggregateTestRule aggregateTestRule =
new LiferayIntegrationTestRule();

@Before
public void setUp() throws Exception {
super.setUp();

_contentReviewerUser = UserTestUtil.addUser(group.getGroupId());

RoleLocalServiceUtil.addUserRole(
_contentReviewerUser.getUserId(),
RoleLocalServiceUtil.getRole(
_contentReviewerUser.getCompanyId(),
RoleConstants.PORTAL_CONTENT_REVIEWER));

_siteMemberUser = UserTestUtil.addUser(group.getGroupId());
}

@Test
public void testGetExpiredFileEntryAsContentReviewer() throws Exception {
FileEntry fileEntry = DLAppServiceTestUtil.addFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

_expireFileEntry(fileEntry);

UserTestUtil.setUser(_contentReviewerUser);

fileEntry = dlAppService.getFileEntry(fileEntry.getFileEntryId());

FileVersion fileVersion = fileEntry.getFileVersion();

Assert.assertTrue(fileVersion.isExpired());
}

@Test
public void testGetExpiredFileEntryAsOwner() throws Exception {
UserTestUtil.setUser(_siteMemberUser);

FileEntry fileEntry = DLAppServiceTestUtil.addFileEntry(
group.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID);

_expireFileEntry(fileEntry);

fileEntry = dlAppService.getFileEntry(fileEntry.getFileEntryId());

FileVersion fileVersion = fileEntry.getFileVersion();

Assert.assertTrue(fileVersion.isExpired());
}

@Test(expected = NoSuchFileEntryException.class)
public void testShouldFailIfNotPresentInRootFolder() throws Exception {
dlAppService.getFileEntry(
Expand All @@ -52,4 +115,35 @@ public void testShouldReturnItIfExistsInRootFolder() throws Exception {
fileEntry1.getFileEntryId(), fileEntry2.getFileEntryId());
}

private void _expireFileEntry(FileEntry fileEntry) throws Exception {
LocalDateTime localDateTime = LocalDateTime.now();

LocalDateTime expirationLocalDateTime = localDateTime.minusMinutes(1);

Date expirationDate = Date.from(
expirationLocalDateTime.toInstant(ZoneOffset.UTC));

DLFileEntry dlFileEntry = (DLFileEntry)fileEntry.getModel();

dlFileEntry.setExpirationDate(expirationDate);

dlFileEntry = DLFileEntryLocalServiceUtil.updateDLFileEntry(
dlFileEntry);

DLFileVersion dlFileVersion = dlFileEntry.getFileVersion();

dlFileVersion.setExpirationDate(expirationDate);

DLFileVersionLocalServiceUtil.updateDLFileVersion(dlFileVersion);

DLFileEntryLocalServiceUtil.checkFileEntries(
dlFileEntry.getCompanyId(), 60);
}

@DeleteAfterTestRun
private User _contentReviewerUser;

@DeleteAfterTestRun
private User _siteMemberUser;

}
Original file line number Diff line number Diff line change
Expand Up @@ -3448,104 +3448,6 @@ definition {
DMDocument.viewCategories(categoryNameList = "Apple,Dragon Fruit");
}

@description = "This test ensures that the user can view an expired document."
@priority = 4
test CanViewExpiredDocument {
property custom.properties = "company.default.time.zone=America/Los_Angeles";
property test.liferay.virtual.instance = "false";
property test.run.type = "single";

DMDocument.updateCheckInterval(fieldValue = 1);

DMNavigator.openToAddEntry(
groupName = "Guest",
siteURLKey = "guest");

WaitForPageLoad();

DMDocument.editDocument(
dmDocumentDescription = "DM Document Description",
dmDocumentFile = "Document_1.txt",
dmDocumentTitle = "Document_1.txt");

DMDocument.setExpirationDate(
enableExpirationDate = "true",
increaseMinutes = 1);

Navigator.openURL();

Notifications.waitForNotificationFlexibly(flexibleRefreshingTime = 20000);

Notifications.viewBadgeCount(notificationCount = 1);

Notifications.gotoNotifications();

Notifications.viewExpiredContent(contentBody = "Document_1.txt");

DMNavigator.openDocumentsAndMediaAdmin(siteURLKey = "guest");

DMDocument.viewStatus(
dmDocumentStatus = "Expired",
dmDocumentTitle = "Document_1.txt");
}

@description = "This test ensures that a user who has content review permissions can see an expired document."
@priority = 4
test CanViewExpiredDocumentAsContentReviewer {
property custom.properties = "company.default.time.zone=America/Los_Angeles${line.separator}jsonws.web.service.paths.excludes=";
property test.liferay.virtual.instance = "false";
property test.run.type = "single";

JSONUser.addUser(
userEmailAddress = "[email protected]",
userFirstName = "userfn",
userLastName = "userln",
userScreenName = "usersn");

JSONUser.setFirstPassword(
agreeToTermsAndAnswerReminderQuery = "true",
requireReset = "false",
userEmailAddress = "[email protected]");

JSONRole.assignRoleToUser(
roleTitle = "Portal Content Reviewer",
userEmailAddress = "[email protected]");

JSONDocument.addFileWithUploadedFile(
dmDocumentDescription = "DM Document Description",
dmDocumentTitle = "Document_5.txt",
groupName = "Guest",
mimeType = "text/plain",
sourceFileName = "Document_5.txt");

DMDocument.updateCheckInterval(fieldValue = 1);

DMNavigator.openToEditEntryInSite(
dmDocumentTitle = "Document_5.txt",
groupName = "Guest",
siteURLKey = "guest");

WaitForPageLoad();

DMDocument.setExpirationDate(
enableExpirationDate = "true",
increaseMinutes = 1);

// We need to wait for the system time to pass by 2 minutes in order to verify the document is expired. There is currently no easy way to manipulate the system time in CI for automation. 2 minutes is the shortest value we can set while ensuring the stability of the test. See LPS-157957.

Pause(value1 = 120000);

User.logoutAndLoginPG(
userLoginEmailAddress = "[email protected]",
userLoginFullName = "userfn userln");

Navigator.gotoPage(pageName = "Documents and Media Page");

DMDocument.viewStatus(
dmDocumentStatus = "Expired",
dmDocumentTitle = "Document_5.txt");
}

@description = "This test ensures that users can view generic error when bulk copy more than ten wrong files."
@priority = 4
test CanViewGenericErrorWhenBulkCopyMoreThanTenWrongFiles {
Expand Down

0 comments on commit bd83dba

Please sign in to comment.