44import com .bettercloud .vault .VaultConfig ;
55import com .bettercloud .vault .response .LogicalResponse ;
66import 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 ;
910import org .testcontainers .containers .GenericContainer ;
1011
1112import java .util .HashMap ;
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