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 )
@@ -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