/** * Verify that the supplied file or directory is within the test data directory. * * @param file the file or directory; may not be null * @return true if inside the test data directory, or false otherwise */ public static boolean inTestDataDir(File file) { return inTestDataDir(file.toPath()); }
/** * Create a file within the test data directory at the given relative path. * * @param relativePath the path of the file within the test data directory; may not be null * @return the reference to the existing readable and writable file */ public static File createTestingFile(Path relativePath) { Path path = relativePath.toAbsolutePath(); if ( !inTestDataDir(path) ) { throw new IllegalStateException("Expecting '" + relativePath + "' to be within the testing directory"); } return IoUtil.createFile(path); }
protected void assertValidDataDirectory(File dir) { assertThat(dir.exists()).isTrue(); assertThat(dir.isDirectory()).isTrue(); assertThat(dir.canWrite()).isTrue(); assertThat(dir.canRead()).isTrue(); assertThat(Testing.Files.inTestDataDir(dir)).isTrue(); }
/** * A method that will delete a file or folder only if it is within the 'target' directory (for safety). * Folders are removed recursively. * * @param path the path to the file or folder in the target directory */ public static void delete(Path path) { if (path != null) { path = path.toAbsolutePath(); if (inTestDataDir(path)) { try { IoUtil.delete(path); } catch (IOException e) { printError("Unable to remove '" + path.toAbsolutePath() + "'", e); } } else { printError("Will not remove directory that is outside test data area: " + path); } } }
protected void assertValidDataDirectory(File dir) { assertThat(dir.exists()).isTrue(); assertThat(dir.isDirectory()).isTrue(); assertThat(dir.canWrite()).isTrue(); assertThat(dir.canRead()).isTrue(); assertThat(Testing.Files.inTestDataDir(dir)).isTrue(); }
@Test public void shouldKnowDirectoriesInsideTestData() { assertThat(Testing.Files.inTestDataDir(Paths.get(Testing.Files.dataDir(), "somefile"))).isTrue(); assertThat(Testing.Files.inTestDataDir(new File("../debezium").toPath())).isFalse(); }