Skip to content

Commit

Permalink
#27988 Adding HTMLPageAssetRenderedAPIImplIntegrationTest inside a Ma… (
Browse files Browse the repository at this point in the history
#28217)

* #27988 Adding HTMLPageAssetRenderedAPIImplIntegrationTest inside a MainSuite2b

* Fixing test

* Add Task230630CreateRunningIdsExperimentFieldIntegrationTest to the MainSuite

* Fixing test

* Fixing test

* Fixing test

* Fixing test

* Shooting arrows :D

* Shooting arrow again

* Fixing

* Fixing test

* Removing line
  • Loading branch information
freddyDOTCMS authored Apr 22, 2024
1 parent 957cf98 commit 3888ce3
Show file tree
Hide file tree
Showing 6 changed files with 286 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.dotcms.experiments.business.ConfigExperimentUtil;
import com.dotcms.experiments.business.web.ExperimentWebAPI;
import com.dotcms.experiments.model.Experiment;
import com.dotcms.mock.request.MockAttributeRequest;
import com.dotcms.mock.request.MockRequest;
import com.dotcms.rendering.velocity.services.PageLoader;
import com.dotcms.repackage.com.google.common.annotations.VisibleForTesting;
import com.dotcms.variant.business.web.VariantWebAPI.RenderContext;
Expand Down Expand Up @@ -599,19 +601,41 @@ public PageLivePreviewVersionBean getPageRenderedLivePreviewVersion (final Strin
new PageLoader().invalidate(page, PageMode.EDIT_MODE, PageMode.PREVIEW_MODE);
final Host host = this.hostWebAPI.find(pageIdentifier.getHostId(), user, false);

final HttpServletRequest wrapRequestLiveMode = new DiffMockRequest(request);
wrapRequestLiveMode.setAttribute(WebKeys.PAGE_MODE_PARAMETER, PageMode.LIVE);

final String renderLive = HTMLPageAssetRendered.class.cast(new HTMLPageAssetRenderedBuilder()
.setHtmlPageAsset(page).setUser(user)
.setRequest(request).setResponse(response)
.setRequest(wrapRequestLiveMode).setResponse(response)
.setSite(host).setURLMapper(pageURI)
.setLive(true).build(true, PageMode.LIVE)).getHtml();

final HttpServletRequest wrapRequestPreviewMode = new DiffMockRequest(request);
wrapRequestPreviewMode.setAttribute(WebKeys.PAGE_MODE_PARAMETER, PageMode.PREVIEW_MODE);

final String renderWorking = HTMLPageAssetRendered.class.cast(new HTMLPageAssetRenderedBuilder()
.setHtmlPageAsset(page).setUser(user)
.setRequest(request).setResponse(response)
.setRequest(wrapRequestPreviewMode).setResponse(response)
.setSite(host).setURLMapper(pageURI)
.setLive(false).build(true, PageMode.PREVIEW_MODE)).getHtml();

return new PageLivePreviewVersionBean(renderLive, renderWorking);
}

private static class DiffMockRequest extends MockAttributeRequest {
public DiffMockRequest(HttpServletRequest request) {
super(request);
}

@Override
public String getParameter(String name) {
if (WebKeys.PAGE_MODE_PARAMETER.equals(name)) {
return null;
}

return super.getParameter(name);
}


}
}
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public PageView build(final boolean rendered, final PageMode mode) throws DotDat
final Collection<? extends ContainerRaw> containers = new ContainerRenderedBuilder(
pageRenderUtil.getContainersRaw(), velocityContext, mode)
.build();
final String pageHTML = this.getPageHTML();
final String pageHTML = this.getPageHTML(mode);

final HTMLPageAssetRendered.RenderedBuilder pageViewBuilder = new HTMLPageAssetRendered.RenderedBuilder().html(pageHTML);
pageViewBuilder.site(site).template(template).containers(containers)
Expand Down Expand Up @@ -214,12 +214,6 @@ private Optional<Contentlet> findUrlContentlet(final HttpServletRequest request)
return Optional.ofNullable(contentlet);
}

public String getPageHTML() throws DotSecurityException {

final PageMode mode = PageMode.get(request);

return getPageHTML(mode);
}

