33
33
import org .junit .jupiter .api .AfterEach ;
34
34
import org .junit .jupiter .api .BeforeAll ;
35
35
import org .junit .jupiter .api .BeforeEach ;
36
- import org .junit .jupiter .api .Test ;
37
36
import org .junit .jupiter .params .ParameterizedTest ;
38
- import org .junit .jupiter .params .provider .ValueSource ;
37
+ import org .junit .jupiter .params .provider .Arguments ;
38
+ import org .junit .jupiter .params .provider .MethodSource ;
39
39
import org .opentest4j .AssertionFailedError ;
40
40
import software .amazon .awssdk .testutils .FileUtils ;
41
41
import software .amazon .awssdk .transfer .s3 .model .CompletedDirectoryDownload ;
@@ -97,6 +97,7 @@ public static void teardown() {
97
97
}
98
98
99
99
closeQuietly (tmCrt , log .logger ());
100
+ closeQuietly (tmJava , log .logger ());
100
101
}
101
102
102
103
/**
@@ -116,21 +117,23 @@ public static void teardown() {
116
117
* }
117
118
* </pre>
118
119
*/
119
- @ Test
120
- public void downloadDirectory () throws Exception {
121
- DirectoryDownload downloadDirectory = tmCrt .downloadDirectory (u -> u .destination (directory )
122
- .bucket (TEST_BUCKET ));
120
+ @ ParameterizedTest
121
+ @ MethodSource ("transferManagers" )
122
+ public void downloadDirectory (S3TransferManager tm ) throws Exception {
123
+ DirectoryDownload downloadDirectory = tm .downloadDirectory (u -> u .destination (directory )
124
+ .bucket (TEST_BUCKET ));
123
125
CompletedDirectoryDownload completedDirectoryDownload = downloadDirectory .completionFuture ().get (5 , TimeUnit .SECONDS );
124
126
assertThat (completedDirectoryDownload .failedTransfers ()).isEmpty ();
125
127
assertTwoDirectoriesHaveSameStructure (sourceDirectory , directory );
126
128
}
127
129
128
130
@ ParameterizedTest
129
- @ ValueSource (strings = {"notes/2021" , "notes/2021/" })
130
- void downloadDirectory_withPrefix (String prefix ) throws Exception {
131
- DirectoryDownload downloadDirectory = tmCrt .downloadDirectory (u -> u .destination (directory )
132
- .listObjectsV2RequestTransformer (r -> r .prefix (prefix ))
133
- .bucket (TEST_BUCKET ));
131
+ @ MethodSource ("prefixTestArguments" )
132
+ void downloadDirectory_withPrefix (S3TransferManager tm , String prefix ) throws Exception {
133
+ DirectoryDownload downloadDirectory =
134
+ tm .downloadDirectory (u -> u .destination (directory )
135
+ .listObjectsV2RequestTransformer (r -> r .prefix (prefix ))
136
+ .bucket (TEST_BUCKET ));
134
137
CompletedDirectoryDownload completedDirectoryDownload = downloadDirectory .completionFuture ().get (5 , TimeUnit .SECONDS );
135
138
assertThat (completedDirectoryDownload .failedTransfers ()).isEmpty ();
136
139
@@ -152,12 +155,14 @@ void downloadDirectory_withPrefix(String prefix) throws Exception {
152
155
* }
153
156
* </pre>
154
157
*/
155
- @ Test
156
- void downloadDirectory_containsObjectWithPrefixInTheKey_shouldResolveCorrectly () throws Exception {
158
+ @ ParameterizedTest
159
+ @ MethodSource ("transferManagers" )
160
+ void downloadDirectory_containsObjectWithPrefixInTheKey_shouldResolveCorrectly (S3TransferManager tm )
161
+ throws Exception {
157
162
String prefix = "notes" ;
158
- DirectoryDownload downloadDirectory = tmCrt .downloadDirectory (u -> u .destination (directory )
159
- .listObjectsV2RequestTransformer (r -> r .prefix (prefix ))
160
- .bucket (TEST_BUCKET ));
163
+ DirectoryDownload downloadDirectory = tm .downloadDirectory (u -> u .destination (directory )
164
+ .listObjectsV2RequestTransformer (r -> r .prefix (prefix ))
165
+ .bucket (TEST_BUCKET ));
161
166
CompletedDirectoryDownload completedDirectoryDownload = downloadDirectory .completionFuture ().get (5 , TimeUnit .SECONDS );
162
167
assertThat (completedDirectoryDownload .failedTransfers ()).isEmpty ();
163
168
@@ -182,14 +187,15 @@ void downloadDirectory_containsObjectWithPrefixInTheKey_shouldResolveCorrectly()
182
187
* }
183
188
* </pre>
184
189
*/
185
- @ Test
186
- public void downloadDirectory_withPrefixAndDelimiter () throws Exception {
190
+ @ ParameterizedTest
191
+ @ MethodSource ("transferManagers" )
192
+ public void downloadDirectory_withPrefixAndDelimiter (S3TransferManager tm ) throws Exception {
187
193
String prefix = "notes-2021" ;
188
194
DirectoryDownload downloadDirectory =
189
- tmCrt .downloadDirectory (u -> u .destination (directory )
190
- .listObjectsV2RequestTransformer (r -> r .delimiter (CUSTOM_DELIMITER )
195
+ tm .downloadDirectory (u -> u .destination (directory )
196
+ .listObjectsV2RequestTransformer (r -> r .delimiter (CUSTOM_DELIMITER )
191
197
.prefix (prefix ))
192
- .bucket (TEST_BUCKET_CUSTOM_DELIMITER ));
198
+ .bucket (TEST_BUCKET_CUSTOM_DELIMITER ));
193
199
CompletedDirectoryDownload completedDirectoryDownload = downloadDirectory .completionFuture ().get (5 , TimeUnit .SECONDS );
194
200
assertThat (completedDirectoryDownload .failedTransfers ()).isEmpty ();
195
201
assertTwoDirectoriesHaveSameStructure (sourceDirectory .resolve ("notes" ).resolve ("2021" ), directory );
@@ -206,9 +212,10 @@ public void downloadDirectory_withPrefixAndDelimiter() throws Exception {
206
212
* }
207
213
* </pre>
208
214
*/
209
- @ Test
210
- public void downloadDirectory_withFilter () throws Exception {
211
- DirectoryDownload downloadDirectory = tmCrt .downloadDirectory (u -> u
215
+ @ ParameterizedTest
216
+ @ MethodSource ("transferManagers" )
217
+ public void downloadDirectory_withFilter (S3TransferManager tm ) throws Exception {
218
+ DirectoryDownload downloadDirectory = tm .downloadDirectory (u -> u
212
219
.destination (directory )
213
220
.bucket (TEST_BUCKET )
214
221
.filter (s3Object -> s3Object .key ().startsWith ("notes/2021/2" )));
@@ -296,4 +303,14 @@ private static Path createLocalTestDirectory() throws IOException {
296
303
RandomStringUtils .random (100 ).getBytes (StandardCharsets .UTF_8 ));
297
304
return directory ;
298
305
}
306
+
307
+ private static Stream <Arguments > prefixTestArguments () {
308
+ String [] prefixes = {"notes/2021" , "notes/2021/" };
309
+ return Stream .of (
310
+ Arguments .of (tmCrt , prefixes [0 ]),
311
+ Arguments .of (tmCrt , prefixes [1 ]),
312
+ Arguments .of (tmJava , prefixes [0 ]),
313
+ Arguments .of (tmJava , prefixes [1 ])
314
+ );
315
+ }
299
316
}
0 commit comments