11package org .cloudfoundry .multiapps .controller .process .steps ;
22
3- import static org .junit .jupiter .api .Assertions .assertEquals ;
4- import static org .junit .jupiter .api .Assertions .assertFalse ;
5- import static org .junit .jupiter .api .Assertions .assertThrows ;
6- import static org .mockito .ArgumentMatchers .any ;
7- import static org .mockito .Mockito .when ;
8-
93import java .io .InputStream ;
104import java .math .BigInteger ;
115import java .nio .file .Files ;
2115
2216import org .cloudfoundry .multiapps .common .SLException ;
2317import org .cloudfoundry .multiapps .controller .core .util .ApplicationConfiguration ;
18+ import org .cloudfoundry .multiapps .controller .core .validators .parameters .FileMimeTypeValidator ;
2419import org .cloudfoundry .multiapps .controller .persistence .model .FileEntry ;
2520import org .cloudfoundry .multiapps .controller .persistence .model .ImmutableFileEntry ;
2621import org .cloudfoundry .multiapps .controller .persistence .services .FileStorageException ;
3328import org .junit .jupiter .params .provider .MethodSource ;
3429import org .mockito .Mockito ;
3530
31+ import static org .junit .jupiter .api .Assertions .assertEquals ;
32+ import static org .junit .jupiter .api .Assertions .assertFalse ;
33+ import static org .junit .jupiter .api .Assertions .assertThrows ;
34+ import static org .mockito .ArgumentMatchers .any ;
35+ import static org .mockito .Mockito .when ;
36+
3637class ValidateDeployParametersStepTest extends SyncFlowableStepTest <ValidateDeployParametersStep > {
3738
3839 private static final String MERGED_ARCHIVE_TEST_MTAR = "merged-archive-test.mtar" ;
@@ -48,36 +49,37 @@ class ValidateDeployParametersStepTest extends SyncFlowableStepTest<ValidateDepl
4849
4950 private static Stream <Arguments > testExecution () {
5051 return Stream .of (
51- // [1] No file associated with the specified file id
52- Arguments .of (new StepInput (EXISTING_FILE_ID , NOT_EXISTING_FILE_ID + "," + EXISTING_FILE_ID , 1 , null ),
53- MessageFormat .format (Messages .ERROR_NO_FILE_ASSOCIATED_WITH_THE_SPECIFIED_FILE_ID_0_IN_SPACE_1 ,
54- "notExistingFileId" , "space-id" ),
55- false , "" ),
56-
57- // [2] Valid parameters
58- Arguments .of (new StepInput (EXISTING_FILE_ID ,
59- EXISTING_FILE_ID + "," + EXISTING_FILE_ID ,
60- 1 ,
61- VersionRule .HIGHER .toString ()),
62- null , false , "" ),
63-
64- // [3] Max descriptor size exceeded
65- Arguments .of (new StepInput (EXISTING_FILE_ID , EXISTING_BIGGER_FILE_ID , 1 , VersionRule .HIGHER .toString ()),
66- MessageFormat .format (org .cloudfoundry .multiapps .mta .Messages .ERROR_SIZE_OF_FILE_EXCEEDS_CONFIGURED_MAX_SIZE_LIMIT ,
67- "1048577" , "extDescriptorFile" , "1048576" ),
68- false , "" ),
69-
70- // [4] Process chunked file
71- Arguments .of (new StepInput (MERGED_ARCHIVE_NAME + ".part.0," + MERGED_ARCHIVE_NAME + ".part.1,"
72- + MERGED_ARCHIVE_NAME + ".part.2" , null , 1 , VersionRule .HIGHER .toString ()), null , true , "" ),
73-
74- // [5] Max size of entries exceeded
75- Arguments .of (new StepInput (EXCEEDING_FILE_SIZE_ID + ".part.0," + EXCEEDING_FILE_SIZE_ID + ".part.1,"
76- + EXCEEDING_FILE_SIZE_ID + ".part.2," + EXCEEDING_FILE_SIZE_ID + ".part.3," + EXCEEDING_FILE_SIZE_ID
77- + ".part.4" , null , 1 , VersionRule .HIGHER .toString ()),
78- MessageFormat .format (Messages .SIZE_OF_ALL_OPERATIONS_FILES_0_EXCEEDS_MAX_UPLOAD_SIZE_1 , 5368709120L ,
79- 4294967296L ),
80- true , "" ));
52+ // [1] No file associated with the specified file id
53+ Arguments .of (new StepInput (EXISTING_FILE_ID , NOT_EXISTING_FILE_ID + "," + EXISTING_FILE_ID , 1 , null ),
54+ MessageFormat .format (Messages .ERROR_NO_FILE_ASSOCIATED_WITH_THE_SPECIFIED_FILE_ID_0_IN_SPACE_1 ,
55+ "notExistingFileId" , "space-id" ),
56+ false , "" ),
57+
58+ // [2] Valid parameters
59+ Arguments .of (new StepInput (EXISTING_FILE_ID ,
60+ EXISTING_FILE_ID + "," + EXISTING_FILE_ID ,
61+ 1 ,
62+ VersionRule .HIGHER .toString ()),
63+ null , false , "" ),
64+
65+ // [3] Max descriptor size exceeded
66+ Arguments .of (new StepInput (EXISTING_FILE_ID , EXISTING_BIGGER_FILE_ID , 1 , VersionRule .HIGHER .toString ()),
67+ MessageFormat .format (org .cloudfoundry .multiapps .mta .Messages .ERROR_SIZE_OF_FILE_EXCEEDS_CONFIGURED_MAX_SIZE_LIMIT ,
68+ "1048577" , "extDescriptorFile" , "1048576" ),
69+ false , "" ),
70+
71+ // [4] Process chunked file
72+ Arguments .of (new StepInput (MERGED_ARCHIVE_NAME + ".part.0," + MERGED_ARCHIVE_NAME + ".part.1,"
73+ + MERGED_ARCHIVE_NAME + ".part.2" , null , 1 , VersionRule .HIGHER .toString ()), null , true , "" ),
74+
75+ // [5] Max size of entries exceeded
76+ Arguments .of (new StepInput (EXCEEDING_FILE_SIZE_ID + ".part.0," + EXCEEDING_FILE_SIZE_ID + ".part.1,"
77+ + EXCEEDING_FILE_SIZE_ID + ".part.2," + EXCEEDING_FILE_SIZE_ID + ".part.3,"
78+ + EXCEEDING_FILE_SIZE_ID
79+ + ".part.4" , null , 1 , VersionRule .HIGHER .toString ()),
80+ MessageFormat .format (Messages .SIZE_OF_ALL_OPERATIONS_FILES_0_EXCEEDS_MAX_UPLOAD_SIZE_1 , 5368709120L ,
81+ 4294967296L ),
82+ true , "" ));
8183 }
8284
8385 private static FileEntry createFileEntry (String id , String name , long size ) {
@@ -125,15 +127,15 @@ private void prepareContext() {
125127
126128 private void prepareFileService (String appArchiveId ) throws FileStorageException {
127129 when (fileService .getFile ("space-id" , EXISTING_FILE_ID ))
128- .thenReturn (createFileEntry (EXISTING_FILE_ID , "some-file-entry-name" , 1024 * 1024L ));
130+ .thenReturn (createFileEntry (EXISTING_FILE_ID , "some-file-entry-name" , 1024 * 1024L ));
129131 when (fileService .getFile ("space-id" , MERGED_ARCHIVE_NAME + ".part.0" ))
130- .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.0" , MERGED_ARCHIVE_NAME + ".part.0" , 1024 * 1024L ));
132+ .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.0" , MERGED_ARCHIVE_NAME + ".part.0" , 1024 * 1024L ));
131133
132134 when (fileService .getFile ("space-id" , MERGED_ARCHIVE_NAME + ".part.1" ))
133- .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.1" , MERGED_ARCHIVE_NAME + ".part.1" , 1024 * 1024L ));
135+ .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.1" , MERGED_ARCHIVE_NAME + ".part.1" , 1024 * 1024L ));
134136
135137 when (fileService .getFile ("space-id" , MERGED_ARCHIVE_NAME + ".part.2" ))
136- .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.2" , MERGED_ARCHIVE_NAME + ".part.2" , 1024 * 1024L ));
138+ .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.2" , MERGED_ARCHIVE_NAME + ".part.2" , 1024 * 1024L ));
137139
138140 when (fileService .getFile ("space-id" , EXCEEDING_FILE_SIZE_ID + ".part.0" ))
139141 .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.0" , MERGED_ARCHIVE_NAME + ".part.0" , 1024 * 1024 * 1024 ));
@@ -151,11 +153,11 @@ private void prepareFileService(String appArchiveId) throws FileStorageException
151153 .thenReturn (createFileEntry (MERGED_ARCHIVE_NAME + ".part.4" , MERGED_ARCHIVE_NAME + ".part.4" , 1024 * 1024 * 1024 ));
152154
153155 when (fileService .getFile ("space-id" , EXISTING_BIGGER_FILE_ID ))
154- .thenReturn (createFileEntry (EXISTING_BIGGER_FILE_ID , "extDescriptorFile" , 1024 * 1024L + 1 ));
156+ .thenReturn (createFileEntry (EXISTING_BIGGER_FILE_ID , "extDescriptorFile" , 1024 * 1024L + 1 ));
155157 when (fileService .getFile ("space-id" , NOT_EXISTING_FILE_ID ))
156- .thenReturn (null );
158+ .thenReturn (null );
157159 when (fileService .addFile (any (FileEntry .class ), any (InputStream .class )))
158- .thenReturn (createFileEntry (EXISTING_FILE_ID , MERGED_ARCHIVE_TEST_MTAR , 1024 * 1024 * 1024L ));
160+ .thenReturn (createFileEntry (EXISTING_FILE_ID , MERGED_ARCHIVE_TEST_MTAR , 1024 * 1024 * 1024L ));
159161 if (appArchiveId .contains (EXCEEDING_FILE_SIZE_ID )) {
160162 List <FileEntry > fileEntries = List .of (createFileEntry (EXCEEDING_FILE_SIZE_ID + ".part.0" , EXCEEDING_FILE_SIZE_ID + ".part.0" ,
161163 1024 * 1024 * 1024 ),
@@ -168,7 +170,7 @@ private void prepareFileService(String appArchiveId) throws FileStorageException
168170 createFileEntry (EXCEEDING_FILE_SIZE_ID + ".part.4" , EXCEEDING_FILE_SIZE_ID + ".part.4" ,
169171 1024 * 1024 * 1024 ));
170172 when (fileService .listFilesBySpaceAndOperationId (Mockito .anyString (), Mockito .anyString ()))
171- .thenReturn (fileEntries );
173+ .thenReturn (fileEntries );
172174 }
173175 }
174176
@@ -179,9 +181,9 @@ private void prepareArchiveMerger() {
179181
180182 private void prepareConfiguration () {
181183 when (configuration .getMaxMtaDescriptorSize ())
182- .thenReturn (ApplicationConfiguration .DEFAULT_MAX_MTA_DESCRIPTOR_SIZE );
184+ .thenReturn (ApplicationConfiguration .DEFAULT_MAX_MTA_DESCRIPTOR_SIZE );
183185 when (configuration .getMaxUploadSize ())
184- .thenReturn (ApplicationConfiguration .DEFAULT_MAX_UPLOAD_SIZE );
186+ .thenReturn (ApplicationConfiguration .DEFAULT_MAX_UPLOAD_SIZE );
185187 }
186188
187189 private void validate () {
@@ -204,7 +206,7 @@ protected ValidateDeployParametersStep createStep() {
204206 futureTask .run ();
205207 return futureTask ;
206208 });
207- return new ValidateDeployParametersStep (executorService );
209+ return new ValidateDeployParametersStep (executorService , new FileMimeTypeValidator () );
208210 }
209211
210212 private static class StepInput {
0 commit comments