-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate tests to keep the log files that were created. Put the log fi…
…les into a directory with the test name and method name. Signed-off-by: James R. Perkins <[email protected]>
- Loading branch information
Showing
7 changed files
with
216 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,6 @@ | |
package org.jboss.logmanager.handlers; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URI; | ||
|
@@ -32,74 +31,79 @@ | |
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
import java.util.zip.GZIPInputStream; | ||
|
||
import org.jboss.logmanager.ExtHandler; | ||
import org.jboss.logmanager.ExtLogRecord; | ||
import org.jboss.logmanager.formatters.PatternFormatter; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInfo; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">James R. Perkins</a> | ||
*/ | ||
public class AbstractHandlerTest { | ||
static final File BASE_LOG_DIR; | ||
|
||
private static final Path BASE_LOG_DIR; | ||
|
||
static { | ||
BASE_LOG_DIR = new File(System.getProperty("log.dir")); | ||
BASE_LOG_DIR = Path.of(System.getProperty("log.dir")); | ||
} | ||
|
||
final static PatternFormatter FORMATTER = new PatternFormatter("%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"); | ||
|
||
private TestInfo testInfo; | ||
|
||
@BeforeEach | ||
public void setup() throws Exception { | ||
BASE_LOG_DIR.mkdir(); | ||
} | ||
|
||
@AfterEach | ||
public void cleanUp() throws Exception { | ||
deleteChildrenRecursively(BASE_LOG_DIR); | ||
} | ||
|
||
static boolean deleteRecursively(final File dir) { | ||
if (dir.isDirectory()) { | ||
final File[] files = dir.listFiles(); | ||
if (files != null) { | ||
for (final File f : files) { | ||
if (f.isDirectory()) { | ||
if (!deleteRecursively(f)) { | ||
return false; | ||
} | ||
} | ||
if (!f.delete()) { | ||
return false; | ||
} | ||
} | ||
} | ||
public void setup(final TestInfo testInfo) throws Exception { | ||
this.testInfo = testInfo; | ||
deleteDirectory(logDirectory(testInfo)); | ||
} | ||
|
||
@Test | ||
public void simple() { | ||
Assertions.assertTrue(testInfo.getTestMethod().isPresent()); | ||
} | ||
|
||
protected Path resolvePath(final String filename) throws IOException { | ||
return logDirectory().resolve(filename); | ||
} | ||
|
||
protected Path logDirectory() throws IOException { | ||
return logDirectory(testInfo); | ||
} | ||
|
||
protected Path logDirectory(final TestInfo testInfo) throws IOException { | ||
Assertions.assertTrue(testInfo.getTestClass().isPresent()); | ||
Assertions.assertTrue(testInfo.getTestMethod().isPresent()); | ||
final Path dir = BASE_LOG_DIR | ||
.resolve(testInfo.getTestClass().get().getSimpleName() + "-" + testInfo.getTestMethod().get().getName()); | ||
if (Files.notExists(dir)) { | ||
Files.createDirectories(dir); | ||
} | ||
return dir.delete(); | ||
} | ||
|
||
static boolean deleteChildrenRecursively(final File dir) { | ||
if (dir.isDirectory()) { | ||
final File[] files = dir.listFiles(); | ||
if (files != null) { | ||
for (final File f : files) { | ||
if (f.isDirectory()) { | ||
if (!deleteRecursively(f)) { | ||
return false; | ||
} | ||
} | ||
if (!f.delete()) { | ||
return false; | ||
} | ||
} | ||
return dir; | ||
} | ||
|
||
private static void deleteDirectory(final Path dir) throws IOException { | ||
if (Files.isDirectory(dir)) { | ||
try (Stream<Path> paths = Files.walk(dir)) { | ||
paths.sorted(Comparator.reverseOrder()) | ||
.forEach(p -> { | ||
try { | ||
Files.delete(p); | ||
} catch (IOException e) { | ||
// TODO (jrp) report maybe, but don't fail | ||
} | ||
}); | ||
} | ||
} else { | ||
Files.delete(dir); | ||
} | ||
return true; | ||
} | ||
|
||
protected static void configureHandlerDefaults(final ExtHandler handler) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.