Skip to content

Commit

Permalink
LPD-31506 Migrate ExportImportMastersPageTemplateWithThumbnail to int…
Browse files Browse the repository at this point in the history
…egration test
  • Loading branch information
ealonso authored and brianchandotcom committed Aug 15, 2024
1 parent 9a26328 commit af82692
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 57 deletions.
1 change: 1 addition & 0 deletions modules/apps/layout/layout-page-template-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies {
testIntegrationImplementation group: "com.fasterxml.jackson.core", name: "jackson-databind", version: "2.16.1"
testIntegrationImplementation group: "com.github.everit-org.json-schema", name: "org.everit.json.schema", version: "1.11.1"
testIntegrationImplementation group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "default"
testIntegrationImplementation group: "commons-io", name: "commons-io", version: "2.15.1"
testIntegrationImplementation group: "javax.portlet", name: "portlet-api", version: "3.0.1"
testIntegrationImplementation group: "javax.ws.rs", name: "javax.ws.rs-api", version: "2.1"
testIntegrationImplementation project(":apps:asset:asset-display-page-api")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
import com.liferay.fragment.contributor.FragmentCollectionContributor;
import com.liferay.fragment.model.FragmentEntry;
import com.liferay.fragment.service.FragmentEntryLocalServiceUtil;
import com.liferay.layout.exporter.LayoutsExporter;
import com.liferay.layout.importer.LayoutsImportStrategy;
import com.liferay.layout.importer.LayoutsImporter;
import com.liferay.layout.importer.LayoutsImporterResultEntry;
import com.liferay.layout.page.template.constants.LayoutPageTemplateConstants;
import com.liferay.layout.page.template.constants.LayoutPageTemplateEntryTypeConstants;
import com.liferay.layout.page.template.constants.LayoutPageTemplateExportImportConstants;
import com.liferay.layout.page.template.model.LayoutPageTemplateEntry;
import com.liferay.layout.page.template.model.LayoutPageTemplateStructure;
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryLocalService;
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryService;
import com.liferay.layout.page.template.service.LayoutPageTemplateStructureLocalService;
import com.liferay.layout.util.structure.DropZoneLayoutStructureItem;
import com.liferay.layout.util.structure.LayoutStructure;
Expand All @@ -24,7 +28,10 @@
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.Repository;
import com.liferay.portal.kernel.model.User;
import com.liferay.portal.kernel.portletfilerepository.PortletFileRepositoryUtil;
import com.liferay.portal.kernel.repository.model.FileEntry;
import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
import com.liferay.portal.kernel.test.TestInfo;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
Expand All @@ -33,11 +40,13 @@
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.FileUtil;
import com.liferay.portal.kernel.util.HashMapBuilder;
import com.liferay.portal.kernel.util.ListUtil;
import com.liferay.portal.kernel.util.LocaleUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.workflow.WorkflowConstants;
import com.liferay.portal.kernel.zip.ZipWriter;
import com.liferay.portal.kernel.zip.ZipWriterFactory;
import com.liferay.portal.test.rule.Inject;
Expand All @@ -58,6 +67,8 @@
import java.util.Locale;
import java.util.Map;

import org.apache.commons.io.IOUtils;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
Expand Down Expand Up @@ -107,6 +118,71 @@ public void tearDown() {
_serviceRegistration.unregister();
}

@Test
@TestInfo("LPS-102207")
public void testExportImportMasterLayoutsWithThumbnail() throws Exception {
LayoutPageTemplateEntry layoutPageTemplateEntry =
_layoutPageTemplateEntryLocalService.addLayoutPageTemplateEntry(
null, TestPropsValues.getUserId(), _group.getGroupId(),
LayoutPageTemplateConstants.
PARENT_LAYOUT_PAGE_TEMPLATE_COLLECTION_ID_DEFAULT,
RandomTestUtil.randomString(),
LayoutPageTemplateEntryTypeConstants.MASTER_LAYOUT, 0,
WorkflowConstants.STATUS_APPROVED,
ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

Repository repository = PortletFileRepositoryUtil.addPortletRepository(
_group.getGroupId(), RandomTestUtil.randomString(),
ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

Class<?> clazz = getClass();

FileEntry fileEntry = PortletFileRepositoryUtil.addPortletFileEntry(
null, _group.getGroupId(), TestPropsValues.getUserId(),
LayoutPageTemplateEntry.class.getName(),
layoutPageTemplateEntry.getLayoutPageTemplateEntryId(),
RandomTestUtil.randomString(), repository.getDlFolderId(),
clazz.getResourceAsStream("dependencies/thumbnail.png"),
"thumbnail.png", ContentTypes.IMAGE_PNG, false);

InputStream inputStream = fileEntry.getContentStream();

_layoutPageTemplateEntryLocalService.updateLayoutPageTemplateEntry(
layoutPageTemplateEntry.getLayoutPageTemplateEntryId(),
fileEntry.getFileEntryId());

File file = _layoutsExporter.exportLayoutPageTemplateEntries(
new long[] {layoutPageTemplateEntry.getLayoutPageTemplateEntryId()},
LayoutPageTemplateEntryTypeConstants.MASTER_LAYOUT);

_layoutPageTemplateEntryLocalService.deleteLayoutPageTemplateEntry(
layoutPageTemplateEntry.getLayoutPageTemplateEntryId());

Assert.assertEquals(
0,
_layoutPageTemplateEntryService.getLayoutPageTemplateEntriesCount(
_group.getGroupId(),
LayoutPageTemplateEntryTypeConstants.MASTER_LAYOUT));

List<LayoutsImporterResultEntry> layoutsImporterResultEntries =
_getLayoutsImporterResultEntries(file);

Assert.assertEquals(
layoutsImporterResultEntries.toString(), 1,
layoutsImporterResultEntries.size());

LayoutPageTemplateEntry importedLayoutPageTemplateEntry =
_getLayoutPageTemplateEntry(layoutsImporterResultEntries, 0);

FileEntry importedFileEntry =
PortletFileRepositoryUtil.getPortletFileEntry(
importedLayoutPageTemplateEntry.getPreviewFileEntryId());

Assert.assertTrue(
IOUtils.contentEquals(
inputStream, importedFileEntry.getContentStream()));
}

@Test
public void testImportMasterLayoutDropZone() throws Exception {
LayoutPageTemplateEntry layoutPageTemplateEntry =
Expand Down Expand Up @@ -319,13 +395,11 @@ private LayoutPageTemplateEntry _getLayoutPageTemplateEntry(
}

private List<LayoutsImporterResultEntry> _getLayoutsImporterResultEntries(
String testCaseName)
File file)
throws Exception {

List<LayoutsImporterResultEntry> layoutsImporterResultEntries = null;

File file = _generateZipFile(testCaseName);

ServiceContextThreadLocal.pushServiceContext(
ServiceContextTestUtil.getServiceContext(_group.getGroupId()));

Expand All @@ -343,6 +417,13 @@ private List<LayoutsImporterResultEntry> _getLayoutsImporterResultEntries(
return layoutsImporterResultEntries;
}

private List<LayoutsImporterResultEntry> _getLayoutsImporterResultEntries(
String testCaseName)
throws Exception {

return _getLayoutsImporterResultEntries(_generateZipFile(testCaseName));
}

private LayoutPageTemplateEntry _importLayoutPageTemplateEntry(
String testCaseName)
throws Exception {
Expand Down Expand Up @@ -445,10 +526,16 @@ private void _validateLayoutPageTemplateStructureDropZone(
private LayoutPageTemplateEntryLocalService
_layoutPageTemplateEntryLocalService;

@Inject
private LayoutPageTemplateEntryService _layoutPageTemplateEntryService;

@Inject
private LayoutPageTemplateStructureLocalService
_layoutPageTemplateStructureLocalService;

@Inject
private LayoutsExporter _layoutsExporter;

@Inject
private LayoutsImporter _layoutsImporter;

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -549,60 +549,6 @@ definition {
}
}

@description = "This is a use case for LPS-102207. Can export a master page template with the thumbnail and import."
@priority = 4
test ExportImportMastersPageTemplateWithThumbnail {
task ("Add a custom master") {
JSONLayoutpagetemplate.addMasterPageTemplateEntry(
groupName = "Test Site Name",
masterPageTemplateEntryName = "Custom Masters Page Template");

MastersPageTemplatesAdmin.openMastersAdmin(siteURLKey = "test-site-name");

MastersPageTemplatesAdmin.gotoMasters(masterLayoutName = "Custom Masters Page Template");

MastersPageTemplates.publishMaster();
}

task ("Change thumbnail of custom master") {
MastersPageTemplatesAdmin.openMastersAdmin(siteURLKey = "test-site-name");

MastersPageTemplatesAdmin.gotoMastersEllipsisItem(
item = "Change Thumbnail",
masterLayoutName = "Custom Masters Page Template");

ItemSelector.uploadFile(uploadFileName = "Document_1.png");

LexiconCard.viewCardThumbnail(card = "Custom Masters Page Template");

SelectFrameTop(value1 = "relative=top");
}

task ("Export custom master") {
MastersPageTemplatesAdmin.openMastersAdmin(siteURLKey = "test-site-name");

MastersPageTemplatesAdmin.gotoMastersEllipsisItem(
item = "Export",
masterLayoutName = "Custom Masters Page Template");

DownloadTempFile();
}

task ("Import masters page template in new site") {
HeadlessSite.addSite(siteName = "Site Name");

MastersPageTemplatesAdmin.openMastersAdmin(siteURLKey = "site-name");

MastersPageTemplatesAdmin.importMastersFromTempFolder();
}

task ("Assert the thumbnail of custom master is imported") {
MastersPageTemplatesAdmin.viewMastersPresent(masterLayoutName = "Custom Masters Page Template");

LexiconCard.viewCardThumbnail(card = "Custom Masters Page Template");
}
}

@description = "This is a use case for LPS-102207. The existing entry will be overwriten when import a master page template with thumbnail if check Overwrite Existing Entries."
@priority = 4
test OverwriteExistingEntryWithThumbnailIfCheckOverwriteExistingEntries {
Expand Down

0 comments on commit af82692

Please sign in to comment.