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 package software.amazon.awssdk.services.s3control; 16 17 import static org.assertj.core.api.Assertions.assertThat; 18 import static org.junit.Assert.assertNotNull; 19 import static software.amazon.awssdk.testutils.service.S3BucketUtils.temporaryBucketName; 20 21 import java.util.StringJoiner; 22 import org.junit.AfterClass; 23 import org.junit.BeforeClass; 24 import org.junit.Test; 25 import software.amazon.awssdk.core.sync.RequestBody; 26 import software.amazon.awssdk.regions.Region; 27 import software.amazon.awssdk.services.s3.model.GetObjectRequest; 28 import software.amazon.awssdk.services.s3.model.PutObjectRequest; 29 import software.amazon.awssdk.services.sts.StsClient; 30 31 public class S3AsyncAccessPointsIntegrationTest extends S3ControlIntegrationTestBase { 32 33 private static final String BUCKET = temporaryBucketName(S3AsyncAccessPointsIntegrationTest.class); 34 35 private static final String AP_NAME = "java-sdk-" + System.currentTimeMillis(); 36 37 private static final String KEY = "some-key"; 38 39 private static S3ControlAsyncClient s3control; 40 41 private static StsClient sts; 42 43 private static String accountId; 44 45 @BeforeClass setupFixture()46 public static void setupFixture() { 47 createBucket(BUCKET); 48 49 s3control = S3ControlAsyncClient.builder() 50 .region(Region.US_WEST_2) 51 .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN) 52 .build(); 53 54 sts = StsClient.builder() 55 .region(Region.US_WEST_2) 56 .credentialsProvider(CREDENTIALS_PROVIDER_CHAIN) 57 .build(); 58 59 accountId = sts.getCallerIdentity().account(); 60 s3control.createAccessPoint(r -> r.accountId(accountId) 61 .bucket(BUCKET) 62 .name(AP_NAME)) 63 .join(); 64 } 65 66 @AfterClass tearDown()67 public static void tearDown() { 68 s3control.deleteAccessPoint(b -> b.accountId(accountId).name(AP_NAME)).join(); 69 deleteBucketAndAllContents(BUCKET); 70 } 71 72 @Test accessPointOperation_nonArns()73 public void accessPointOperation_nonArns() { 74 assertNotNull(s3control.listAccessPoints(b -> b.bucket(BUCKET).accountId(accountId).maxResults(1)).join()); 75 assertNotNull(s3control.getAccessPoint(b -> b.name(AP_NAME).accountId(accountId)).join()); 76 } 77 78 @Test transfer_Succeeds_UsingAccessPoint()79 public void transfer_Succeeds_UsingAccessPoint() { 80 StringJoiner apArn = new StringJoiner(":"); 81 apArn.add("arn").add("aws").add("s3").add("us-west-2").add(accountId).add("accesspoint").add(AP_NAME); 82 83 s3.putObject(PutObjectRequest.builder() 84 .bucket(apArn.toString()) 85 .key(KEY) 86 .build(), RequestBody.fromString("helloworld")); 87 88 String objectContent = s3.getObjectAsBytes(GetObjectRequest.builder() 89 .bucket(apArn.toString()) 90 .key(KEY) 91 .build()).asUtf8String(); 92 93 assertThat(objectContent).isEqualTo("helloworld"); 94 } 95 } 96