Skip to content

Commit

Permalink
Improved cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astachowski committed Oct 25, 2024
1 parent e4743d8 commit ca0f810
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand All @@ -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");
Expand All @@ -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<PosixFilePermission> perms = new HashSet<>();
Expand Down Expand Up @@ -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");
Expand All @@ -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();
Expand Down

0 comments on commit ca0f810

Please sign in to comment.