|
26 | 26 | import static org.junit.Assert.assertSame;
|
27 | 27 |
|
28 | 28 | import com.google.api.client.http.HttpResponseException;
|
| 29 | +import com.google.cloud.storage.Blob; |
29 | 30 | import com.google.cloud.storage.BlobInfo;
|
30 | 31 | import com.google.cloud.storage.Bucket;
|
31 | 32 | import com.google.cloud.storage.BucketInfo;
|
|
37 | 38 | import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem;
|
38 | 39 | import com.google.cloud.storage.contrib.nio.CloudStorageFileSystemProvider;
|
39 | 40 | import com.google.cloud.storage.contrib.nio.CloudStoragePath;
|
| 41 | +import com.google.cloud.storage.contrib.nio.testing.LocalStorageHelper; |
40 | 42 | import com.google.cloud.storage.testing.RemoteStorageHelper;
|
41 | 43 | import com.google.common.collect.ImmutableList;
|
| 44 | +import com.google.common.collect.Lists; |
42 | 45 | import com.google.common.collect.Sets;
|
43 | 46 | import java.io.ByteArrayOutputStream;
|
44 | 47 | import java.io.EOFException;
|
|
62 | 65 | import java.util.Arrays;
|
63 | 66 | import java.util.List;
|
64 | 67 | import java.util.Random;
|
| 68 | +import java.util.UUID; |
65 | 69 | import java.util.concurrent.ExecutionException;
|
66 | 70 | import java.util.concurrent.TimeUnit;
|
67 | 71 | import java.util.logging.Level;
|
@@ -1074,6 +1078,32 @@ public void testCopyWithDifferentProvider() throws IOException {
|
1074 | 1078 | assertNotEquals(sourceFileSystem.config(), targetFileSystem.config());
|
1075 | 1079 | }
|
1076 | 1080 |
|
| 1081 | + @Test |
| 1082 | + public void testListObject() throws IOException { |
| 1083 | + String firstBucket = "first-bucket-" + UUID.randomUUID().toString(); |
| 1084 | + String secondBucket = "second-bucket" + UUID.randomUUID().toString(); |
| 1085 | + Storage localStorageService = LocalStorageHelper.customOptions(true).getService(); |
| 1086 | + fillFile(localStorageService, firstBucket, "object", SML_SIZE); |
| 1087 | + fillFile(localStorageService, firstBucket, "test-object", SML_SIZE); |
| 1088 | + fillFile(localStorageService, secondBucket, "test-object", SML_SIZE); |
| 1089 | + |
| 1090 | + // Listing objects from first bucket without prefix. |
| 1091 | + List<Blob> objects = Lists.newArrayList(localStorageService.list(firstBucket).getValues()); |
| 1092 | + assertThat(objects.size()).isEqualTo(2); |
| 1093 | + |
| 1094 | + // Listing objects from first bucket with prefix. |
| 1095 | + objects = |
| 1096 | + Lists.newArrayList( |
| 1097 | + localStorageService |
| 1098 | + .list(firstBucket, Storage.BlobListOption.prefix("test-")) |
| 1099 | + .getValues()); |
| 1100 | + assertThat(objects.size()).isEqualTo(1); |
| 1101 | + |
| 1102 | + // Listing objects from second bucket. |
| 1103 | + objects = Lists.newArrayList(localStorageService.list(secondBucket).getValues()); |
| 1104 | + assertThat(objects.size()).isEqualTo(1); |
| 1105 | + } |
| 1106 | + |
1077 | 1107 | private CloudStorageFileSystem getTestBucket() throws IOException {
|
1078 | 1108 | // in typical usage we use the single-argument version of forBucket
|
1079 | 1109 | // and rely on the user being logged into their project with the
|
|
0 commit comments