Migrate TemporaryFolder rule to JUnit 5.4 TempDir annotation
This commit is contained in:
parent
d6f422e0ec
commit
a24ddf65a5
@ -23,10 +23,8 @@ import de.stklcode.jvault.connector.model.*;
|
|||||||
import de.stklcode.jvault.connector.model.response.*;
|
import de.stklcode.jvault.connector.model.response.*;
|
||||||
import de.stklcode.jvault.connector.test.Credentials;
|
import de.stklcode.jvault.connector.test.Credentials;
|
||||||
import de.stklcode.jvault.connector.test.VaultConfiguration;
|
import de.stklcode.jvault.connector.test.VaultConfiguration;
|
||||||
import org.junit.Rule;
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
@ -52,7 +50,6 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
|||||||
* @author Stefan Kalscheuer
|
* @author Stefan Kalscheuer
|
||||||
* @since 0.1
|
* @since 0.1
|
||||||
*/
|
*/
|
||||||
@EnableRuleMigrationSupport
|
|
||||||
public class HTTPVaultConnectorTest {
|
public class HTTPVaultConnectorTest {
|
||||||
private static String VAULT_VERSION = "1.1.0"; // the vault version this test is supposed to run against
|
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";
|
private static final String KEY1 = "E38bkCm0VhUvpdCKGQpcohhD9XmcHJ/2hreOSY019Lho";
|
||||||
@ -86,8 +83,8 @@ public class HTTPVaultConnectorTest {
|
|||||||
private Process vaultProcess;
|
private Process vaultProcess;
|
||||||
private VaultConnector connector;
|
private VaultConnector connector;
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public TemporaryFolder tmpDir = new TemporaryFolder();
|
File tempDir;
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
public static void init() {
|
public static void init() {
|
||||||
@ -1202,7 +1199,7 @@ public class HTTPVaultConnectorTest {
|
|||||||
* @throws IllegalStateException on error
|
* @throws IllegalStateException on error
|
||||||
*/
|
*/
|
||||||
private VaultConfiguration initializeVault(boolean tls) throws IllegalStateException, IOException {
|
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);
|
copyDirectory(new File(getClass().getResource("/data_dir").getPath()), dataDir);
|
||||||
|
|
||||||
/* Generate vault local unencrypted configuration */
|
/* Generate vault local unencrypted configuration */
|
||||||
@ -1223,7 +1220,7 @@ public class HTTPVaultConnectorTest {
|
|||||||
BufferedWriter bw = null;
|
BufferedWriter bw = null;
|
||||||
File configFile;
|
File configFile;
|
||||||
try {
|
try {
|
||||||
configFile = tmpDir.newFile("vault.conf");
|
configFile = new File(tempDir, "vault.conf");
|
||||||
bw = new BufferedWriter(new FileWriter(configFile));
|
bw = new BufferedWriter(new FileWriter(configFile));
|
||||||
bw.write(config.toString());
|
bw.write(config.toString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -22,9 +22,10 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
@ -45,8 +46,8 @@ public class HTTPVaultConnectorBuilderTest {
|
|||||||
private static Integer VAULT_MAX_RETRIES = 13;
|
private static Integer VAULT_MAX_RETRIES = 13;
|
||||||
private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public TemporaryFolder tmpDir = new TemporaryFolder();
|
File tempDir;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final EnvironmentVariables environment = new EnvironmentVariables();
|
public final EnvironmentVariables environment = new EnvironmentVariables();
|
||||||
@ -68,7 +69,7 @@ public class HTTPVaultConnectorBuilderTest {
|
|||||||
}
|
}
|
||||||
connector = factory.build();
|
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("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));
|
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));
|
assertThat("Number of retries not set correctly", getRequestHelperPrivate(connector, "retries"), is(VAULT_MAX_RETRIES));
|
||||||
|
|
||||||
/* Provide CA certificate */
|
/* 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);
|
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -22,9 +22,10 @@ import de.stklcode.jvault.connector.exception.VaultConnectorException;
|
|||||||
import org.junit.Rule;
|
import org.junit.Rule;
|
||||||
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
import org.junit.contrib.java.lang.system.EnvironmentVariables;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.io.TempDir;
|
||||||
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
import org.junit.jupiter.migrationsupport.rules.EnableRuleMigrationSupport;
|
||||||
import org.junit.rules.TemporaryFolder;
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.nio.file.NoSuchFileException;
|
import java.nio.file.NoSuchFileException;
|
||||||
@ -45,8 +46,8 @@ public class HTTPVaultConnectorFactoryTest {
|
|||||||
private static Integer VAULT_MAX_RETRIES = 13;
|
private static Integer VAULT_MAX_RETRIES = 13;
|
||||||
private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
private static String VAULT_TOKEN = "00001111-2222-3333-4444-555566667777";
|
||||||
|
|
||||||
@Rule
|
@TempDir
|
||||||
public TemporaryFolder tmpDir = new TemporaryFolder();
|
File tempDir;
|
||||||
|
|
||||||
@Rule
|
@Rule
|
||||||
public final EnvironmentVariables environment = new EnvironmentVariables();
|
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));
|
assertThat("Number of retries not set correctly", getRequestHelperPrivate(connector, "retries"), is(VAULT_MAX_RETRIES));
|
||||||
|
|
||||||
/* Provide CA certificate */
|
/* 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);
|
setenv(VAULT_ADDR, VAULT_CACERT, VAULT_MAX_RETRIES.toString(), null);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -96,7 +97,7 @@ public class HTTPVaultConnectorFactoryTest {
|
|||||||
} catch (VaultConnectorException e) {
|
} catch (VaultConnectorException e) {
|
||||||
assertThat(e, is(instanceOf(TlsException.class)));
|
assertThat(e, is(instanceOf(TlsException.class)));
|
||||||
assertThat(e.getCause(), is(instanceOf(NoSuchFileException.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 */
|
/* Automatic authentication */
|
||||||
@ -116,7 +117,7 @@ public class HTTPVaultConnectorFactoryTest {
|
|||||||
environment.set("VAULT_MAX_RETRIES", vault_max_retries);
|
environment.set("VAULT_MAX_RETRIES", vault_max_retries);
|
||||||
environment.set("VAULT_TOKEN", vault_token);
|
environment.set("VAULT_TOKEN", vault_token);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
private Object getRequestHelperPrivate(HTTPVaultConnector connector, String fieldName) throws NoSuchFieldException, IllegalAccessException {
|
||||||
return getPrivate(getPrivate(connector, "request"), fieldName);
|
return getPrivate(getPrivate(connector, "request"), fieldName);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user