Skip to content

Commit 65248cd

Browse files
committed
Add changelog and express bucket integ test
1 parent 860adb2 commit 65248cd

2 files changed

Lines changed: 81 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "feature",
3+
"category": "Amazon S3",
4+
"contributor": "",
5+
"description": "Added `doesObjectExist` and `doesBucketExist` convenience methods to S3Client and S3AsyncClient"
6+
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.services.s3.s3express;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName;
20+
21+
import org.junit.jupiter.api.AfterAll;
22+
import org.junit.jupiter.api.BeforeAll;
23+
import org.junit.jupiter.api.Test;
24+
import software.amazon.awssdk.core.sync.RequestBody;
25+
import software.amazon.awssdk.regions.Region;
26+
import software.amazon.awssdk.services.s3.S3Client;
27+
28+
/**
29+
* Verify that doesObjectExist/doesBucketExist extension methods work with S3 Express (directory buckets).
30+
*/
31+
class S3ExpressExtensionMethodsTest extends S3ExpressIntegrationTestBase {
32+
33+
private static final Region TEST_REGION = Region.US_EAST_1;
34+
private static final String AZ = "use1-az4";
35+
private static final String BUCKET = String.format(
36+
temporaryBucketName(S3ExpressExtensionMethodsTest.class) + "--%s--x-s3", AZ);
37+
private static final String KEY = "test-key";
38+
39+
private static S3Client s3;
40+
41+
@BeforeAll
42+
static void setup() {
43+
s3 = s3ClientBuilder(TEST_REGION).build();
44+
createBucketS3Express(s3, BUCKET, AZ);
45+
s3.putObject(r -> r.bucket(BUCKET).key(KEY), RequestBody.fromString("hello"));
46+
}
47+
48+
@AfterAll
49+
static void teardown() {
50+
deleteBucketAndAllContents(s3, BUCKET);
51+
s3.close();
52+
}
53+
54+
@Test
55+
void doesObjectExist_existingObject_returnsTrue() {
56+
assertThat(s3.doesObjectExist(BUCKET, KEY)).isTrue();
57+
}
58+
59+
@Test
60+
void doesObjectExist_nonExistentObject_returnsFalse() {
61+
assertThat(s3.doesObjectExist(BUCKET, "fake-key")).isFalse();
62+
}
63+
64+
@Test
65+
void doesBucketExist_existingBucket_returnsTrue() {
66+
assertThat(s3.doesBucketExist(BUCKET)).isTrue();
67+
}
68+
69+
@Test
70+
void doesBucketExist_nonExistentBucket_returnsFalse() {
71+
String fakeBucket = String.format(
72+
temporaryBucketName("nonexistent") + "--%s--x-s3", AZ);
73+
assertThat(s3.doesBucketExist(fakeBucket)).isFalse();
74+
}
75+
}

0 commit comments

Comments
 (0)