mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
(fix) return code 0 on assertion check
This commit is contained in:
parent
4a4ebcadc0
commit
911a4f2ceb
4 changed files with 32 additions and 8 deletions
|
|
@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- read saxon XdmNode with InputFactory
|
- read saxon XdmNode with InputFactory
|
||||||
- [CLI] custom output without the various log messages
|
- [CLI] custom output without the various log messages
|
||||||
- [CLI] options to set the log level (`-X` = full debug output, `-l <level>` set a specific level)
|
- [CLI] options to set the log level (`-X` = full debug output, `-l <level>` set a specific level)
|
||||||
|
- [CLI] return code ist <> 0 on rejected results
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- InputFactory has methods to read any java.xml.transform.Source as Input not only StreamSources
|
- InputFactory has methods to read any java.xml.transform.Source as Input not only StreamSources
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,7 @@ package de.kosit.validationtool.cmd;
|
||||||
|
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.text.MessageFormat;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
@ -40,7 +41,6 @@ import de.kosit.validationtool.cmd.report.Line;
|
||||||
import de.kosit.validationtool.impl.DefaultCheck;
|
import de.kosit.validationtool.impl.DefaultCheck;
|
||||||
import de.kosit.validationtool.impl.tasks.CheckAction;
|
import de.kosit.validationtool.impl.tasks.CheckAction;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Simple Erweiterung der Klasse {@link DefaultCheck} um das Ergebnis der Assertion-Prüfung auszwerten und auszugeben.
|
* Simple Erweiterung der Klasse {@link DefaultCheck} um das Ergebnis der Assertion-Prüfung auszwerten und auszugeben.
|
||||||
* Diese Klasse stellt keine fachlicher Erweiterung des eigentlichen Prüfvorganges dar!
|
* Diese Klasse stellt keine fachlicher Erweiterung des eigentlichen Prüfvorganges dar!
|
||||||
|
|
@ -80,19 +80,36 @@ class InternalCheck extends DefaultCheck {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean printAndEvaluate(final Map<Path, Result> results) {
|
void printResults(final Map<Path, Result> results) {
|
||||||
final PrintWriter writer = new PrintWriter(System.out);// NOSONAR
|
final PrintWriter writer = new PrintWriter(System.out);// NOSONAR
|
||||||
|
writer.write("Results:\n");
|
||||||
writer.write(createResultGrid(results).render());
|
writer.write(createResultGrid(results).render());
|
||||||
writer.write(createStatusLine(results));
|
writer.write(createStatusLine(results));
|
||||||
|
writer.write(createAssertionStatus());
|
||||||
writer.flush();
|
writer.flush();
|
||||||
|
}
|
||||||
|
|
||||||
|
private String createAssertionStatus() {
|
||||||
|
final Line line = new Line();
|
||||||
if (this.failedAssertions > 0) {
|
if (this.failedAssertions > 0) {
|
||||||
log.error("Assertion check failed.\n\nAssertions run: {}, Assertions failed: {}\n", this.checkAssertions,
|
log.error("Assertion check failed.\n\nAssertions run: {}, Assertions failed: {}\n", this.checkAssertions,
|
||||||
this.failedAssertions);
|
this.failedAssertions);
|
||||||
|
line.add(MessageFormat.format("Assertions run: {0}, Assertions failed: ", this.checkAssertions));
|
||||||
|
line.add(this.failedAssertions, Code.RED);
|
||||||
} else if (this.checkAssertions > 0) {
|
} else if (this.checkAssertions > 0) {
|
||||||
log.info("Assertion check successful.\n\nAssertions run: {}, Assertions failed: {}\n", this.checkAssertions,
|
log.info("Assertion check successful.\n\nAssertions run: {}, Assertions failed: {}\n", this.checkAssertions,
|
||||||
this.failedAssertions);
|
this.failedAssertions);
|
||||||
|
line.add(MessageFormat.format("Assertions run: {0}, Assertions failed: {1}", this.checkAssertions, this.failedAssertions));
|
||||||
}
|
}
|
||||||
return this.failedAssertions == 0 && results.entrySet().stream().allMatch(e -> e.getValue().isAcceptable());
|
return line.render(true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isSuccessful(final Map<Path, Result> results) {
|
||||||
|
if (this.checkAssertions > 0) {
|
||||||
|
return this.failedAssertions == 0;
|
||||||
|
}
|
||||||
|
return super.isSuccessful(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String createStatusLine(final Map<Path, Result> results) {
|
private static String createStatusLine(final Map<Path, Result> results) {
|
||||||
|
|
@ -105,7 +122,7 @@ class InternalCheck extends DefaultCheck {
|
||||||
if (errors > 0) {
|
if (errors > 0) {
|
||||||
line.add(" Processing errors: ").add(errors, Code.RED);
|
line.add(" Processing errors: ").add(errors, Code.RED);
|
||||||
}
|
}
|
||||||
return line.render();
|
return line.render(true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Grid createResultGrid(final Map<Path, Result> results) {
|
private static Grid createResultGrid(final Map<Path, Result> results) {
|
||||||
|
|
|
||||||
|
|
@ -190,10 +190,10 @@ public class Validator {
|
||||||
}
|
}
|
||||||
final long processingTime = System.currentTimeMillis() - start;
|
final long processingTime = System.currentTimeMillis() - start;
|
||||||
Printer.writeOut("Processing of {0} objects completed in {1}ms", targets.size(), processingTime);
|
Printer.writeOut("Processing of {0} objects completed in {1}ms", targets.size(), processingTime);
|
||||||
Printer.writeOut("Results:");
|
|
||||||
final boolean result = check.printAndEvaluate(results);
|
check.printResults(results);
|
||||||
log.info("Processing {} object(s) completed in {}ms", targets.size(), processingTime);
|
log.info("Processing {} object(s) completed in {}ms", targets.size(), processingTime);
|
||||||
return result ? 0 : 1;
|
return check.isSuccessful(results) ? 0 : 1;
|
||||||
|
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
e.printStackTrace();// NOSONAR
|
e.printStackTrace();// NOSONAR
|
||||||
|
|
@ -219,7 +219,7 @@ public class Validator {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void printScenarios(final Configuration configuration) {
|
private static void printScenarios(final Configuration configuration) {
|
||||||
Printer.writeOut("Loaded \"{0} {1}\" by {2} from {3} ", configuration.getName(), "1", configuration.getAuthor(),
|
Printer.writeOut("Loaded \"{0}\" by {1} from {2} ", configuration.getName(), configuration.getAuthor(),
|
||||||
configuration.getDate());
|
configuration.getDate());
|
||||||
Printer.writeOut("\nThe following scenarios are available:");
|
Printer.writeOut("\nThe following scenarios are available:");
|
||||||
configuration.getScenarios().forEach(e -> {
|
configuration.getScenarios().forEach(e -> {
|
||||||
|
|
|
||||||
|
|
@ -21,9 +21,11 @@ package de.kosit.validationtool.impl;
|
||||||
|
|
||||||
import static de.kosit.validationtool.impl.DateFactory.createTimestamp;
|
import static de.kosit.validationtool.impl.DateFactory.createTimestamp;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
@ -101,6 +103,10 @@ public class DefaultCheck implements Check {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected boolean isSuccessful(final Map<Path, Result> results) {
|
||||||
|
return results.entrySet().stream().allMatch(e -> e.getValue().isAcceptable());
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Result checkInput(final Input input) {
|
public Result checkInput(final Input input) {
|
||||||
final CheckAction.Bag t = new CheckAction.Bag(input, createReport());
|
final CheckAction.Bag t = new CheckAction.Bag(input, createReport());
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue