Skip to content

Commit ce5b0d0

Browse files
authored
Merge pull request #2308 from adobe/integration-tests-kotlin-sdk
Add Kotlin SDK ITs, simplifications
2 parents dc557f4 + b1d7916 commit ce5b0d0

File tree

5 files changed

+184
-143
lines changed

5 files changed

+184
-143
lines changed

integration-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@
131131
<artifactId>s3-transfer-manager</artifactId>
132132
<scope>test</scope>
133133
</dependency>
134+
<dependency>
135+
<groupId>aws.sdk.kotlin</groupId>
136+
<artifactId>s3-jvm</artifactId>
137+
<scope>test</scope>
138+
</dependency>
134139
</dependencies>
135140

136141
<build>

integration-tests/src/test/kotlin/com/adobe/testing/s3mock/its/AclITV2.kt

Lines changed: 44 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2024 Adobe.
2+
* Copyright 2017-2025 Adobe.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,16 +21,10 @@ import org.assertj.core.api.Assertions.assertThat
2121
import org.junit.jupiter.api.Test
2222
import org.junit.jupiter.api.TestInfo
2323
import software.amazon.awssdk.services.s3.S3Client
24-
import software.amazon.awssdk.services.s3.model.AccessControlPolicy
25-
import software.amazon.awssdk.services.s3.model.CreateBucketRequest
26-
import software.amazon.awssdk.services.s3.model.GetObjectAclRequest
2724
import software.amazon.awssdk.services.s3.model.Grant
28-
import software.amazon.awssdk.services.s3.model.Grantee
2925
import software.amazon.awssdk.services.s3.model.ObjectCannedACL
3026
import software.amazon.awssdk.services.s3.model.ObjectOwnership
31-
import software.amazon.awssdk.services.s3.model.Owner
3227
import software.amazon.awssdk.services.s3.model.Permission.FULL_CONTROL
33-
import software.amazon.awssdk.services.s3.model.PutObjectAclRequest
3428
import software.amazon.awssdk.services.s3.model.Type.CANONICAL_USER
3529

