Skip to content

Commit 41c3a80

Browse files
committed
Move Vault assertions to assertj
1 parent 576aa2b commit 41c3a80

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
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 & 13 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)
@@ -32,11 +32,20 @@ public class VaultContainerTest {
3232
"kv put secret/testing1 top_secret=password123",
3333
"kv put secret/testing2 secret_one=password1 secret_two=password2 secret_three=password3 secret_three=password3 secret_four=password4"
3434
);
35-
3635
// }
3736

37+
@BeforeAll
38+
static void setUp() {
39+
vaultContainer.start();
40+
}
41+
42+
@AfterAll
43+
static void tearDown() {
44+
vaultContainer.stop();
45+
}
46+
3847
@Test
39-
public void readFirstSecretPathWithCli() throws Exception {
48+
void readFirstSecretPathWithCli() throws Exception {
4049
GenericContainer.ExecResult result = vaultContainer.execInContainer(
4150
"vault",
4251
"kv",
@@ -48,7 +57,7 @@ public void readFirstSecretPathWithCli() throws Exception {
4857
}
4958

5059
@Test
51-
public void readSecondSecretPathWithCli() throws Exception {
60+
void readSecondSecretPathWithCli() throws Exception {
5261
GenericContainer.ExecResult result = vaultContainer.execInContainer(
5362
"vault",
5463
"kv",
@@ -66,7 +75,7 @@ public void readSecondSecretPathWithCli() throws Exception {
6675
}
6776

6877
@Test
69-
public void readFirstSecretPathOverHttpApi() {
78+
void readFirstSecretPathOverHttpApi() {
7079
Response response = given()
7180
.header("X-Vault-Token", VAULT_TOKEN)
7281
.when()
@@ -76,7 +85,7 @@ public void readFirstSecretPathOverHttpApi() {
7685
}
7786

7887
@Test
79-
public void readSecondSecretPathOverHttpApi() throws InterruptedException {
88+
void readSecondSecretPathOverHttpApi() throws InterruptedException {
8089
Response response = given()
8190
.header("X-Vault-Token", VAULT_TOKEN)
8291
.when()
@@ -90,7 +99,7 @@ public void readSecondSecretPathOverHttpApi() throws InterruptedException {
9099
}
91100

92101
@Test
93-
public void readTransitKeyOverHttpApi() throws InterruptedException {
102+
void readTransitKeyOverHttpApi() throws InterruptedException {
94103
Response response = given()
95104
.header("X-Vault-Token", VAULT_TOKEN)
96105
.when()
@@ -102,7 +111,7 @@ public void readTransitKeyOverHttpApi() throws InterruptedException {
102111

103112
@Test
104113
// readWithLibrary {
105-
public void readFirstSecretPathOverClientLibrary() throws Exception {
114+
void readFirstSecretPathOverClientLibrary() throws Exception {
106115
final VaultConfig config = new VaultConfig()
107116
.address(vaultContainer.getHttpHostAddress())
108117
.token(VAULT_TOKEN)
@@ -118,7 +127,7 @@ public void readFirstSecretPathOverClientLibrary() throws Exception {
118127
// }
119128

120129
@Test
121-
public void readSecondSecretPathOverClientLibrary() throws Exception {
130+
void readSecondSecretPathOverClientLibrary() throws Exception {
122131
final VaultConfig config = new VaultConfig()
123132
.address(vaultContainer.getHttpHostAddress())
124133
.token(VAULT_TOKEN)
@@ -135,7 +144,7 @@ public void readSecondSecretPathOverClientLibrary() throws Exception {
135144
}
136145

137146
@Test
138-
public void writeSecretOverClientLibrary() throws Exception {
147+
void writeSecretOverClientLibrary() throws Exception {
139148
final VaultConfig config = new VaultConfig()
140149
.address(vaultContainer.getHttpHostAddress())
141150
.token(VAULT_TOKEN)

0 commit comments

Comments
 (0)