use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemTest method testNullness.
@Test
public void testNullness() throws IOException, NoSuchMethodException, SecurityException {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket"))) {
NullPointerTester tester = new NullPointerTester().ignore(CloudStorageFileSystem.class.getMethod("equals", Object.class)).setDefault(CloudStorageConfiguration.class, CloudStorageConfiguration.DEFAULT).setDefault(StorageOptions.class, LocalStorageHelper.getOptions());
tester.testAllPublicStaticMethods(CloudStorageFileSystem.class);
tester.testAllPublicInstanceMethods(fs);
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemProviderTest method testIsDirectory.
@Test
public void testIsDirectory() throws Exception {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://doodle"))) {
assertThat(Files.isDirectory(fs.getPath(""))).isTrue();
assertThat(Files.isDirectory(fs.getPath("/"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("./"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("cat/.."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("hello/cat/.."))).isTrue();
assertThat(Files.isDirectory(fs.getPath("cat/../"))).isTrue();
assertThat(Files.isDirectory(fs.getPath("hello/cat/../"))).isTrue();
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageFileSystemProviderTest method testNullness.
@Test
public void testNullness() throws Exception {
try (FileSystem fs = FileSystems.getFileSystem(URI.create("gs://blood"))) {
NullPointerTester tester = new NullPointerTester();
tester.ignore(CloudStorageFileSystemProvider.class.getMethod("equals", Object.class));
tester.setDefault(URI.class, URI.create("gs://blood"));
tester.setDefault(Path.class, fs.getPath("and/one"));
tester.setDefault(OpenOption.class, CREATE);
tester.setDefault(CopyOption.class, COPY_ATTRIBUTES);
// can't do that, setStorageOptions accepts a null argument.
// TODO(jart): Figure out how to re-enable this.
// tester.testAllPublicStaticMethods(CloudStorageFileSystemProvider.class);
tester.testAllPublicInstanceMethods(new CloudStorageFileSystemProvider());
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class ITGcsNio method testDeleteRecursive.
@Test
public void testDeleteRecursive() throws IOException {
try (FileSystem fs = getTestBucket()) {
List<Path> paths = new ArrayList<>();
paths.add(fs.getPath("Racine"));
paths.add(fs.getPath("playwrights/Moliere"));
paths.add(fs.getPath("playwrights/French/Corneille"));
for (Path path : paths) {
Files.write(path, FILE_CONTENTS, UTF_8);
}
deleteRecursive(fs.getPath("playwrights/"));
assertThat(Files.exists(fs.getPath("playwrights/Moliere"))).isFalse();
assertThat(Files.exists(fs.getPath("playwrights/French/Corneille"))).isFalse();
assertThat(Files.exists(fs.getPath("Racine"))).isTrue();
Files.deleteIfExists(fs.getPath("Racine"));
assertThat(Files.exists(fs.getPath("Racine"))).isFalse();
}
}
use of java.nio.file.FileSystem in project google-cloud-java by GoogleCloudPlatform.
the class ITGcsNio method testListFiles.
@Test
public void testListFiles() throws IOException {
try (FileSystem fs = getTestBucket()) {
List<Path> goodPaths = new ArrayList<>();
List<Path> paths = new ArrayList<>();
goodPaths.add(fs.getPath("dir/angel"));
goodPaths.add(fs.getPath("dir/alone"));
paths.add(fs.getPath("dir/dir2/another_angel"));
paths.add(fs.getPath("atroot"));
paths.addAll(goodPaths);
goodPaths.add(fs.getPath("dir/dir2/"));
for (Path path : paths) {
fillFile(storage, path.toString(), SML_SIZE);
}
List<Path> got = new ArrayList<>();
for (Path path : Files.newDirectoryStream(fs.getPath("/dir/"))) {
got.add(path);
}
assertThat(got).containsExactlyElementsIn(goodPaths);
// Must also work with relative path
got.clear();
for (Path path : Files.newDirectoryStream(fs.getPath("dir/"))) {
got.add(path);
}
assertThat(got).containsExactlyElementsIn(goodPaths);
}
}
Aggregations