2626
2727import com .google .common .collect .ImmutableList ;
2828import com .google .common .collect .ImmutableMap ;
29+ import com .google .gcloud .Page ;
2930import com .google .gcloud .RestorableState ;
31+ import com .google .gcloud .storage .Storage .BlobField ;
32+ import com .google .gcloud .storage .Storage .BucketField ;
3033import com .google .gcloud .storage .testing .RemoteGcsHelper ;
3134
3235import org .junit .AfterClass ;
@@ -80,17 +83,49 @@ public static void afterClass()
8083
8184 @ Test (timeout = 5000 )
8285 public void testListBuckets () throws InterruptedException {
83- Iterator <BucketInfo > bucketIterator =
84- storage . list ( Storage .BucketListOption .prefix ( BUCKET )).values ().iterator ();
86+ Iterator <BucketInfo > bucketIterator = storage . list ( Storage . BucketListOption . prefix ( BUCKET ),
87+ Storage .BucketListOption .fields ( )).values ().iterator ();
8588 while (!bucketIterator .hasNext ()) {
8689 Thread .sleep (500 );
87- bucketIterator = storage .list (Storage .BucketListOption .prefix (BUCKET )).values ().iterator ();
90+ bucketIterator = storage .list (Storage .BucketListOption .prefix (BUCKET ),
91+ Storage .BucketListOption .fields ()).values ().iterator ();
8892 }
8993 while (bucketIterator .hasNext ()) {
90- assertTrue (bucketIterator .next ().name ().startsWith (BUCKET ));
94+ BucketInfo remoteBucket = bucketIterator .next ();
95+ assertTrue (remoteBucket .name ().startsWith (BUCKET ));
96+ assertNull (remoteBucket .createTime ());
97+ assertNull (remoteBucket .selfLink ());
9198 }
9299 }
93100
101+ @ Test
102+ public void testGetBucketSelectedFields () {
103+ BucketInfo remoteBucket = storage .get (BUCKET , Storage .BucketGetOption .fields (BucketField .ID ));
104+ assertEquals (BUCKET , remoteBucket .name ());
105+ assertNull (remoteBucket .createTime ());
106+ assertNotNull (remoteBucket .id ());
107+ }
108+
109+ @ Test
110+ public void testGetBucketAllSelectedFields () {
111+ BucketInfo remoteBucket = storage .get (BUCKET , Storage .BucketGetOption .fields (BucketField .ACL ,
112+ BucketField .CORS , BucketField .DEFAULT_OBJECT_ACL , BucketField .ETAG , BucketField .ID ,
113+ BucketField .LOCATION , BucketField .METAGENERATION , BucketField .NAME , BucketField .OWNER ,
114+ BucketField .SELF_LINK , BucketField .STORAGE_CLASS , BucketField .TIME_CREATED ,
115+ BucketField .VERSIONING , BucketField .WEBSITE ));
116+ assertEquals (BUCKET , remoteBucket .name ());
117+ assertNotNull (remoteBucket .createTime ());
118+ assertNotNull (remoteBucket .selfLink ());
119+ }
120+
121+ @ Test
122+ public void testGetBucketEmptyFields () {
123+ BucketInfo remoteBucket = storage .get (BUCKET , Storage .BucketGetOption .fields ());
124+ assertEquals (BUCKET , remoteBucket .name ());
125+ assertNull (remoteBucket .createTime ());
126+ assertNull (remoteBucket .selfLink ());
127+ }
128+
94129 @ Test
95130 public void testCreateBlob () {
96131 String blobName = "test-create-blob" ;
@@ -180,13 +215,35 @@ public void testGetBlobSelectedFields() {
180215 .build ();
181216 assertNotNull (storage .create (blob ));
182217 BlobInfo remoteBlob = storage .get (blob .blobId (), Storage .BlobGetOption .fields (
183- Storage . BlobField .METADATA ));
218+ BlobField .METADATA ));
184219 assertEquals (blob .blobId (), remoteBlob .blobId ());
185220 assertEquals (ImmutableMap .of ("k" , "v" ), remoteBlob .metadata ());
186221 assertNull (remoteBlob .contentType ());
187222 assertTrue (storage .delete (BUCKET , blobName ));
188223 }
189224
225+ @ Test
226+ public void testGetBlobAllSelectedFields () {
227+ String blobName = "test-get-all-selected-fields-blob" ;
228+ BlobInfo blob = BlobInfo .builder (BUCKET , blobName )
229+ .contentType (CONTENT_TYPE )
230+ .metadata (ImmutableMap .of ("k" , "v" ))
231+ .build ();
232+ assertNotNull (storage .create (blob ));
233+ BlobInfo remoteBlob = storage .get (blob .blobId (), Storage .BlobGetOption .fields (
234+ BlobField .ACL , BlobField .BUCKET , BlobField .CACHE_CONTROL , BlobField .COMPONENT_COUNT ,
235+ BlobField .CONTENT_DISPOSITION , BlobField .CONTENT_ENCODING , BlobField .CONTENT_LANGUAGE ,
236+ BlobField .CONTENT_TYPE , BlobField .CRC32C , BlobField .ETAG , BlobField .GENERATION ,
237+ BlobField .ID , BlobField .KIND , BlobField .MD5HASH , BlobField .MEDIA_LINK , BlobField .METADATA ,
238+ BlobField .METAGENERATION , BlobField .NAME , BlobField .OWNER , BlobField .SELF_LINK ,
239+ BlobField .SIZE , BlobField .STORAGE_CLASS , BlobField .TIME_DELETED , BlobField .UPDATED ));
240+ assertEquals (blob .blobId (), remoteBlob .blobId ());
241+ assertEquals (ImmutableMap .of ("k" , "v" ), remoteBlob .metadata ());
242+ assertNotNull (remoteBlob .id ());
243+ assertNotNull (remoteBlob .selfLink ());
244+ assertTrue (storage .delete (BUCKET , blobName ));
245+ }
246+
190247 @ Test
191248 public void testListBlobsSelectedFields () {
192249 String [] blobNames = {"test-list-blobs-selected-fields-blob1" ,
@@ -202,11 +259,11 @@ public void testListBlobsSelectedFields() {
202259 .build ();
203260 assertNotNull (storage .create (blob1 ));
204261 assertNotNull (storage .create (blob2 ));
205- ListResult <BlobInfo > result = storage .list (BUCKET ,
262+ Page <BlobInfo > page = storage .list (BUCKET ,
206263 Storage .BlobListOption .prefix ("test-list-blobs-selected-fields-blob" ),
207- Storage .BlobListOption .fields (Storage . BlobField .METADATA ));
264+ Storage .BlobListOption .fields (BlobField .METADATA ));
208265 int index = 0 ;
209- for (BlobInfo remoteBlob : result ) {
266+ for (BlobInfo remoteBlob : page . values () ) {
210267 assertEquals (BUCKET , remoteBlob .bucket ());
211268 assertEquals (blobNames [index ++], remoteBlob .name ());
212269 assertEquals (metadata , remoteBlob .metadata ());
@@ -228,11 +285,11 @@ public void testListBlobsEmptySelectedFields() {
228285 .build ();
229286 assertNotNull (storage .create (blob1 ));
230287 assertNotNull (storage .create (blob2 ));
231- ListResult <BlobInfo > result = storage .list (BUCKET ,
288+ Page <BlobInfo > page = storage .list (BUCKET ,
232289 Storage .BlobListOption .prefix ("test-list-blobs-empty-selected-fields-blob" ),
233290 Storage .BlobListOption .fields ());
234291 int index = 0 ;
235- for (BlobInfo remoteBlob : result ) {
292+ for (BlobInfo remoteBlob : page . values () ) {
236293 assertEquals (BUCKET , remoteBlob .bucket ());
237294 assertEquals (blobNames [index ++], remoteBlob .name ());
238295 assertNull (remoteBlob .contentType ());
0 commit comments