Skip to content

Commit b9e5737

Browse files
carolmariaabbbrianchandotcom
authored andcommitted
LPD-49016 Add integration test
1 parent 7f58439 commit b9e5737

File tree

1 file changed

+43
-13
lines changed

1 file changed

+43
-13
lines changed

modules/apps/dynamic-data-mapping/dynamic-data-mapping-test/src/testIntegration/java/com/liferay/dynamic/data/mapping/form/web/internal/portlet/action/test/UploadFileEntryMVCActionCommandTest.java

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package com.liferay.dynamic.data.mapping.form.web.internal.portlet.action.test;
77

88
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
9+
import com.liferay.document.library.configuration.DLFileEntryMimeTypeConfiguration;
910
import com.liferay.document.library.kernel.model.DLFileEntry;
1011
import com.liferay.document.library.kernel.model.DLFolderConstants;
1112
import com.liferay.document.library.kernel.service.DLFileEntryLocalService;
@@ -16,6 +17,7 @@
1617
import com.liferay.petra.memory.DeleteFileFinalizeAction;
1718
import com.liferay.petra.memory.FinalizeManager;
1819
import com.liferay.petra.string.StringPool;
20+
import com.liferay.portal.configuration.test.util.CompanyConfigurationTemporarySwapper;
1921
import com.liferay.portal.kernel.json.JSONFactory;
2022
import com.liferay.portal.kernel.json.JSONObject;
2123
import com.liferay.portal.kernel.model.Group;
@@ -46,6 +48,8 @@
4648
import com.liferay.portal.kernel.upload.FileItem;
4749
import com.liferay.portal.kernel.util.ContentTypes;
4850
import com.liferay.portal.kernel.util.HashMapBuilder;
51+
import com.liferay.portal.kernel.util.HashMapDictionaryBuilder;
52+
import com.liferay.portal.kernel.util.LocaleUtil;
4953
import com.liferay.portal.kernel.util.Portal;
5054
import com.liferay.portal.kernel.util.ProxyUtil;
5155
import com.liferay.portal.kernel.util.StringUtil;
@@ -159,24 +163,12 @@ public void testProcessAction() throws Exception {
159163
_dlFileEntryLocalService.fetchDLFileEntry(
160164
_oldDLFileEntry.getFileEntryId()));
161165

162-
MockLiferayPortletActionResponse mockLiferayPortletActionResponse =
163-
new MockLiferayPortletActionResponse();
164-
165-
_mvcActionCommand.processAction(
166-
new MockLiferayPortletActionRequest(_getMockHttpServletRequest()),
167-
mockLiferayPortletActionResponse);
166+
JSONObject jsonObject = _processAction();
168167

169168
Assert.assertNull(
170169
_dlFileEntryLocalService.fetchDLFileEntry(
171170
_oldDLFileEntry.getFileEntryId()));
172171

173-
MockHttpServletResponse mockHttpServletResponse =
174-
(MockHttpServletResponse)
175-
mockLiferayPortletActionResponse.getHttpServletResponse();
176-
177-
JSONObject jsonObject = _jsonFactory.createJSONObject(
178-
mockHttpServletResponse.getContentAsString());
179-
180172
JSONObject fileJSONObject = jsonObject.getJSONObject("file");
181173

182174
DLFileEntry dlFileEntry = _dlFileEntryLocalService.fetchDLFileEntry(
@@ -201,6 +193,27 @@ public void testProcessAction() throws Exception {
201193
ActionKeys.VIEW));
202194
}
203195

196+
@Test
197+
public void testProcessActionWithInvalidMimetype() throws Exception {
198+
try (CompanyConfigurationTemporarySwapper
199+
companyConfigurationTemporarySwapper =
200+
new CompanyConfigurationTemporarySwapper(
201+
TestPropsValues.getCompanyId(),
202+
DLFileEntryMimeTypeConfiguration.class.getName(),
203+
HashMapDictionaryBuilder.<String, Object>put(
204+
"fileMimeTypes", new String[] {"image/jpeg"}
205+
).build())) {
206+
207+
JSONObject jsonObject = _processAction();
208+
209+
JSONObject errorJSONObject = jsonObject.getJSONObject("error");
210+
211+
Assert.assertEquals(
212+
"Please enter a file with a valid mime type (image/jpeg).",
213+
errorJSONObject.get("message"));
214+
}
215+
}
216+
204217
private FileItem _getFileItem() throws Exception {
205218
Path path = Files.createTempFile(null, ".txt");
206219

@@ -260,6 +273,7 @@ private MockHttpServletRequest _getMockHttpServletRequest()
260273

261274
themeDisplay.setCompany(
262275
_companyLocalService.fetchCompany(TestPropsValues.getCompanyId()));
276+
themeDisplay.setLocale(LocaleUtil.US);
263277
themeDisplay.setPermissionChecker(
264278
PermissionCheckerFactoryUtil.create(TestPropsValues.getUser()));
265279

@@ -272,6 +286,22 @@ private MockHttpServletRequest _getMockHttpServletRequest()
272286
return mockHttpServletRequest;
273287
}
274288

289+
private JSONObject _processAction() throws Exception {
290+
MockLiferayPortletActionResponse mockLiferayPortletActionResponse =
291+
new MockLiferayPortletActionResponse();
292+
293+
_mvcActionCommand.processAction(
294+
new MockLiferayPortletActionRequest(_getMockHttpServletRequest()),
295+
mockLiferayPortletActionResponse);
296+
297+
MockHttpServletResponse mockHttpServletResponse =
298+
(MockHttpServletResponse)
299+
mockLiferayPortletActionResponse.getHttpServletResponse();
300+
301+
return _jsonFactory.createJSONObject(
302+
mockHttpServletResponse.getContentAsString());
303+
}
304+
275305
@Inject
276306
private CompanyLocalService _companyLocalService;
277307

0 commit comments

Comments
 (0)