|
6 | 6 | import static org.testng.AssertJUnit.assertEquals; |
7 | 7 |
|
8 | 8 | import java.io.ByteArrayInputStream; |
| 9 | +import java.io.File; |
9 | 10 | import java.io.IOException; |
10 | 11 | import java.net.URI; |
11 | 12 | import java.net.URISyntaxException; |
|
16 | 17 | import java.time.format.DateTimeFormatter; |
17 | 18 | import java.util.concurrent.ExecutionException; |
18 | 19 | import java.util.concurrent.TimeoutException; |
| 20 | +import java.util.Optional; |
19 | 21 |
|
20 | 22 | import org.jetbrains.annotations.NotNull; |
21 | 23 | import org.junit.jupiter.api.AfterAll; |
|
41 | 43 | import io.github.cdimascio.dotenv.Dotenv; |
42 | 44 |
|
43 | 45 | public class RealApiIntegrationTests { |
44 | | - private static final Dotenv dotenv = Dotenv.configure() |
45 | | - .ignoreIfMissing() |
46 | | - .load(); |
| 46 | + private static final Dotenv dotenv = getDotenv(); |
47 | 47 | private static Vaas vaas; |
48 | 48 |
|
| 49 | + private static Dotenv getDotenv() { |
| 50 | + var dotenv = Dotenv.configure() |
| 51 | + .ignoreIfMissing(); |
| 52 | + |
| 53 | + Optional<File> envFile = findFile(".env"); |
| 54 | + |
| 55 | + if (envFile.isPresent()) { |
| 56 | + var directory = envFile.get().getParent(); |
| 57 | + dotenv.directory(directory); |
| 58 | + } |
| 59 | + |
| 60 | + return dotenv.load(); |
| 61 | + } |
| 62 | + |
| 63 | + private static Optional<File> findFile(String name) { |
| 64 | + File currentDirectory = new File(System.getProperty("user.dir")); |
| 65 | + File file = new File(currentDirectory, name); |
| 66 | + |
| 67 | + while (!file.exists() && currentDirectory.getParentFile() != null) { |
| 68 | + currentDirectory = currentDirectory.getParentFile(); |
| 69 | + file = new File(currentDirectory, name); |
| 70 | + } |
| 71 | + |
| 72 | + return file.exists() ? Optional.of(file) : Optional.empty(); |
| 73 | + } |
| 74 | + |
49 | 75 | @BeforeAll |
50 | 76 | public static void setUpAll() throws URISyntaxException, InterruptedException, IOException, ExecutionException, |
51 | 77 | TimeoutException, VaasAuthenticationException { |
|
0 commit comments