Skip to content

Commit 8334f77

Browse files
committed
Migrate "testcontainers" package to Kotlin, add Java tests
1 parent 9e0cf67 commit 8334f77

File tree

8 files changed

+408
-122
lines changed

8 files changed

+408
-122
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
<xmlunit-assertj3.version>2.10.3</xmlunit-assertj3.version>
136136
<spring-test-profiler.version>0.0.11</spring-test-profiler.version>
137137
<ktlint-maven-plugin.version>3.5.0</ktlint-maven-plugin.version>
138+
<jetbrains-annotations.version>26.0.2-1</jetbrains-annotations.version>
138139
</properties>
139140

140141
<dependencyManagement>
@@ -339,6 +340,11 @@
339340
<artifactId>jspecify</artifactId>
340341
<version>${jspecify.version}</version>
341342
</dependency>
343+
<dependency>
344+
<groupId>org.jetbrains</groupId>
345+
<artifactId>annotations</artifactId>
346+
<version>${jetbrains-annotations.version}</version>
347+
</dependency>
342348
<dependency>
343349
<groupId>org.mockito</groupId>
344350
<artifactId>mockito-core</artifactId>

testsupport/testcontainers/pom.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@
4848
<groupId>org.testcontainers</groupId>
4949
<artifactId>testcontainers</artifactId>
5050
</dependency>
51+
<dependency>
52+
<groupId>org.jetbrains.kotlin</groupId>
53+
<artifactId>kotlin-stdlib</artifactId>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.jetbrains</groupId>
57+
<artifactId>annotations</artifactId>
58+
</dependency>
5159
<dependency>
5260
<groupId>org.apache.commons</groupId>
5361
<artifactId>commons-compress</artifactId>

testsupport/testcontainers/src/main/java/com/adobe/testing/s3mock/testcontainers/package-info.java

Lines changed: 0 additions & 20 deletions
This file was deleted.

testsupport/testcontainers/src/main/kotlin/com/adobe/testing/s3mock/testcontainers/S3MockContainer.kt

Lines changed: 97 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -13,111 +13,106 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
package com.adobe.testing.s3mock.testcontainers
1617

17-
package com.adobe.testing.s3mock.testcontainers;
18-
19-
import java.nio.file.Path;
20-
import org.testcontainers.containers.BindMode;
21-
import org.testcontainers.containers.GenericContainer;
22-
import org.testcontainers.containers.wait.strategy.Wait;
23-
import org.testcontainers.utility.DockerImageName;
18+
import org.testcontainers.containers.BindMode
19+
import org.testcontainers.containers.GenericContainer
20+
import org.testcontainers.containers.wait.strategy.Wait
21+
import org.testcontainers.utility.DockerImageName
22+
import java.nio.file.Path
2423

