diff --git a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java index a4426d449..c874b3e33 100644 --- a/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java +++ b/src/test/java/net/snowflake/client/jdbc/FileUploaderExpandFileNamesTest.java @@ -40,6 +40,8 @@ public void testProcessFileNames() throws Exception { folder.newFile("TestFileB"); String folderName = folder.getRoot().getCanonicalPath(); + String originalUserDir = System.getProperty("user.dir"); + String originalUserHome = System.getProperty("user.home"); System.setProperty("user.dir", folderName); System.setProperty("user.home", folderName); @@ -58,6 +60,17 @@ public void testProcessFileNames() throws Exception { assertTrue(files.contains(folderName + File.separator + "TestFileC")); assertTrue(files.contains(folderName + File.separator + "TestFileD")); assertTrue(files.contains(folderName + File.separator + "TestFileE~")); + + if (originalUserHome != null) { + System.setProperty("user.home", originalUserHome); + } else { + System.clearProperty("user.home"); + } + if (originalUserDir != null) { + System.setProperty("user.dir", originalUserDir); + } else { + System.clearProperty("user.dir"); + } } @Test diff --git a/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java b/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java index 0ff8ba6c7..79791dac3 100644 --- a/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java +++ b/src/test/java/net/snowflake/client/log/JDK14LoggerWithClientLatestIT.java @@ -27,6 +27,7 @@ import org.junit.Test; import org.junit.experimental.categories.Category; import org.junit.rules.TemporaryFolder; +import sun.nio.ch.FileKey; @Category(TestCategoryOthers.class) public class JDK14LoggerWithClientLatestIT extends AbstractDriverIT { @@ -36,9 +37,13 @@ public class JDK14LoggerWithClientLatestIT extends AbstractDriverIT { String homePath = systemGetProperty("user.home"); @Test - public void testJDK14LoggingWithClientConfig() { - Path configFilePath = Paths.get("config.json"); - String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"logs\"}}"; + public void testJDK14LoggingWithClientConfig() throws IOException { + File configFile = tmpFolder.newFile("config.json"); + Path configFilePath = configFile.toPath(); + File logFolder = tmpFolder.newFolder("logs"); + Path logFolderPath = logFolder.toPath(); + String configJson = + "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"" + logFolderPath + "\"}}"; try { Files.write(configFilePath, configJson.getBytes()); Properties properties = new Properties(); @@ -47,11 +52,8 @@ public void testJDK14LoggingWithClientConfig() { Statement statement = connection.createStatement()) { statement.executeQuery("select 1"); - File file = new File("logs/jdbc/"); + File file = new File(Paths.get(logFolderPath.toString(), "jdbc").toString()); assertTrue(file.exists()); - - Files.deleteIfExists(configFilePath); - FileUtils.deleteDirectory(new File("logs")); } } catch (IOException e) { fail("testJDK14LoggingWithClientConfig failed"); @@ -74,9 +76,9 @@ public void testJDK14LoggingWithClientConfigInvalidConfigFilePath() throws SQLEx @ConditionalIgnoreRule.ConditionalIgnore(condition = RunningOnWin.class) public void testJDK14LoggingWithClientConfigPermissionError() throws IOException { File configFile = tmpFolder.newFile("config.json"); - Path configFilePath = Paths.get(configFile.getAbsolutePath()); + Path configFilePath = configFile.toPath(); File directory = tmpFolder.newFolder("logs"); - Path directoryPath = Paths.get(directory.getAbsolutePath()); + Path directoryPath = directory.toPath(); String configJson = "{\"common\":{\"log_level\":\"debug\",\"log_path\":\"" + directoryPath + "\"}}"; HashSet perms = new HashSet<>(); @@ -109,7 +111,8 @@ public void testJDK14LoggerWithQuotesInMessage() { @Test public void testJDK14LoggingWithMissingLogPathClientConfig() throws Exception { - Path configFilePath = Paths.get("config.json"); + File configFile = tmpFolder.newFile("config.json"); + Path configFilePath = configFile.toPath(); String configJson = "{\"common\":{\"log_level\":\"debug\"}}"; Path homeLogPath = Paths.get(homePath, "jdbc"); @@ -135,7 +138,8 @@ public void testJDK14LoggingWithMissingLogPathClientConfig() throws Exception { public void testJDK14LoggingWithMissingLogPathNoHomeDirClientConfig() throws Exception { System.clearProperty("user.home"); - Path configFilePath = Paths.get("config.json"); + File configFile = tmpFolder.newFile("config.json"); + Path configFilePath = configFile.toPath(); String configJson = "{\"common\":{\"log_level\":\"debug\"}}"; Files.write(configFilePath, configJson.getBytes()); Properties properties = new Properties();