Tweak test script no issue #
[arvados.git] / src / test / java / org / arvados / client / test / utils / FileTestUtils.java
1 /*
2  * Copyright (C) The Arvados Authors. All rights reserved.
3  *
4  * SPDX-License-Identifier: AGPL-3.0 OR Apache-2.0
5  *
6  */
7
8 package org.arvados.client.test.utils;
9
10 import org.apache.commons.io.FileUtils;
11 import org.assertj.core.util.Lists;
12
13 import java.io.File;
14 import java.io.IOException;
15 import java.io.RandomAccessFile;
16 import java.util.List;
17
18 public class FileTestUtils {
19
20     public static final String FILE_SPLIT_TEST_DIR = "/tmp/file-split";
21     public static final String FILE_DOWNLOAD_TEST_DIR = "/tmp/arvados-downloaded";
22     public static final String TEST_FILE = FILE_SPLIT_TEST_DIR + "/test-file";
23     public static long ONE_FOURTH_GB = FileUtils.ONE_GB / 4;
24     public static long ONE_EIGTH_GB = FileUtils.ONE_GB / 8;
25     public static long HALF_GB = FileUtils.ONE_GB / 2;
26     public static int FILE_SPLIT_SIZE = 64;
27
28     public static void createDirectory(String path) throws Exception {
29         new File(path).mkdirs();
30     }
31
32     public static void cleanDirectory(String directory) throws Exception {
33         FileUtils.cleanDirectory(new File(directory));
34     }
35     
36     public static File generateFile(String path, long length) throws IOException {
37         RandomAccessFile testFile = new RandomAccessFile(path, "rwd");
38         testFile.setLength(length);
39         testFile.close();
40         return new File(path);
41     }
42     
43     public static List<File> generatePredefinedFiles() throws IOException {
44         return Lists.newArrayList(
45                 generateFile(TEST_FILE + 1, FileUtils.ONE_KB),
46                 generateFile(TEST_FILE + 2, FileUtils.ONE_KB * 20),
47                 generateFile(TEST_FILE + " " + 3, FileUtils.ONE_MB)
48             );
49     }
50 }