-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java API for constraint error check (#13)
- Loading branch information
Showing
4 changed files
with
64 additions
and
21 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
43 changes: 43 additions & 0 deletions
43
src/main/java/ch/geowerkstatt/interlis/testbed/runner/validation/IliValidatorLogParser.java
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package ch.geowerkstatt.interlis.testbed.runner.validation; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Provides static methods that can be used to get information from ilivalidator log files. | ||
*/ | ||
public final class IliValidatorLogParser { | ||
private static final Logger LOGGER = LogManager.getLogger(); | ||
|
||
private IliValidatorLogParser() { | ||
} | ||
|
||
/** | ||
* Checks if the log file contains at least one error for the provided constraint. | ||
* | ||
* @param logFile the path to the log file. | ||
* @param constraintName the fully qualified name of the constraint to check. | ||
* @return {@code true} if the log file contains an error for the constraint, {@code false} otherwise. | ||
* @throws ValidatorException if an unexpected error such as an {@link IOException} occurred. | ||
*/ | ||
public static boolean containsConstraintError(Path logFile, String constraintName) throws ValidatorException { | ||
var constraintPattern = Pattern.compile("^Error: .*\\b" + Pattern.quote(constraintName) + "\\b"); | ||
|
||
try (var lines = Files.lines(logFile)) { | ||
return lines.anyMatch(line -> { | ||
if (constraintPattern.matcher(line).find()) { | ||
LOGGER.info("Found expected error for constraint {} in log file: {}", constraintName, line); | ||
return true; | ||
} | ||
return false; | ||
}); | ||
} catch (IOException e) { | ||
throw new ValidatorException(e); | ||
} | ||
} | ||
} |
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