diff --git a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java index 27e2427..d8c719b 100644 --- a/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java +++ b/src/test/java/de/stklcode/jvault/connector/HTTPVaultConnectorTest.java @@ -23,10 +23,8 @@ import de.stklcode.jvault.connector.model.*; import de.stklcode.jvault.connector.model.response.*; import de.stklcode.jvault.connector.test.Credentials; import de.stklcode.jvault.connector.test.VaultConfiguration; -import org.junit.Rule; import org.junit.jupiter.api.*; -import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -import org.junit.rules.TemporaryFolder; +import org.junit.jupiter.api.io.TempDir; import java.io.*; import java.lang.reflect.Field; @@ -52,7 +50,6 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue; * @author Stefan Kalscheuer * @since 0.1 */ -@EnableRuleMigrationSupport public class HTTPVaultConnectorTest { private static String VAULT_VERSION = "1.1.0"; // the vault version this test is supposed to run against private static final String KEY1 = "E38bkCm0VhUvpdCKGQpcohhD9XmcHJ/2hreOSY019Lho"; @@ -86,8 +83,8 @@ public class HTTPVaultConnectorTest { private Process vaultProcess; private VaultConnector connector; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); + @TempDir + File tempDir; @BeforeAll public static void init() { @@ -1202,7 +1199,7 @@ public class HTTPVaultConnectorTest { * @throws IllegalStateException on error */ private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException, IOException { - File dataDir = tmpDir.newFolder(); + File dataDir = new File(tempDir, "data"); copyDirectory(new File(getClass().getResource("/data_dir").getPath()), dataDir); /* Generate vault local unencrypted configuration */ @@ -1223,7 +1220,7 @@ public class HTTPVaultConnectorTest { BufferedWriter bw = null; File configFile; try { - configFile = tmpDir.newFile("vault.conf"); + configFile = new File(tempDir, "vault.conf"); bw = new BufferedWriter(new FileWriter(configFile)); bw.write(config.toString()); } catch (IOException e) { diff --git a/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java b/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java index 4d8a501..34b30b7 100644 --- a/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java +++ b/src/test/java/de/stklcode/jvault/connector/builder/HTTPVaultConnectorBuilderTest.java @@ -22,9 +22,10 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException; import org.junit.Rule; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -import org.junit.rules.TemporaryFolder; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.NoSuchFileException; @@ -45,8 +46,8 @@ public class HTTPVaultConnectorBuilderTest { private static Integer VAULT_MAX_RETRIES = 13; private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777"; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); + @TempDir + File tempDir; @Rule public final EnvironmentVariables environment = new EnvironmentVariables(); @@ -68,7 +69,7 @@ public class HTTPVaultConnectorBuilderTest { } connector = factory.build(); - assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/"))); + assertThat("URL nor set correctly", getRequestHelperPrivate(connector, "baseURL"), is(equalTo(VAULT_ADDR + "/v1/"))); assertThat("Trusted CA cert set when no cert provided", getRequestHelperPrivate(connector, "trustedCaCert"), is(nullValue())); assertThat("Non-default number of retries, when none set", getRequestHelperPrivate(connector, "retries"), is(0)); @@ -87,7 +88,7 @@ public class HTTPVaultConnectorBuilderTest { assertThat("Number of retries not set correctly", getRequestHelperPrivate(connector, "retries"), is(VAULT_MAX_RETRIES)); /* Provide CA certificate */ - String VAULT_CACERT = tmpDir.newFolder().toString() + "/doesnotexist"; + String VAULT_CACERT = tempDir.toString() + "/doesnotexist"; setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null); try { diff --git a/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java b/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java index ac9118c..8c9b7ca 100644 --- a/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java +++ b/src/test/java/de/stklcode/jvault/connector/factory/HTTPVaultConnectorFactoryTest.java @@ -22,9 +22,10 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException; import org.junit.Rule; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport; -import org.junit.rules.TemporaryFolder; +import java.io.File; import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.NoSuchFileException; @@ -45,8 +46,8 @@ public class HTTPVaultConnectorFactoryTest { private static Integer VAULT_MAX_RETRIES = 13; private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777"; - @Rule - public TemporaryFolder tmpDir = new TemporaryFolder(); + @TempDir + File tempDir; @Rule public final EnvironmentVariables environment = new EnvironmentVariables(); @@ -87,7 +88,7 @@ public class HTTPVaultConnectorFactoryTest { assertThat("Number of retries not set correctly", getRequestHelperPrivate(connector, "retries"), is(VAULT_MAX_RETRIES)); /* Provide CA certificate */ - String VAULT_CACERT = tmpDir.newFolder().toString() + "/doesnotexist"; + String VAULT_CACERT = tempDir.toString() + "/doesnotexist"; setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null); try { @@ -96,7 +97,7 @@ public class HTTPVaultConnectorFactoryTest { } catch (VaultConnectorException e) { assertThat(e, is(instanceOf(TlsException.class))); assertThat(e.getCause(), is(instanceOf(NoSuchFileException.class))); - assertThat(((NoSuchFileException)e.getCause()).getFile(), is(VAULT_CACERT)); + assertThat(((NoSuchFileException) e.getCause()).getFile(), is(VAULT_CACERT)); } /* Automatic authentication */ @@ -116,7 +117,7 @@ public class HTTPVaultConnectorFactoryTest { environment.set("VAULT_MAX_RETRIES", vault_max_retries); environment.set("VAULT_TOKEN", vault_token); } - + private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) throws NoSuchFieldException, IllegalAccessException { return getPrivate(getPrivate(connector, "request"), fieldName); }