2121import static java .net .HttpURLConnection .HTTP_NOT_IMPLEMENTED ;
2222import static java .net .HttpURLConnection .HTTP_OK ;
2323import static org .junit .jupiter .api .Assertions .assertEquals ;
24+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
2425import static org .junit .jupiter .api .Assertions .assertThrows ;
2526import static org .mockito .Mockito .mock ;
2627import static org .mockito .Mockito .when ;
@@ -79,6 +80,15 @@ public void clean() throws IOException {
7980 }
8081 }
8182
83+ /**
84+ * Helper method to get ACL from bucket and validate response.
85+ */
86+ private S3BucketAcl getBucketAcl (String bucketName ) throws Exception {
87+ Response response = bucketEndpoint .get (bucketName );
88+ assertEquals (HTTP_OK , response .getStatus ());
89+ return assertInstanceOf (S3BucketAcl .class , response .getEntity ());
90+ }
91+
8292 @ Test
8393 public void testGetAcl () throws Exception {
8494 when (parameterMap .containsKey (ACL_MARKER )).thenReturn (true );
@@ -105,7 +115,7 @@ public void testRead() throws Exception {
105115 Response response =
106116 bucketEndpoint .put (BUCKET_NAME , null );
107117 assertEquals (HTTP_OK , response .getStatus ());
108- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
118+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
109119 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
110120 assertEquals (S3Acl .ACLType .READ .getValue (),
111121 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -119,7 +129,7 @@ public void testWrite() throws Exception {
119129 Response response =
120130 bucketEndpoint .put (BUCKET_NAME , null );
121131 assertEquals (HTTP_OK , response .getStatus ());
122- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
132+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
123133 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
124134 assertEquals (S3Acl .ACLType .WRITE .getValue (),
125135 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -133,8 +143,7 @@ public void testReadACP() throws Exception {
133143 Response response =
134144 bucketEndpoint .put (BUCKET_NAME , null );
135145 assertEquals (HTTP_OK , response .getStatus ());
136- S3BucketAcl getResponse =
137- bucketEndpoint .getAcl (BUCKET_NAME );
146+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
138147 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
139148 assertEquals (S3Acl .ACLType .READ_ACP .getValue (),
140149 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -148,7 +157,7 @@ public void testWriteACP() throws Exception {
148157 Response response =
149158 bucketEndpoint .put (BUCKET_NAME , null );
150159 assertEquals (HTTP_OK , response .getStatus ());
151- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
160+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
152161 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
153162 assertEquals (S3Acl .ACLType .WRITE_ACP .getValue (),
154163 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -162,7 +171,7 @@ public void testFullControl() throws Exception {
162171 Response response =
163172 bucketEndpoint .put (BUCKET_NAME , null );
164173 assertEquals (HTTP_OK , response .getStatus ());
165- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
174+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
166175 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
167176 assertEquals (S3Acl .ACLType .FULL_CONTROL .getValue (),
168177 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -184,7 +193,7 @@ public void testCombination() throws Exception {
184193 Response response =
185194 bucketEndpoint .put (BUCKET_NAME , null );
186195 assertEquals (HTTP_OK , response .getStatus ());
187- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
196+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
188197 assertEquals (5 , getResponse .getAclList ().getGrantList ().size ());
189198 }
190199
@@ -197,7 +206,7 @@ public void testPutClearOldAcls() throws Exception {
197206 Response response =
198207 bucketEndpoint .put (BUCKET_NAME , null );
199208 assertEquals (HTTP_OK , response .getStatus ());
200- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
209+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
201210 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
202211 assertEquals (S3Acl .ACLType .READ .getValue (),
203212 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -214,7 +223,7 @@ public void testPutClearOldAcls() throws Exception {
214223 response =
215224 bucketEndpoint .put (BUCKET_NAME , null );
216225 assertEquals (HTTP_OK , response .getStatus ());
217- getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
226+ getResponse = getBucketAcl (BUCKET_NAME );
218227 assertEquals (1 , getResponse .getAclList ().getGrantList ().size ());
219228 assertEquals (S3Acl .ACLType .WRITE .getValue (),
220229 getResponse .getAclList ().getGrantList ().get (0 ).getPermission ());
@@ -241,7 +250,7 @@ public void testAclInBody() throws Exception {
241250 Response response =
242251 bucketEndpoint .put (BUCKET_NAME , inputBody );
243252 assertEquals (HTTP_OK , response .getStatus ());
244- S3BucketAcl getResponse = bucketEndpoint . getAcl (BUCKET_NAME );
253+ S3BucketAcl getResponse = getBucketAcl (BUCKET_NAME );
245254 assertEquals (2 , getResponse .getAclList ().getGrantList ().size ());
246255 }
247256
@@ -251,7 +260,7 @@ public void testBucketNotExist() throws Exception {
251260 when (headers .getHeaderString (S3Acl .GRANT_READ ))
252261 .thenReturn (S3Acl .ACLIdentityType .USER .getHeaderType () + "=root" );
253262 OS3Exception e = assertThrows (OS3Exception .class , () ->
254- bucketEndpoint .getAcl ("bucket-not-exist" ));
263+ bucketEndpoint .get ("bucket-not-exist" ));
255264 assertEquals (e .getHttpCode (), HTTP_NOT_FOUND );
256265 }
257266}
0 commit comments