1616
1717package com .google .gcloud .storage ;
1818
19+ import static com .google .gcloud .storage .Acl .Project .ProjectRole .VIEWERS ;
20+ import static com .google .gcloud .storage .Acl .Role .READER ;
21+ import static com .google .gcloud .storage .Acl .Role .WRITER ;
1922import static org .easymock .EasyMock .capture ;
2023import static org .easymock .EasyMock .createMock ;
2124import static org .easymock .EasyMock .createStrictMock ;
3033import com .google .common .collect .ImmutableList ;
3134import com .google .gcloud .Page ;
3235import com .google .gcloud .PageImpl ;
36+ import com .google .gcloud .storage .Acl .Project ;
37+ import com .google .gcloud .storage .Acl .User ;
3338import com .google .gcloud .storage .BatchResponse .Result ;
39+ import com .google .gcloud .storage .BucketInfo .AgeDeleteRule ;
40+ import com .google .gcloud .storage .BucketInfo .DeleteRule ;
3441
3542import org .easymock .Capture ;
3643import org .junit .After ;
44+ import org .junit .Before ;
3745import org .junit .Test ;
3846
3947import java .io .ByteArrayInputStream ;
4654
4755public class BucketTest {
4856
57+ private static final List <Acl > ACL = ImmutableList .of (
58+ Acl .of (User .ofAllAuthenticatedUsers (), READER ), Acl .of (new Project (VIEWERS , "p1" ), WRITER ));
59+ private static final String ETAG = "0xFF00" ;
60+ private static final String ID = "B/N:1" ;
61+ private static final Long META_GENERATION = 10L ;
62+ private static final User OWNER =
new User (
"[email protected] " );
63+ private static final String SELF_LINK = "http://storage/b/n" ;
64+ private static final Long CREATE_TIME = System .currentTimeMillis ();
65+ private static final List <Cors > CORS = Collections .singletonList (Cors .builder ().build ());
66+ private static final List <Acl > DEFAULT_ACL =
67+ Collections .singletonList (Acl .of (User .ofAllAuthenticatedUsers (), WRITER ));
68+ private static final List <? extends DeleteRule > DELETE_RULES =
69+ Collections .singletonList (new AgeDeleteRule (5 ));
70+ private static final String INDEX_PAGE = "index.html" ;
71+ private static final String NOT_FOUND_PAGE = "error.html" ;
72+ private static final String LOCATION = "ASIA" ;
73+ private static final String STORAGE_CLASS = "STANDARD" ;
74+ private static final Boolean VERSIONING_ENABLED = true ;
75+ private static final BucketInfo FULL_BUCKET_INFO = BucketInfo .builder ("b" )
76+ .acl (ACL )
77+ .etag (ETAG )
78+ .id (ID )
79+ .metageneration (META_GENERATION )
80+ .owner (OWNER )
81+ .selfLink (SELF_LINK )
82+ .cors (CORS )
83+ .createTime (CREATE_TIME )
84+ .defaultAcl (DEFAULT_ACL )
85+ .deleteRules (DELETE_RULES )
86+ .indexPage (INDEX_PAGE )
87+ .notFoundPage (NOT_FOUND_PAGE )
88+ .location (LOCATION )
89+ .storageClass (STORAGE_CLASS )
90+ .versioningEnabled (VERSIONING_ENABLED )
91+ .build ();
4992 private static final BucketInfo BUCKET_INFO = BucketInfo .builder ("b" ).metageneration (42L ).build ();
5093 private static final String CONTENT_TYPE = "text/plain" ;
5194
@@ -56,6 +99,11 @@ public class BucketTest {
5699 private Bucket expectedBucket ;
57100 private Iterable <Blob > blobResults ;
58101
102+ @ Before
103+ public void setUp () {
104+ storage = createStrictMock (Storage .class );
105+ }
106+
59107 @ After
60108 public void tearDown () throws Exception {
61109 verify (storage );
@@ -64,7 +112,6 @@ public void tearDown() throws Exception {
64112 private void initializeExpectedBucket (int optionsCalls ) {
65113 expect (serviceMockReturnsOptions .options ()).andReturn (mockOptions ).times (optionsCalls );
66114 replay (serviceMockReturnsOptions );
67- storage = createStrictMock (Storage .class );
68115 expectedBucket = new Bucket (serviceMockReturnsOptions , new BucketInfo .BuilderImpl (BUCKET_INFO ));
69116 blobResults = ImmutableList .of (
70117 new Blob (serviceMockReturnsOptions ,
@@ -283,4 +330,14 @@ public void testCreateFromStreamNullContentType() throws Exception {
283330 Blob blob = bucket .create ("n" , streamContent , null );
284331 assertEquals (expectedBlob , blob );
285332 }
333+
334+ @ Test
335+ public void testToBuilder () {
336+ expect (storage .options ()).andReturn (mockOptions ).times (4 );
337+ replay (storage );
338+ Bucket fullBucket = new Bucket (storage , new BucketInfo .BuilderImpl (FULL_BUCKET_INFO ));
339+ assertEquals (fullBucket , fullBucket .toBuilder ().build ());
340+ Bucket simpleBlob = new Bucket (storage , new BucketInfo .BuilderImpl (BUCKET_INFO ));
341+ assertEquals (simpleBlob , simpleBlob .toBuilder ().build ());
342+ }
286343}
0 commit comments