@CloseDBIfOpened
public String getPageHTML(final PageMode pageMode) throws DotSecurityException {
Expand Down
6 changes: 5 additions & 1 deletion dotcms-integration/src/test/java/com/dotcms/MainSuite2b.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
import com.dotmarketing.portlets.contentlet.business.ContentletCacheImplTest;
import com.dotmarketing.portlets.contentlet.model.ContentletDependenciesTest;
import com.dotmarketing.portlets.folders.business.FolderFactoryImplTest;
import com.dotmarketing.portlets.htmlpages.business.render.HTMLPageAssetRenderedAPIImplIntegrationTest;
import com.dotmarketing.portlets.templates.business.FileAssetTemplateUtilTest;
import com.dotmarketing.portlets.workflows.actionlet.MoveContentActionletTest;
import com.dotmarketing.portlets.workflows.actionlet.SaveContentAsDraftActionletIntegrationTest;
Expand Down Expand Up @@ -155,6 +156,7 @@
import com.dotmarketing.startup.runonce.Task240102AlterVarcharLengthOfRelationTypeTest;
import com.dotmarketing.startup.runonce.Task240111AddInodeAndIdentifierLeftIndexesTest;
import com.dotmarketing.startup.runonce.Task240112AddMetadataColumnToStructureTableTest;
import com.dotmarketing.startup.runonce.Task230630CreateRunningIdsExperimentFieldIntegrationTest;
import com.dotmarketing.util.MaintenanceUtilTest;
import com.dotmarketing.util.ResourceCollectorUtilTest;
import com.dotmarketing.util.UtilMethodsITest;
Expand All @@ -170,6 +172,9 @@
@SuiteClasses({
Task220825CreateVariantFieldTest.class,
Task221007AddVariantIntoPrimaryKeyTest.class,
com.dotcms.rest.api.v1.template.TemplateResourceTest.class,
Task230630CreateRunningIdsExperimentFieldIntegrationTest.class,
HTMLPageAssetRenderedAPIImplIntegrationTest.class,
Task05380ChangeContainerPathToAbsoluteTest.class,
DotTemplateToolTest.class,
Task05370AddAppsPortletToLayoutTest.class,
Expand All @@ -190,7 +195,6 @@
Task201013AddNewColumnsToIdentifierTableTest.class,
Task201014UpdateColumnsValuesInIdentifierTableTest.class,
AppsInterpolationTest.class,
com.dotcms.rest.api.v1.template.TemplateResourceTest.class,
Task201102UpdateColumnSitelicTableTest.class,
DependencyManagerTest.class,
com.dotcms.rest.api.v1.versionable.VersionableResourceTest.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,9 @@ public void testRenderWithContent() throws DotDataException, DotSecurityExceptio
@Test
public void shouldReturnPageByURLPattern()
throws DotDataException, DotSecurityException, InterruptedException, SystemException, PortalException {

when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

HttpServletRequestThreadLocal.INSTANCE.setRequest(request);

final String baseUrl = String.format("/test%s", System.currentTimeMillis());
Expand Down Expand Up @@ -747,7 +750,7 @@ public void testRenderNotPersonalizationVersion()
throws DotDataException, DotSecurityException, SystemException, PortalException {
final String modeParam = "PREVIEW_MODE";
when(request.getAttribute(WebKeys.PAGE_MODE_PARAMETER)).thenReturn(PageMode.get(modeParam));
when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(APILocator.systemUser());
when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

final Language defaultLang = APILocator.getLanguageAPI().getDefaultLanguage();
final long languageId = defaultLang.getId();
Expand Down Expand Up @@ -784,6 +787,9 @@ public void testRenderNotPersonalizationVersion()
@Test
public void testRenderPersonalizationVersion()
throws DotDataException, DotSecurityException, SystemException, PortalException {

when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

final Language defaultLang = APILocator.getLanguageAPI().getDefaultLanguage();
final long languageId = defaultLang.getId();

Expand Down Expand Up @@ -1127,6 +1133,9 @@ private PageContainerForm createPageContainerForm(final String containerId, fina
@Test
public void testOnNumberOfPagesDataAttribute_render() throws DotDataException, SystemException, DotSecurityException,
PortalException {

when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

// Initialization
final String modeParam = "EDIT_MODE";
final Language defaultLang = APILocator.getLanguageAPI().getDefaultLanguage();
Expand Down Expand Up @@ -1157,6 +1166,8 @@ public void testOnNumberOfPagesDataAttribute_render() throws DotDataException, S
*/
@Test
public void testCleanUpSessionWhenDeviceInodeIsNull() throws Exception {
when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

pageResource.render(request, response, pagePath, null, null, APILocator.getLanguageAPI().getDefaultLanguage().getLanguage(), null);

verify(session).removeAttribute(WebKeys.CURRENT_DEVICE);
Expand All @@ -1171,6 +1182,8 @@ public void testCleanUpSessionWhenDeviceInodeIsNull() throws Exception {
*/
@Test
public void testCleanUpSessionWhenDeviceInodeIsBlank() throws Exception {
when(request.getAttribute(com.liferay.portal.util.WebKeys.USER)).thenReturn(user);

pageResource.render(request, response, pagePath, null, null, APILocator.getLanguageAPI().getDefaultLanguage().getLanguage(), "");

verify(session).removeAttribute(WebKeys.CURRENT_DEVICE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,6 @@ public void legacyUUIDTemplate() throws DotDataException, DotSecurityException,
templateFromDaBaseBeforeUpdate.getDrawedBody());
assertTrue(templateLayoutBeforeUpdate.existsContainer(container, uuid));

//Thread.sleep(10000);
templateResource.save(request, response, templateForm);

final Template templateFromDaBaseAfterUpdate = APILocator.getTemplateAPI()
Expand All @@ -1250,13 +1249,8 @@ public void legacyUUIDTemplate() throws DotDataException, DotSecurityException,
templateFromDaBaseAfterUpdate.getDrawedBody());
assertTrue(templateLayoutAfterUpdate.existsContainer(container, "1"));

System.out.println("SECOND TIME------------------------");

final String pageHtml_2 = APILocator.getHTMLPageAssetRenderedAPI()
.getPageHtml(pageContext, request, response);
assertTrue(pageHtml_2.contains("<div>Testing</div>"));



}
}
Loading

0 comments on commit 3888ce3

Please sign in to comment.