Skip to content

Commit 6525567

Browse files
authored
Move Vault tests to JUnit Jupiter (#10768)
1 parent 13d688b commit 6525567

File tree

3 files changed

+32
-15
lines changed

3 files changed

+32
-15
lines changed

modules/vault/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ description = "Testcontainers :: Vault"
33
dependencies {
44
api project(':testcontainers')
55

6+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'
7+
8+
testImplementation 'org.junit.jupiter:junit-jupiter:5.13.4'
69
testImplementation 'com.bettercloud:vault-java-driver:5.1.0'
710
testImplementation 'io.rest-assured:rest-assured:5.5.6'
811
testImplementation 'org.assertj:assertj-core:3.27.4'
912

1013
}
14+
15+
test {
16+
useJUnitPlatform()
17+
}

modules/vault/src/test/java/org/testcontainers/vault/VaultClientTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44
import com.bettercloud.vault.VaultConfig;
55
import com.bettercloud.vault.VaultException;
66
import com.bettercloud.vault.response.LogicalResponse;
7-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
88

99
import java.util.HashMap;
1010
import java.util.Map;
1111

1212
import static org.assertj.core.api.Assertions.assertThat;
1313

14-
public class VaultClientTest {
14+
class VaultClientTest {
1515

1616
private static final String VAULT_TOKEN = "my-root-token";
1717

1818
@Test
19-
public void writeAndReadMultipleValues() throws VaultException {
19+
void writeAndReadMultipleValues() throws VaultException {
2020
try (VaultContainer<?> vaultContainer = new VaultContainer<>("vault:1.1.3").withVaultToken(VAULT_TOKEN)) {
2121
vaultContainer.start();
2222

modules/vault/src/test/java/org/testcontainers/vault/VaultContainerTest.java

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
import com.bettercloud.vault.VaultConfig;
55
import com.bettercloud.vault.response.LogicalResponse;
66
import io.restassured.response.Response;
7-
import org.junit.ClassRule;
8-
import org.junit.Test;
7+
import org.junit.jupiter.api.AfterAll;
8+
import org.junit.jupiter.api.BeforeAll;
9+
import org.junit.jupiter.api.Test;
910
import org.testcontainers.containers.GenericContainer;
1011

1112
import java.util.HashMap;
@@ -18,11 +19,10 @@
1819
* This test shows the pattern to use the VaultContainer @ClassRule for a junit test. It also has tests that ensure
1920
* the secrets were added correctly by reading from Vault with the CLI, over HTTP and over Client Library.
2021
*/
21-
public class VaultContainerTest {
22+
class VaultContainerTest {
2223

2324
private static final String VAULT_TOKEN = "my-root-token";
2425

25-
@ClassRule
2626
// vaultContainer {
2727
public static VaultContainer<?> vaultContainer = new VaultContainer<>("hashicorp/vault:1.13")
2828
.withVaultToken(VAULT_TOKEN)
@@ -35,8 +35,18 @@ public class VaultContainerTest {
3535

3636
// }
3737

38+
@BeforeAll
39+
static void setUp() {
40+
vaultContainer.start();
41+
}
42+
43+
@AfterAll
44+
static void tearDown() {
45+
vaultContainer.stop();
46+
}
47+
3848
@Test
39-
public void readFirstSecretPathWithCli() throws Exception {
49+
void readFirstSecretPathWithCli() throws Exception {
4050
GenericContainer.ExecResult result = vaultContainer.execInContainer(
4151
"vault",
4252
"kv",
@@ -48,7 +58,7 @@ public void readFirstSecretPathWithCli() throws Exception {
4858
}
4959

5060
@Test
51-
public void readSecondSecretPathWithCli() throws Exception {
61+
void readSecondSecretPathWithCli() throws Exception {
5262
GenericContainer.ExecResult result = vaultContainer.execInContainer(
5363
"vault",
5464
"kv",
@@ -66,7 +76,7 @@ public void readSecondSecretPathWithCli() throws Exception {
6676
}
6777

6878
@Test
69-
public void readFirstSecretPathOverHttpApi() {
79+
void readFirstSecretPathOverHttpApi() {
7080
Response response = given()
7181
.header("X-Vault-Token", VAULT_TOKEN)
7282
.when()
@@ -76,7 +86,7 @@ public void readFirstSecretPathOverHttpApi() {
7686
}
7787

7888
@Test
79-
public void readSecondSecretPathOverHttpApi() throws InterruptedException {
89+
void readSecondSecretPathOverHttpApi() throws InterruptedException {
8090
Response response = given()
8191
.header("X-Vault-Token", VAULT_TOKEN)
8292
.when()
@@ -90,7 +100,7 @@ public void readSecondSecretPathOverHttpApi() throws InterruptedException {
90100
}
91101

92102
@Test
93-
public void readTransitKeyOverHttpApi() throws InterruptedException {
103+
void readTransitKeyOverHttpApi() throws InterruptedException {
94104
Response response = given()
95105
.header("X-Vault-Token", VAULT_TOKEN)
96106
.when()
@@ -102,7 +112,7 @@ public void readTransitKeyOverHttpApi() throws InterruptedException {
102112

103113
@Test
104114
// readWithLibrary {
105-
public void readFirstSecretPathOverClientLibrary() throws Exception {
115+
void readFirstSecretPathOverClientLibrary() throws Exception {
106116
final VaultConfig config = new VaultConfig()
107117
.address(vaultContainer.getHttpHostAddress())
108118
.token(VAULT_TOKEN)
@@ -118,7 +128,7 @@ public void readFirstSecretPathOverClientLibrary() throws Exception {
118128
// }
119129

120130
@Test
121-
public void readSecondSecretPathOverClientLibrary() throws Exception {
131+
void readSecondSecretPathOverClientLibrary() throws Exception {
122132
final VaultConfig config = new VaultConfig()
123133
.address(vaultContainer.getHttpHostAddress())
124134
.token(VAULT_TOKEN)
@@ -135,7 +145,7 @@ public void readSecondSecretPathOverClientLibrary() throws Exception {
135145
}
136146

137147
@Test
138-
public void writeSecretOverClientLibrary() throws Exception {
148+
void writeSecretOverClientLibrary() throws Exception {
139149
final VaultConfig config = new VaultConfig()
140150
.address(vaultContainer.getHttpHostAddress())
141151
.token(VAULT_TOKEN)

0 commit comments

Comments
 (0)