2524
/**
2625
* Testcontainer for S3Mock.
2726
*/
28-
public class S3MockContainer extends GenericContainer<S3MockContainer> {
29-
public static final String IMAGE_NAME = "adobe/s3mock";
30-
private static final int S3MOCK_DEFAULT_HTTP_PORT = 9090;
31-
private static final int S3MOCK_DEFAULT_HTTPS_PORT = 9191;
32-
private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse(IMAGE_NAME);
33-
private static final String PROP_INITIAL_BUCKETS = "COM_ADOBE_TESTING_S3MOCK_STORE_INITIAL_BUCKETS";
34-
private static final String PROP_ROOT_DIRECTORY = "COM_ADOBE_TESTING_S3MOCK_STORE_ROOT";
35-
private static final String PROP_VALID_KMS_KEYS = "COM_ADOBE_TESTING_S3MOCK_STORE_VALID_KMS_KEYS";
36-
private static final String PROP_REGION = "COM_ADOBE_TESTING_S3MOCK_STORE_REGION";
37-
private static final String PROP_RETAIN_FILES_ON_EXIT = "COM_ADOBE_TESTING_S3MOCK_STORE_RETAIN_FILES_ON_EXIT";
38-
39-
/**
40-
* Create a S3MockContainer.
41-
*
42-
* @param tag in the format of "2.1.27"
43-
*/
44-
public S3MockContainer(String tag) {
45-
this(DEFAULT_IMAGE_NAME.withTag(tag));
46-
}
47-
48-
/**
49-
* Create a S3MockContainer.
50-
*
51-
* @param dockerImageName in the format of {@link DockerImageName#parse(String)} where the
52-
* parameter is the full image name like "adobe/s3mock:2.1.27"
53-
*/
54-
public S3MockContainer(DockerImageName dockerImageName) {
55-
super(dockerImageName);
56-
57-
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
58-
addExposedPort(S3MOCK_DEFAULT_HTTP_PORT);
59-
addExposedPort(S3MOCK_DEFAULT_HTTPS_PORT);
60-
waitingFor(Wait.forHttp("/favicon.ico")
61-
.forPort(S3MOCK_DEFAULT_HTTP_PORT)
62-
.withMethod("GET")
63-
.forStatusCode(200));
64-
}
65-
66-
public S3MockContainer withRegion(String region) {
67-
this.addEnv(PROP_REGION, region);
68-
return self();
69-
}
70-
71-
public S3MockContainer withRetainFilesOnExit(boolean retainFilesOnExit) {
72-
this.addEnv(PROP_RETAIN_FILES_ON_EXIT, String.valueOf(retainFilesOnExit));
73-
return self();
74-
}
75-
76-
public S3MockContainer withValidKmsKeys(String kmsKeys) {
77-
this.addEnv(PROP_VALID_KMS_KEYS, kmsKeys);
78-
return self();
79-
}
80-
81-
public S3MockContainer withInitialBuckets(String initialBuckets) {
82-
this.addEnv(PROP_INITIAL_BUCKETS, initialBuckets);
83-
return self();
84-
}
85-
86-
/**
87-
* Mount a volume from the host system for the S3Mock to use as the "root".
88-
* Docker must be able to read / write into this directory (!)
89-
*
90-
* @param root absolute path in host system
91-
*/
92-
public S3MockContainer withVolumeAsRoot(String root) {
93-
this.withFileSystemBind(root, "/s3mockroot", BindMode.READ_WRITE);
94-
this.addEnv(PROP_ROOT_DIRECTORY, "/s3mockroot");
95-
return self();
96-
}
97-
98-
/**
99-
* Mount a volume from the host system for the S3Mock to use as the "root".
100-
* Docker must be able to read / write into this directory (!)
101-
*
102-
* @param root absolute path in host system
103-
*/
104-
public S3MockContainer withVolumeAsRoot(Path root) {
105-
return this.withVolumeAsRoot(root.toString());
106-
}
107-
108-
public String getHttpEndpoint() {
109-
return String.format("http://%s:%d", getHost(), getHttpServerPort());
110-
}
111-
112-
public String getHttpsEndpoint() {
113-
return String.format("https://%s:%d", getHost(), getHttpsServerPort());
114-
}
115-
116-
public Integer getHttpServerPort() {
117-
return getMappedPort(S3MOCK_DEFAULT_HTTP_PORT);
118-
}
119-
120-
public Integer getHttpsServerPort() {
121-
return getMappedPort(S3MOCK_DEFAULT_HTTPS_PORT);
122-
}
27+
class S3MockContainer(dockerImageName: DockerImageName) : GenericContainer<S3MockContainer>(dockerImageName) {
28+
/**
29+
* Create a S3MockContainer.
30+
*
31+
* @param tag in the format of "2.1.27"
32+
*/
33+
constructor(tag: String) : this(DEFAULT_IMAGE_NAME.withTag(tag))
34+
35+
/**
36+
* Create a S3MockContainer.
37+
*
38+
* @param dockerImageName in the format of [DockerImageName.parse] where the
39+
* parameter is the full image name like "adobe/s3mock:2.1.27"
40+
*/
41+
init {
42+
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME)
43+
addExposedPort(S3MOCK_DEFAULT_HTTP_PORT)
44+
addExposedPort(S3MOCK_DEFAULT_HTTPS_PORT)
45+
waitingFor(
46+
Wait.forHttp("/favicon.ico")
47+
.forPort(S3MOCK_DEFAULT_HTTP_PORT)
48+
.withMethod("GET")
49+
.forStatusCode(200)
50+
)
51+
}
52+
53+
fun withRegion(region: String): S3MockContainer {
54+
this.addEnv(PROP_REGION, region)
55+
return self()
56+
}
57+
58+
fun withRetainFilesOnExit(retainFilesOnExit: Boolean): S3MockContainer {
59+
this.addEnv(PROP_RETAIN_FILES_ON_EXIT, retainFilesOnExit.toString())
60+
return self()
61+
}
62+
63+
fun withValidKmsKeys(kmsKeys: String): S3MockContainer {
64+
this.addEnv(PROP_VALID_KMS_KEYS, kmsKeys)
65+
return self()
66+
}
67+
68+
fun withInitialBuckets(initialBuckets: String): S3MockContainer {
69+
this.addEnv(PROP_INITIAL_BUCKETS, initialBuckets)
70+
return self()
71+
}
72+
73+
/**
74+
* Mount a volume from the host system for the S3Mock to use as the "root".
75+
* Docker must be able to read / write into this directory (!)
76+
*
77+
* @param root absolute path in host system
78+
*/
79+
fun withVolumeAsRoot(root: String): S3MockContainer {
80+
this.withFileSystemBind(root, "/s3mockroot", BindMode.READ_WRITE)
81+
this.addEnv(PROP_ROOT_DIRECTORY, "/s3mockroot")
82+
return self()
83+
}
84+
85+
/**
86+
* Mount a volume from the host system for the S3Mock to use as the "root".
87+
* Docker must be able to read / write into this directory (!)
88+
*
89+
* @param root absolute path in host system
90+
*/
91+
fun withVolumeAsRoot(root: Path): S3MockContainer {
92+
return this.withVolumeAsRoot(root.toString())
93+
}
94+
95+
val httpEndpoint: String
96+
get() = "http://$host:$httpServerPort"
97+
98+
val httpsEndpoint: String
99+
get() = "https://$host:$httpsServerPort"
100+
101+
val httpServerPort: Int
102+
get() = getMappedPort(S3MOCK_DEFAULT_HTTP_PORT)
103+
104+
val httpsServerPort: Int
105+
get() = getMappedPort(S3MOCK_DEFAULT_HTTPS_PORT)
106+
107+
companion object {
108+
const val IMAGE_NAME: String = "adobe/s3mock"
109+
private const val S3MOCK_DEFAULT_HTTP_PORT = 9090
110+
private const val S3MOCK_DEFAULT_HTTPS_PORT = 9191
111+
private val DEFAULT_IMAGE_NAME: DockerImageName = DockerImageName.parse(IMAGE_NAME)
112+
private const val PROP_INITIAL_BUCKETS = "COM_ADOBE_TESTING_S3MOCK_STORE_INITIAL_BUCKETS"
113+
private const val PROP_ROOT_DIRECTORY = "COM_ADOBE_TESTING_S3MOCK_STORE_ROOT"
114+
private const val PROP_VALID_KMS_KEYS = "COM_ADOBE_TESTING_S3MOCK_STORE_VALID_KMS_KEYS"
115+
private const val PROP_REGION = "COM_ADOBE_TESTING_S3MOCK_STORE_REGION"
116+
private const val PROP_RETAIN_FILES_ON_EXIT = "COM_ADOBE_TESTING_S3MOCK_STORE_RETAIN_FILES_ON_EXIT"
117+
}
123118
}

0 commit comments

Comments
 (0)