Skip to content

Commit

Permalink
#30604: fixing HTMLPageAssetRenderedAPIImplTest flaky tests (#30605)
Browse files Browse the repository at this point in the history
  • Loading branch information
victoralfaro-dotcms authored Nov 7, 2024
1 parent 4271248 commit 8f9083f
Showing 1 changed file with 5 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.dotmarketing.business.PermissionAPI;
import com.dotmarketing.business.PermissionLevel;
import com.dotmarketing.business.UserAPI;
import com.dotmarketing.business.VersionableAPI;
import com.dotmarketing.business.web.HostWebAPI;
import com.dotmarketing.business.web.LanguageWebAPI;
import com.dotmarketing.cms.urlmap.URLMapAPIImpl;
Expand All @@ -15,27 +14,22 @@
import com.dotmarketing.exception.DotDataException;
import com.dotmarketing.exception.DotRuntimeException;
import com.dotmarketing.exception.DotSecurityException;
import com.dotmarketing.filters.Constants;
import com.dotmarketing.portlets.contentlet.business.HostAPI;
import com.dotmarketing.portlets.contentlet.model.Contentlet;
import com.dotmarketing.portlets.contentlet.model.ContentletVersionInfo;
import com.dotmarketing.portlets.htmlpageasset.business.HTMLPageAssetAPI;
import com.dotmarketing.portlets.htmlpageasset.model.HTMLPageAsset;
import com.dotmarketing.portlets.htmlpageasset.model.IHTMLPage;
import com.dotmarketing.portlets.languagesmanager.business.LanguageAPI;
import com.dotmarketing.portlets.languagesmanager.model.Language;
import com.dotmarketing.util.PageMode;
import com.dotmarketing.util.WebKeys;
import com.liferay.portal.model.User;
import java.util.Optional;
import javax.servlet.http.HttpServletResponse;
import org.junit.Before;
import org.junit.Test;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.Optional;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand All @@ -56,9 +50,9 @@ public class HTMLPageAssetRenderedAPIImplTest {
private final LanguageAPI languageAPI = mock(LanguageAPI.class);
private final HTMLPageAssetAPI htmlPageAssetAPI = mock(HTMLPageAssetAPI.class);
private final HttpSession httpSession = mock(HttpSession.class);
private HTMLPageAssetRenderedAPIImpl hTMLPageAssetRenderedAPIImpl;
private final URLMapAPIImpl urlMapAPIImpl = mock(URLMapAPIImpl.class);
private final LanguageWebAPI languageWebAPI = mock(LanguageWebAPI.class);
private HTMLPageAssetRenderedAPIImpl hTMLPageAssetRenderedAPIImpl;

@Before
public void init() throws DotDataException, DotSecurityException {
Expand All @@ -73,6 +67,7 @@ public void init() throws DotDataException, DotSecurityException {

when(languageAPI.getDefaultLanguage()).thenReturn(DEFAULT_LANGUAGE);
when(DEFAULT_LANGUAGE.getId()).thenReturn(1l);
when(languageWebAPI.getLanguage(any(HttpServletRequest.class))).thenReturn(DEFAULT_LANGUAGE);

hTMLPageAssetRenderedAPIImpl = new HTMLPageAssetRenderedAPIImpl(
permissionAPI, userAPI, hostWebAPI, languageAPI, htmlPageAssetAPI,
Expand Down Expand Up @@ -103,8 +98,6 @@ public void testShouldReturnPREVIEWMODE_whenPageIsNotLockAndUserHaveReadPermissi

when(this.hostWebAPI.getCurrentHost(request, systemUser)).thenReturn(currentHost);

when(languageWebAPI.getLanguage(request)).thenReturn(DEFAULT_LANGUAGE);

final PageMode defaultEditPageMode =
hTMLPageAssetRenderedAPIImpl.getDefaultEditPageMode(user, request, pageUri);

Expand Down Expand Up @@ -200,7 +193,7 @@ public void testShouldDoAURLMapper_whenPageIsNotFoundByURI()
when(htmlPageAssetAPI.getPageByPath(pageUri, currentHost, DEFAULT_LANGUAGE.getId(),
PageMode.PREVIEW_MODE.showLive)).thenReturn(htmlPage);

when(languageWebAPI.getLanguage(request)).thenReturn(language);
when(languageWebAPI.getLanguage(any(HttpServletRequest.class))).thenReturn(language);

when(urlMapInfo.getContentlet()).thenReturn(contentlet);
when(urlMapInfo.getIdentifier()).thenReturn(identifier);
Expand Down

0 comments on commit 8f9083f

Please sign in to comment.