6
6
package com .liferay .dynamic .data .mapping .form .web .internal .portlet .action .test ;
7
7
8
8
import com .liferay .arquillian .extension .junit .bridge .junit .Arquillian ;
9
+ import com .liferay .document .library .configuration .DLFileEntryMimeTypeConfiguration ;
9
10
import com .liferay .document .library .kernel .model .DLFileEntry ;
10
11
import com .liferay .document .library .kernel .model .DLFolderConstants ;
11
12
import com .liferay .document .library .kernel .service .DLFileEntryLocalService ;
16
17
import com .liferay .petra .memory .DeleteFileFinalizeAction ;
17
18
import com .liferay .petra .memory .FinalizeManager ;
18
19
import com .liferay .petra .string .StringPool ;
20
+ import com .liferay .portal .configuration .test .util .CompanyConfigurationTemporarySwapper ;
19
21
import com .liferay .portal .kernel .json .JSONFactory ;
20
22
import com .liferay .portal .kernel .json .JSONObject ;
21
23
import com .liferay .portal .kernel .model .Group ;
46
48
import com .liferay .portal .kernel .upload .FileItem ;
47
49
import com .liferay .portal .kernel .util .ContentTypes ;
48
50
import com .liferay .portal .kernel .util .HashMapBuilder ;
51
+ import com .liferay .portal .kernel .util .HashMapDictionaryBuilder ;
52
+ import com .liferay .portal .kernel .util .LocaleUtil ;
49
53
import com .liferay .portal .kernel .util .Portal ;
50
54
import com .liferay .portal .kernel .util .ProxyUtil ;
51
55
import com .liferay .portal .kernel .util .StringUtil ;
@@ -159,24 +163,12 @@ public void testProcessAction() throws Exception {
159
163
_dlFileEntryLocalService .fetchDLFileEntry (
160
164
_oldDLFileEntry .getFileEntryId ()));
161
165
162
- MockLiferayPortletActionResponse mockLiferayPortletActionResponse =
163
- new MockLiferayPortletActionResponse ();
164
-
165
- _mvcActionCommand .processAction (
166
- new MockLiferayPortletActionRequest (_getMockHttpServletRequest ()),
167
- mockLiferayPortletActionResponse );
166
+ JSONObject jsonObject = _processAction ();
168
167
169
168
Assert .assertNull (
170
169
_dlFileEntryLocalService .fetchDLFileEntry (
171
170
_oldDLFileEntry .getFileEntryId ()));
172
171
173
- MockHttpServletResponse mockHttpServletResponse =
174
- (MockHttpServletResponse )
175
- mockLiferayPortletActionResponse .getHttpServletResponse ();
176
-
177
- JSONObject jsonObject = _jsonFactory .createJSONObject (
178
- mockHttpServletResponse .getContentAsString ());
179
-
180
172
JSONObject fileJSONObject = jsonObject .getJSONObject ("file" );
181
173
182
174
DLFileEntry dlFileEntry = _dlFileEntryLocalService .fetchDLFileEntry (
@@ -201,6 +193,27 @@ public void testProcessAction() throws Exception {
201
193
ActionKeys .VIEW ));
202
194
}
203
195
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
+
204
217
private FileItem _getFileItem () throws Exception {
205
218
Path path = Files .createTempFile (null , ".txt" );
206
219
@@ -260,6 +273,7 @@ private MockHttpServletRequest _getMockHttpServletRequest()
260
273
261
274
themeDisplay .setCompany (
262
275
_companyLocalService .fetchCompany (TestPropsValues .getCompanyId ()));
276
+ themeDisplay .setLocale (LocaleUtil .US );
263
277
themeDisplay .setPermissionChecker (
264
278
PermissionCheckerFactoryUtil .create (TestPropsValues .getUser ()));
265
279
@@ -272,6 +286,22 @@ private MockHttpServletRequest _getMockHttpServletRequest()
272
286
return mockHttpServletRequest ;
273
287
}
274
288
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
+
275
305
@ Inject
276
306
private CompanyLocalService _companyLocalService ;
277
307
0 commit comments