3630
internal class AclITV2 : S3TestBase() {
@@ -43,33 +37,27 @@ internal class AclITV2 : S3TestBase() {
4337
val bucketName = bucketName(testInfo)
4438

4539
//create bucket that sets ownership to non-default to allow setting ACLs.
46-
s3ClientV2.createBucket(CreateBucketRequest
47-
.builder()
48-
.bucket(bucketName)
49-
.objectOwnership(ObjectOwnership.OBJECT_WRITER)
50-
.build()
51-
)
40+
s3ClientV2.createBucket {
41+
it.bucket(bucketName)
42+
it.objectOwnership(ObjectOwnership.OBJECT_WRITER)
43+
}.also {
44+
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
45+
}
5246

5347
givenObjectV2(bucketName, sourceKey)
5448

55-
s3ClientV2.putObjectAcl(
56-
PutObjectAclRequest
57-
.builder()
58-
.bucket(bucketName)
59-
.key(sourceKey)
60-
.acl(ObjectCannedACL.PRIVATE)
61-
.build()
62-
).also {
49+
s3ClientV2.putObjectAcl {
50+
it.bucket(bucketName)
51+
it.key(sourceKey)
52+
it.acl(ObjectCannedACL.PRIVATE)
53+
}.also {
6354
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
6455
}
6556

66-
s3ClientV2.getObjectAcl(
67-
GetObjectAclRequest
68-
.builder()
69-
.bucket(bucketName)
70-
.key(sourceKey)
71-
.build()
72-
).also {
57+
s3ClientV2.getObjectAcl {
58+
it.bucket(bucketName)
59+
it.key(sourceKey)
60+
}.also {
7361
assertThat(it.sdkHttpResponse().isSuccessful).isTrue()
7462
assertThat(it.owner().id()).isNotBlank()
7563
assertThat(it.owner().displayName()).isNotBlank()
@@ -85,13 +73,10 @@ internal class AclITV2 : S3TestBase() {
8573
val sourceKey = UPLOAD_FILE_NAME
8674
val (bucketName, _) = givenBucketAndObjectV2(testInfo, sourceKey)
8775

88-
val acl = s3ClientV2.getObjectAcl(
89-
GetObjectAclRequest
90-
.builder()
91-
.bucket(bucketName)
92-
.key(sourceKey)
93-
.build()
94-
)
76+
val acl = s3ClientV2.getObjectAcl {
77+
it.bucket(bucketName)
78+
it.key(sourceKey)
79+
}
9580

9681
acl.owner().also { owner ->
9782
assertThat(owner.id()).isEqualTo(DEFAULT_OWNER.id)
@@ -124,34 +109,30 @@ internal class AclITV2 : S3TestBase() {
124109
val granteeId = "79a59df900b949e55d96a1e698fbacedfd6e09d98eacf8f8d5218e7cd47ef2ef"
125110
val granteeName = "Jane Doe"
126111
val granteeEmail = "jane@doe.com"
127-
s3ClientV2.putObjectAcl(
128-
PutObjectAclRequest
129-
.builder()
130-
.bucket(bucketName)
131-
.key(sourceKey)
132-
.accessControlPolicy(
133-
AccessControlPolicy
134-
.builder()
135-
.owner(Owner.builder().id(userId).displayName(userName).build())
136-
.grants(
137-
Grant.builder()
138-
.permission(FULL_CONTROL)
139-
.grantee(
140-
Grantee.builder().id(granteeId).displayName(granteeName)
141-
.type(CANONICAL_USER).build()
142-
).build()
143-
).build()
144-
)
145-
.build()
146-
)
147-
148-
val acl = s3ClientV2.getObjectAcl(
149-
GetObjectAclRequest
150-
.builder()
151-
.bucket(bucketName)
152-
.key(sourceKey)
153-
.build()
154-
)
112+
s3ClientV2.putObjectAcl {
113+
it.bucket(bucketName)
114+
it.key(sourceKey)
115+
it.accessControlPolicy {
116+
it.owner {
117+
it.id(userId)
118+
it.displayName(userName)
119+
}
120+
it.grants(
121+
Grant.builder()
122+
.permission(FULL_CONTROL)
123+
.grantee {
124+
it.id(granteeId)
125+
it.displayName(granteeName)
126+
it.type(CANONICAL_USER)
127+
}.build()
128+
).build()
129+
}
130+
}
131+
132+
val acl = s3ClientV2.getObjectAcl {
133+
it.bucket(bucketName)
134+
it.key(sourceKey)
135+
}
155136
acl.owner().also {
156137
assertThat(it).isNotNull
157138
assertThat(it.id()).isEqualTo(userId)
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2017-2025 Adobe.
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+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.adobe.testing.s3mock.its
18+
19+
import aws.sdk.kotlin.services.s3.model.CreateBucketRequest
20+
import aws.sdk.kotlin.services.s3.model.DeleteBucketRequest
21+
import aws.sdk.kotlin.services.s3.model.HeadBucketRequest
22+
import aws.sdk.kotlin.services.s3.model.S3Exception
23+
import aws.sdk.kotlin.services.s3.waiters.waitUntilBucketExists
24+
import aws.sdk.kotlin.services.s3.waiters.waitUntilBucketNotExists
25+
import kotlinx.coroutines.runBlocking
26+
import org.assertj.core.api.Assertions.assertThatThrownBy
27+
import org.junit.jupiter.api.Test
28+
import org.junit.jupiter.api.TestInfo
29+
30+
internal class KotlinSDKIT: S3TestBase() {
31+
private val s3Client = createS3ClientKotlin()
32+
33+
@Test
34+
@S3VerifiedTodo
35+
fun createAndDeleteBucket(testInfo: TestInfo) : Unit = runBlocking {
36+
val bucketName = bucketName(testInfo)
37+
s3Client.createBucket(CreateBucketRequest { bucket = bucketName })
38+
39+
s3Client.waitUntilBucketExists(HeadBucketRequest { bucket = bucketName })
40+
41+
//does not throw exception if bucket exists.
42+
s3Client.headBucket(HeadBucketRequest { bucket = bucketName })
43+
44+
s3Client.deleteBucket(DeleteBucketRequest { bucket = bucketName })
45+
s3Client.waitUntilBucketNotExists(HeadBucketRequest { bucket = bucketName })
46+
47+
//throws exception if bucket does not exist.
48+
assertThatThrownBy {
49+
runBlocking {
50+
s3Client.headBucket(HeadBucketRequest { bucket = bucketName })
51+
}
52+
}.isInstanceOf(S3Exception::class.java)
53+
}
54+
}

0 commit comments

Comments
 (0)