Skip to content

Commit

Permalink
LPS-132769 Test if group cannot be determine response is forwarded to…
Browse files Browse the repository at this point in the history
… localized 404 page.
  • Loading branch information
lfbesada authored and brianchandotcom committed Jun 23, 2021
1 parent 70bb903 commit acf97f9
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
package com.liferay.portal.servlet.test;

import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.language.Language;
import com.liferay.portal.kernel.model.Group;
import com.liferay.portal.kernel.model.GroupConstants;
import com.liferay.portal.kernel.service.GroupLocalService;
import com.liferay.portal.kernel.test.ReflectionTestUtil;
import com.liferay.portal.kernel.test.rule.AggregateTestRule;
import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
import com.liferay.portal.kernel.test.util.CompanyTestUtil;
Expand Down Expand Up @@ -267,6 +269,45 @@ public void testModifiedGroupI18nData() throws Exception {
_testIsNotDefaultOrFirstI18nData(_group, LocaleUtil.US, LocaleUtil.UK);
}

@Test
public void testResponseIsForwardedToLocalized404PageIfGroupNotFound()
throws Exception {

String layoutFriendlyUrlPageNotFound = "/web/guest/page-404";

ReflectionTestUtil.setFieldValue(
PropsValues.class, "LAYOUT_FRIENDLY_URL_PAGE_NOT_FOUND",
layoutFriendlyUrlPageNotFound);

String expectedI18nErrorPath =
StringPool.SLASH + LocaleUtil.SPAIN.getLanguage();

MockHttpServletRequest mockHttpServletRequest =
new MockHttpServletRequest();

mockHttpServletRequest.setServletPath(expectedI18nErrorPath);

mockHttpServletRequest.setAttribute(
WebKeys.COMPANY_ID, _group.getCompanyId());

mockHttpServletRequest.setPathInfo(
StringBundler.concat(
PropsValues.LAYOUT_FRIENDLY_URL_PRIVATE_USER_SERVLET_MAPPING,
"/nonexistingfriendlyurl", RandomTestUtil.randomString()));

MockHttpServletResponse mockHttpServletResponse =
new MockHttpServletResponse();

service(mockHttpServletRequest, mockHttpServletResponse);

Assert.assertEquals(
expectedI18nErrorPath + layoutFriendlyUrlPageNotFound,
mockHttpServletResponse.getForwardedUrl());
Assert.assertEquals(
HttpServletResponse.SC_NOT_FOUND,
mockHttpServletResponse.getStatus());
}

@Test
public void testSendRedirectWithContext() throws Exception {
MockServletContext mockServletContext = new MockServletContext();
Expand Down

0 comments on commit acf97f9

Please sign in to comment.