13
13
*******************************************************************************/
14
14
package org .eclipse .core .tests .filesystem ;
15
15
16
- import static org .assertj .core .api .Assertions .assertThat ;
17
16
import static org .eclipse .core .tests .internal .localstore .LocalStoreTestUtil .createTree ;
18
17
import static org .eclipse .core .tests .internal .localstore .LocalStoreTestUtil .getTree ;
19
18
import static org .eclipse .core .tests .resources .ResourceTestUtil .createInFileSystem ;
20
- import static org .eclipse .core .tests .resources .ResourceTestUtil .createInputStream ;
21
19
import static org .eclipse .core .tests .resources .ResourceTestUtil .createRandomString ;
22
20
import static org .eclipse .core .tests .resources .ResourceTestUtil .createTestMonitor ;
23
21
import static org .eclipse .core .tests .resources .ResourceTestUtil .getFileStore ;
34
32
35
33
import java .io .File ;
36
34
import java .io .IOException ;
37
- import java .io .InputStream ;
38
35
import java .io .OutputStream ;
39
36
import java .net .URI ;
40
37
import java .nio .file .Files ;
41
38
import java .nio .file .Path ;
42
39
import java .util .ArrayList ;
40
+ import java .util .Arrays ;
43
41
import java .util .Collections ;
44
42
import java .util .List ;
43
+ import java .util .Random ;
45
44
import java .util .concurrent .atomic .AtomicInteger ;
46
45
import java .util .stream .Stream ;
47
46
import org .eclipse .core .filesystem .EFS ;
56
55
import org .eclipse .core .resources .IResource ;
57
56
import org .eclipse .core .runtime .CoreException ;
58
57
import org .eclipse .core .runtime .IPath ;
59
- import org .eclipse .core .runtime .IProgressMonitor ;
60
58
import org .eclipse .core .runtime .Platform ;
61
59
import org .eclipse .core .tests .resources .util .WorkspaceResetExtension ;
62
60
import org .eclipse .osgi .util .NLS ;
63
61
import org .junit .jupiter .api .Test ;
64
62
import org .junit .jupiter .api .extension .ExtendWith ;
65
63
import org .junit .jupiter .api .io .TempDir ;
64
+ import org .junit .jupiter .params .ParameterizedTest ;
65
+ import org .junit .jupiter .params .provider .ValueSource ;
66
66
67
67
/**
68
68
* Basic tests for the IFileStore API
69
69
*/
70
70
@ ExtendWith (WorkspaceResetExtension .class )
71
71
public class FileStoreTest {
72
72
73
+ private static final Random RANDOM = new Random ();
74
+
73
75
private IFileStore createDir (IFileStore store , boolean clear ) throws CoreException {
74
76
if (clear && store .fetchInfo ().exists ()) {
75
77
store .delete (EFS .NONE , null );
@@ -93,10 +95,12 @@ private static IFileStore randomUniqueNotExistingFileStore() throws IOException
93
95
return getFileStore (randomUniqueNotExistingPath ());
94
96
}
95
97
96
- private void createFile (IFileStore target , String content ) throws CoreException , IOException {
97
- try (OutputStream output = target .openOutputStream (EFS .NONE , null )) {
98
- createInputStream (content ).transferTo (output );
99
- }
98
+ private void createFile (IFileStore target , String content ) throws CoreException {
99
+ createFile (target , content .getBytes ());
100
+ }
101
+
102
+ private void createFile (IFileStore target , byte [] content ) throws CoreException {
103
+ target .write (content , EFS .NONE , null );
100
104
}
101
105
102
106
/**
@@ -146,9 +150,9 @@ private IFileStore[] getFileStoresOnTwoVolumes() {
146
150
/**
147
151
* Basically this is a test for the Windows Platform.
148
152
*/
149
-
150
- @ Test
151
- public void testCopyAcrossVolumes () throws Throwable {
153
+ @ ParameterizedTest ( name = "File size {0} bytes" )
154
+ @ ValueSource ( ints = { 10 , LocalFile . LARGE_FILE_SIZE_THRESHOLD + 10 })
155
+ public void testCopyAcrossVolumes (int fileSize ) throws Throwable {
152
156
IFileStore [] tempDirectories = getFileStoresOnTwoVolumes ();
153
157
154
158
/* test if we are in the adequate environment */
@@ -166,7 +170,7 @@ public void testCopyAcrossVolumes() throws Throwable {
166
170
167
171
IFileStore target = tempSrc .getChild (subfolderName );
168
172
createDir (target , true );
169
- createTree (getTree (target ));
173
+ createTree (getTree (target ), fileSize );
170
174
171
175
/* c:\temp\target -> d:\temp\target */
172
176
IFileStore destination = tempDest .getChild (subfolderName );
@@ -228,34 +232,31 @@ public void testCopyDirectoryParentMissing() throws Throwable {
228
232
assertTrue (!child .fetchInfo ().exists ());
229
233
}
230
234
231
- @ Test
232
- public void testCaseInsensitive () throws Throwable {
233
- IFileStore temp = createDir (randomUniqueNotExistingFileStore (), true );
235
+ @ ParameterizedTest (name = "File size {0} bytes" )
236
+ @ ValueSource (ints = { 10 , LocalFile .LARGE_FILE_SIZE_THRESHOLD + 10 })
237
+ public void testCaseInsensitive (int fileSize ) throws Throwable {
238
+ IFileStore temp = createDir (randomUniqueNotExistingFileStore (), true );
234
239
boolean isCaseSensitive = temp .getFileSystem ().isCaseSensitive ();
235
240
assumeFalse ("only relevant for platforms with case-sensitive file system" , isCaseSensitive );
236
241
242
+ byte [] content = new byte [fileSize ];
243
+ RANDOM .nextBytes (content );
244
+
237
245
// create a file
238
- String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy" ;
239
246
IFileStore fileWithSmallName = temp .getChild ("filename" );
240
247
fileWithSmallName .delete (EFS .NONE , null );
241
248
createFile (fileWithSmallName , content );
242
249
System .out .println (fileWithSmallName .fetchInfo ().getName ());
243
250
assertTrue (fileWithSmallName .fetchInfo ().exists ());
244
- try (InputStream stream = fileWithSmallName .openInputStream (EFS .NONE , null )) {
245
- assertThat (stream ).hasContent (content );
246
- }
251
+ assertTrue ( Arrays .equals (content , fileWithSmallName .readAllBytes (EFS .NONE , null )));
247
252
248
253
IFileStore fileWithOtherName = temp .getChild ("FILENAME" );
249
254
System .out .println (fileWithOtherName .fetchInfo ().getName ());
250
255
// file content is already the same for both Cases:
251
- try (InputStream stream = fileWithOtherName .openInputStream (EFS .NONE , null )) {
252
- assertThat (stream ).hasContent (content );
253
- }
256
+ assertTrue (Arrays .equals (content , fileWithOtherName .readAllBytes (EFS .NONE , null )));
254
257
fileWithSmallName .copy (fileWithOtherName , IResource .DEPTH_INFINITE , null ); // a NOP Operation
255
258
// file content is still the same for both Cases:
256
- try (InputStream stream = fileWithOtherName .openInputStream (EFS .NONE , null )) {
257
- assertThat (stream ).hasContent (content );
258
- }
259
+ assertTrue (Arrays .equals (content , fileWithOtherName .readAllBytes (EFS .NONE , null )));
259
260
assertTrue (fileWithOtherName .fetchInfo ().exists ());
260
261
assertTrue (fileWithSmallName .fetchInfo ().exists ());
261
262
fileWithOtherName .delete (EFS .NONE , null );
@@ -267,26 +268,25 @@ public void testCaseInsensitive() throws Throwable {
267
268
assertEquals (message , exception .getMessage ());
268
269
}
269
270
270
- @ Test
271
- public void testCopyFile () throws Throwable {
271
+ @ ParameterizedTest (name = "File size {0} bytes" )
272
+ @ ValueSource (ints = { 10 , LocalFile .LARGE_FILE_SIZE_THRESHOLD + 10 })
273
+ public void testCopyFile (int fileSize ) throws Throwable {
272
274
/* build scenario */
273
275
IFileStore temp = createDir (randomUniqueNotExistingFileStore (), true );
276
+ byte [] content = new byte [fileSize ];
277
+ RANDOM .nextBytes (content );
278
+
274
279
// create target
275
- String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy" ;
276
280
IFileStore target = temp .getChild ("target" );
277
281
target .delete (EFS .NONE , null );
278
282
createFile (target , content );
279
283
assertTrue (target .fetchInfo ().exists ());
280
- try (InputStream stream = target .openInputStream (EFS .NONE , null )) {
281
- assertThat (stream ).hasContent (content );
282
- }
284
+ assertTrue (Arrays .equals (content , target .readAllBytes (EFS .NONE , null )));
283
285
284
286
/* temp\target -> temp\copy of target */
285
287
IFileStore copyOfTarget = temp .getChild ("copy of target" );
286
288
target .copy (copyOfTarget , IResource .DEPTH_INFINITE , null );
287
- try (InputStream stream = copyOfTarget .openInputStream (EFS .NONE , null )) {
288
- assertThat (stream ).hasContent (content );
289
- }
289
+ assertTrue (Arrays .equals (content , copyOfTarget .readAllBytes (EFS .NONE , null )));
290
290
copyOfTarget .delete (EFS .NONE , null );
291
291
292
292
// We need to know whether or not we can unset the read-only flag
@@ -297,43 +297,22 @@ public void testCopyFile() throws Throwable {
297
297
setReadOnly (target , true );
298
298
299
299
target .copy (copyOfTarget , IResource .DEPTH_INFINITE , null );
300
- try (InputStream stream = copyOfTarget .openInputStream (EFS .NONE , null )) {
301
- assertThat (stream ).hasContent (content );
302
- }
300
+ assertTrue (Arrays .equals (content , copyOfTarget .readAllBytes (EFS .NONE , null )));
303
301
// reset read only flag for cleanup
304
302
setReadOnly (copyOfTarget , false );
305
303
copyOfTarget .delete (EFS .NONE , null );
306
304
// reset the read only flag for cleanup
307
305
setReadOnly (target , false );
308
306
target .delete (EFS .NONE , null );
309
307
}
310
-
311
- /* copy a big file to test progress monitor */
312
- StringBuilder sb = new StringBuilder ();
313
- for (int i = 0 ; i < 1000 ; i ++) {
314
- sb .append ("asdjhasldhaslkfjhasldkfjhasdlkfjhasdlfkjhasdflkjhsdaf" );
315
- }
316
- IFileStore bigFile = temp .getChild ("bigFile" );
317
- createFile (bigFile , sb .toString ());
318
- assertTrue (bigFile .fetchInfo ().exists ());
319
- try (InputStream stream = bigFile .openInputStream (EFS .NONE , null )) {
320
- assertThat (stream ).hasContent (sb .toString ());
321
- }
322
- IFileStore destination = temp .getChild ("copy of bigFile" );
323
- // IProgressMonitor monitor = new LoggingProgressMonitor(System.out);
324
- IProgressMonitor monitor = createTestMonitor ();
325
- bigFile .copy (destination , EFS .NONE , monitor );
326
- try (InputStream stream = destination .openInputStream (EFS .NONE , null )) {
327
- assertThat (stream ).hasContent (sb .toString ());
328
- }
329
- destination .delete (EFS .NONE , null );
330
308
}
331
309
332
310
/**
333
311
* Basically this is a test for the Windows Platform.
334
312
*/
335
- @ Test
336
- public void testCopyFileAcrossVolumes () throws Throwable {
313
+ @ ParameterizedTest (name = "File size {0} bytes" )
314
+ @ ValueSource (ints = { 10 , LocalFile .LARGE_FILE_SIZE_THRESHOLD + 10 })
315
+ public void testCopyFileAcrossVolumes (int fileSize ) throws Throwable {
337
316
IFileStore [] tempDirectories = getFileStoresOnTwoVolumes ();
338
317
339
318
/* test if we are in the adequate environment */
@@ -346,32 +325,27 @@ public void testCopyFileAcrossVolumes() throws Throwable {
346
325
/* get the destination folder */
347
326
IFileStore tempDest = tempDirectories [1 ];
348
327
// create target
349
- String content = "this is just a simple content \n to a simple file \n to test a 'simple' copy" ;
328
+ byte [] content = new byte [fileSize ];
329
+ RANDOM .nextBytes (content );
350
330
String subfolderName = "target_" + System .currentTimeMillis ();
351
331
352
332
IFileStore target = tempSrc .getChild (subfolderName );
353
333
target .delete (EFS .NONE , null );
354
334
createFile (target , content );
355
335
assertTrue (target .fetchInfo ().exists ());
356
- try (InputStream stream = target .openInputStream (EFS .NONE , null )) {
357
- assertThat (stream ).hasContent (content );
358
- }
336
+ assertTrue (Arrays .equals (content , target .readAllBytes (EFS .NONE , null )));
359
337
360
338
/* c:\temp\target -> d:\temp\target */
361
339
IFileStore destination = tempDest .getChild (subfolderName );
362
340
target .copy (destination , IResource .DEPTH_INFINITE , null );
363
- try (InputStream stream = destination .openInputStream (EFS .NONE , null )) {
364
- assertThat (stream ).hasContent (content );
365
- }
341
+ assertTrue (Arrays .equals (content , destination .readAllBytes (EFS .NONE , null )));
366
342
destination .delete (EFS .NONE , null );
367
343
368
344
/* c:\temp\target -> d:\temp\copy of target */
369
345
String copyOfSubfoldername = "copy of " + subfolderName ;
370
346
destination = tempDest .getChild (copyOfSubfoldername );
371
347
target .copy (destination , IResource .DEPTH_INFINITE , null );
372
- try (InputStream stream = destination .openInputStream (EFS .NONE , null )) {
373
- assertThat (stream ).hasContent (content );
374
- }
348
+ assertTrue (Arrays .equals (content , destination .readAllBytes (EFS .NONE , null )));
375
349
destination .delete (EFS .NONE , null );
376
350
377
351
/* c:\temp\target -> d:\temp\target (but the destination is already a file */
@@ -380,9 +354,7 @@ public void testCopyFileAcrossVolumes() throws Throwable {
380
354
createFile (destination , anotherContent );
381
355
assertTrue (!destination .fetchInfo ().isDirectory ());
382
356
target .copy (destination , IResource .DEPTH_INFINITE , null );
383
- try (InputStream stream = destination .openInputStream (EFS .NONE , null )) {
384
- assertThat (stream ).hasContent (content );
385
- }
357
+ assertTrue (Arrays .equals (content , destination .readAllBytes (EFS .NONE , null )));
386
358
destination .delete (EFS .NONE , null );
387
359
388
360
/* c:\temp\target -> d:\temp\target (but the destination is already a folder */
0 commit comments