Skip to content

Commit

Permalink
LPD-30888 Create mock liferay portlet action request with mock multip…
Browse files Browse the repository at this point in the history
…art http servlet request because we are expecting this type of request in SaveAsDraftArticleMVCActionCommand
  • Loading branch information
Mikellorza authored and brianchandotcom committed Jul 9, 2024
1 parent ad04344 commit 105f946
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import com.liferay.layout.page.template.model.LayoutPageTemplateEntry;
import com.liferay.layout.page.template.service.LayoutPageTemplateEntryLocalService;
import com.liferay.layout.test.util.LayoutTestUtil;
import com.liferay.petra.string.StringBundler;
import com.liferay.petra.string.StringPool;
import com.liferay.portal.kernel.json.JSONFactoryUtil;
import com.liferay.portal.kernel.json.JSONObject;
import com.liferay.portal.kernel.model.Group;
Expand All @@ -37,6 +39,7 @@
import com.liferay.portal.kernel.theme.ThemeDisplay;
import com.liferay.portal.kernel.util.Portal;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringUtil;
import com.liferay.portal.kernel.util.WebKeys;
import com.liferay.portal.test.rule.Inject;
import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
Expand All @@ -52,7 +55,9 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.http.MediaType;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockMultipartHttpServletRequest;

/**
* @author Jonathan McCann
Expand Down Expand Up @@ -130,12 +135,28 @@ public void testProcessAction() throws Exception {
previewURL.contains(String.valueOf(journalArticle.getVersion())));
}

private MockMultipartHttpServletRequest
_createMockMultipartHttpServletRequest() {

MockMultipartHttpServletRequest mockMultipartHttpServletRequest =
new MockMultipartHttpServletRequest();

mockMultipartHttpServletRequest.setCharacterEncoding(StringPool.UTF8);
mockMultipartHttpServletRequest.setContentType(
StringBundler.concat(
MediaType.MULTIPART_FORM_DATA_VALUE,
"; boundary=WebKitFormBoundary", StringUtil.randomString()));

return mockMultipartHttpServletRequest;
}

private MockLiferayPortletActionRequest _getMockLiferayPortletActionRequest(
JournalArticle journalArticle)
throws Exception {

MockLiferayPortletActionRequest mockLiferayPortletActionRequest =
new MockLiferayPortletActionRequest();
new MockLiferayPortletActionRequest(
_createMockMultipartHttpServletRequest());

mockLiferayPortletActionRequest.addParameter(
"articleId", journalArticle.getArticleId());
Expand Down

0 comments on commit 105f946

Please sign in to comment.