Skip to content

Commit e5b32d9

Browse files
author
Mohamed Maza
committed
#79 Make Tests green again!
1 parent f45112f commit e5b32d9

20 files changed

+150
-506
lines changed

Diff for: src/main/java/de/kosit/validationtool/cmd/InternalCheck.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,13 @@ class InternalCheck extends DefaultCheck {
6666
*/
6767
@Override
6868
public Result checkInput(final Input input) {
69-
final CheckAction.Process process = new CheckAction.Process(input, createReport(), createXVRLMetadata());
69+
final CheckAction.Process process = new CheckAction.Process(input, createXVRLMetadata());
7070
final Result result = runCheckInternal(process);
71-
if (process.getAssertionResult() != null) {
72-
this.checkAssertions += process.getAssertionResult().getObject();
73-
this.failedAssertions += process.getAssertionResult().getErrors().size();
74-
}
71+
// TODO where are AssertionResults set?
72+
//if (process.getAssertionResult() != null) {
73+
// this.checkAssertions += process.getAssertionResult().getObject();
74+
// this.failedAssertions += process.getAssertionResult().getErrors().size();
75+
//}
7576
return result;
7677
}
7778

Diff for: src/main/java/de/kosit/validationtool/cmd/SerializeReportInputAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public ProcessStepResult check(final Process results) {
4949
final Path file = this.outputDirectory.resolve(results.getName() + "-reportInput.xml");
5050
try {
5151
log.info("Serializing result to {}", file.toAbsolutePath());
52-
final String xml = this.conversionService.writeXml(results.getReportInput());
52+
final String xml = this.conversionService.writeXml(results.getXvrlReportSummary());
5353
Files.write(file, xml.getBytes());
5454
} catch (final IOException e) {
5555
log.error("Can not serialize result report to {}", file.toAbsolutePath(), e);
@@ -71,7 +71,7 @@ private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError
7171

7272
@Override
7373
public boolean isSkipped(final Process results) {
74-
if (results.getReportInput() == null) {
74+
if (results.getMetadata() == null) {
7575
log.warn("Can not serialize report input. No object found");
7676
return true;
7777
}

Diff for: src/main/java/de/kosit/validationtool/impl/DefaultCheck.java

+18-45
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.util.stream.Collectors;
2727

2828
import de.kosit.validationtool.api.*;
29+
import de.kosit.validationtool.model.reportInput.ValidationResultsSchematron;
2930
import lombok.Getter;
3031
import lombok.extern.slf4j.Slf4j;
3132

@@ -35,22 +36,17 @@
3536
import de.kosit.validationtool.impl.tasks.ComputeAcceptanceAction;
3637
import de.kosit.validationtool.impl.tasks.CreateDocumentIdentificationAction;
3738
import de.kosit.validationtool.impl.tasks.CreateReportAction;
38-
import de.kosit.validationtool.impl.tasks.CreateXVRLReportAction;
3939
import de.kosit.validationtool.impl.tasks.DocumentParseAction;
4040
import de.kosit.validationtool.impl.tasks.ScenarioSelectionAction;
4141
import de.kosit.validationtool.impl.tasks.SchemaValidationAction;
4242
import de.kosit.validationtool.impl.tasks.SchematronValidationAction;
43-
import de.kosit.validationtool.impl.tasks.ValidateReportInputAction;
4443
import de.kosit.validationtool.impl.xml.ProcessorProvider;
45-
import de.kosit.validationtool.impl.xvrl.XmlErrorImpl;
4644
import de.kosit.validationtool.model.reportInput.CreateReportInput;
4745
import de.kosit.validationtool.model.reportInput.EngineType;
4846
import de.kosit.validationtool.model.reportInput.XMLSyntaxError;
4947
import de.kosit.validationtool.model.xvrl.Timestamp;
5048
import de.kosit.validationtool.model.xvrl.Validator;
51-
import de.kosit.validationtool.model.xvrl.XVRLDetection;
5249
import de.kosit.validationtool.model.xvrl.XVRLMetadata;
53-
import de.kosit.validationtool.model.xvrl.XVRLReport;
5450

5551
import net.sf.saxon.s9api.Processor;
5652
import net.sf.saxon.s9api.XdmNode;
@@ -96,9 +92,7 @@ public DefaultCheck(final Processor processor, final Configuration... configurat
9692
this.checkSteps.add(new ScenarioSelectionAction(new ScenarioRepository(configuration)));
9793
this.checkSteps.add(new SchemaValidationAction(processor));
9894
this.checkSteps.add(new SchematronValidationAction(this.conversionService));
99-
this.checkSteps.add(new ValidateReportInputAction(this.conversionService, SchemaProvider.getReportInputSchema()));
10095
this.checkSteps.add(new CreateReportAction(processor, this.conversionService));
101-
this.checkSteps.add(new CreateXVRLReportAction(processor, this.conversionService));
10296
this.checkSteps.add(new ComputeAcceptanceAction());
10397
}
10498

@@ -133,7 +127,7 @@ protected boolean isSuccessful(final Map<String, Result> results) {
133127

134128
@Override
135129
public Result checkInput(final Input input) {
136-
final Process checkProcess = new Process(input, createReport(), createXVRLMetadata());
130+
final Process checkProcess = new Process(input, createXVRLMetadata());
137131
return runCheckInternal(checkProcess);
138132
}
139133

@@ -150,45 +144,34 @@ protected Result runCheckInternal(final Process checkProcess) {
150144
}
151145
checkProcess.setFinished(true);
152146
log.info("Finished check of {} in {}ms\n", checkProcess.getInput().getName(), System.currentTimeMillis() - started);
153-
final Result result = createResult(checkProcess);
154-
// createXVRLResult(checkProcess);
155-
return result;
147+
return createResult(checkProcess);
156148
}
157149

158150
private Result createResult(final Process process) {
159-
final de.kosit.validationtool.impl.model.Result<XdmNode, XMLSyntaxError> report = process.getResult(CreateReportAction.class);
160-
de.kosit.validationtool.impl.model.Result<AcceptRecommendation, Object> acceptStatusResult = process
161-
.getResult(ComputeAcceptanceAction.class);
162-
163-
final DefaultResult result = new DefaultResult(report.getObject(), acceptStatusResult.getObject(),
164-
new HtmlExtractor(this.processor));
165-
result.setWellformed(process.getResult(DocumentParseAction.class).isValid());
166-
result.setReportInput(process.getReportInput());
167-
final de.kosit.validationtool.impl.model.Result<Boolean, XMLSyntaxError> schemaValidationResult = process
168-
.getResult(SchemaValidationAction.class);
169-
if (schemaValidationResult != null) {
170-
result.setSchemaViolations(convertErrors(schemaValidationResult.getErrors()));
171-
}
172-
result.setProcessingSuccessful(!process.isStopped() && process.isFinished());
173-
result.setSchematronResult(process.getReportInput().getValidationResultsSchematron().stream().filter(e -> e.getResults() != null)
174-
.map(e -> e.getResults().getSchematronOutput()).collect(Collectors.toList()));
175-
return result;
176-
}
177-
178-
private Result createXVRLResult(final Process process) {
179151

152+
de.kosit.validationtool.impl.model.Result<XdmNode, Object> createReportResult = process.getResult(CreateReportAction.class);
180153
de.kosit.validationtool.impl.model.Result<AcceptRecommendation, Object> acceptStatusResult = process
181154
.getResult(ComputeAcceptanceAction.class);
182-
de.kosit.validationtool.impl.model.Result<XdmNode, Object> createReportResult = process.getResult(CreateReportAction.class);
183155
final XVRLResult xvrlResult = new XVRLResult(createReportResult.getObject(), acceptStatusResult.getObject(),
184156
new HtmlExtractor(this.processor));
185157

186-
final XVRLReport parserReport = process.getReport(DocumentParseAction.class);
187-
xvrlResult.setWellformed("true".equals(parserReport.getDigest().getValid()));
158+
xvrlResult.setWellformed(process.getResult(DocumentParseAction.class).isValid());
188159

189160
xvrlResult.setReportSummary(process.getXvrlReportSummary());
190-
xvrlResult.setSchemaViolations(convertErrorsFromXVRLDetections(process.getXvrlReportSummary().getAllErrorDetections()));
191161

162+
final de.kosit.validationtool.impl.model.Result<Boolean, XMLSyntaxError> schemaValidationResult = process
163+
.getResult(SchemaValidationAction.class);
164+
if (schemaValidationResult != null) {
165+
xvrlResult.setSchemaViolations(convertErrors(schemaValidationResult.getErrors()));
166+
}
167+
168+
de.kosit.validationtool.impl.model.Result<List<ValidationResultsSchematron>, Object> schematronValidationResult = process
169+
.getResult(SchematronValidationAction.class);
170+
if (schematronValidationResult != null) {
171+
xvrlResult.setSchematronResult(schematronValidationResult.getObject().stream()
172+
.map(schematronResult -> schematronResult.getResults().getSchematronOutput())
173+
.collect(Collectors.toList()));
174+
}
192175
xvrlResult.setProcessingSuccessful(!process.isStopped() && process.isFinished());
193176

194177
return xvrlResult;
@@ -198,14 +181,4 @@ private static List<XmlError> convertErrors(final Collection<XMLSyntaxError> err
198181
// noinspection unchecked
199182
return (List<XmlError>) (List<?>) errors;
200183
}
201-
202-
private static List<XmlError> convertErrorsFromXVRLDetections(final Collection<XVRLDetection> errors) {
203-
final List<XmlError> xmlErrorList = new ArrayList<>();
204-
errors.forEach(xvrlDetection -> {
205-
final XmlError xmlError = new XmlErrorImpl(xvrlDetection);
206-
xmlErrorList.add(xmlError);
207-
});
208-
return xmlErrorList;
209-
}
210-
211184
}

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/CheckAction.java

+12-32
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@
2121

2222
import org.apache.commons.io.FilenameUtils;
2323

24-
import lombok.AccessLevel;
2524
import lombok.Getter;
2625
import lombok.Setter;
2726

2827
import de.kosit.validationtool.api.Input;
2928
import de.kosit.validationtool.impl.model.ProcessStepResult;
3029
import de.kosit.validationtool.impl.model.Result;
31-
import de.kosit.validationtool.model.reportInput.CreateReportInput;
32-
import de.kosit.validationtool.model.reportInput.ProcessingError;
3330
import de.kosit.validationtool.model.xvrl.XVRLMetadata;
3431
import de.kosit.validationtool.model.xvrl.XVRLReport;
3532
import de.kosit.validationtool.model.xvrl.XVRLReportSummary;
@@ -55,25 +52,22 @@ class Process {
5552

5653
private List<ProcessStepResult> processStepResults = new ArrayList<>();
5754

58-
@Setter(AccessLevel.NONE)
59-
private CreateReportInput reportInput;
60-
6155
private boolean finished;
6256

6357
private boolean stopped;
6458

6559
/** Das zu prüfende Dokument */
6660
private Input input;
6761

68-
private Result<Integer, String> assertionResult;
62+
// TODO Remove this after checking assertion
63+
// private Result<Integer, String> assertionResult;
6964

7065
public Process(final Input input) {
71-
this(input, new CreateReportInput(), new XVRLMetadata());
66+
this(input, new XVRLMetadata());
7267
}
7368

74-
public Process(final Input input, final CreateReportInput reportInput, final XVRLMetadata xvrlMetadata) {
69+
public Process(final Input input, final XVRLMetadata xvrlMetadata) {
7570
this.input = input;
76-
this.reportInput = reportInput;
7771
this.metadata = xvrlMetadata;
7872
}
7973

@@ -89,41 +83,27 @@ public void addStepResult(final ProcessStepResult result) {
8983
}
9084
}
9185

92-
public XVRLReport getReport(final Class<? extends CheckAction> callingAction) {
93-
return this.processStepResults.stream().filter(b -> b.getType().equals(callingAction)).findFirst()
94-
.orElseThrow(IllegalArgumentException::new).getReport();
95-
}
96-
9786
public XVRLReportSummary getXvrlReportSummary() {
9887
final XVRLReportSummary summary = new XVRLReportSummary();
9988
summary.setMetadata(this.metadata);
10089
summary.getReports().addAll(this.processStepResults.stream().map(ProcessStepResult::getReport).collect(Collectors.toList()));
10190
return summary;
10291
}
10392

93+
public XVRLReport getReport(final Class<? extends CheckAction> callingAction) {
94+
return this.processStepResults.stream().filter(b -> b.getType().equals(callingAction)).findFirst()
95+
.orElse(new ProcessStepResult()).getReport();
96+
}
97+
10498
public <D extends CheckAction, T, E> Result<T, E> getResult(final Class<D> type) {
10599
// noinspection unchecked
106100
return (Result<T, E>) this.processStepResults.stream().filter(b -> b.getType().equals(type)).findFirst()
107101
.orElse(new ProcessStepResult()).getResult();
108102
}
109103

110-
/**
111-
* Signalisiert einen vorzeitigen Stop der Vearbeitung.
112-
*/
113-
public void stopProcessing(final String error) {
114-
stopProcessing(Collections.singleton(error));
115-
}
116-
117-
public void stopProcessing(final Collection<String> errors) {
118-
this.stopped = true;
119-
if (this.reportInput.getProcessingError() == null) {
120-
this.reportInput.setProcessingError(new ProcessingError());
121-
}
122-
this.reportInput.getProcessingError().getError().addAll(errors);
123-
}
124-
125-
public void addProcessingError(final String msg) {
126-
stopProcessing(msg);
104+
public <D extends CheckAction> ProcessStepResult getProcessStepResult(final Class<D> callingAction) {
105+
return this.processStepResults.stream().filter(b -> b.getType().equals(callingAction)).findFirst()
106+
.orElse(new ProcessStepResult());
127107
}
128108

129109
/**

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/ComputeAcceptanceAction.java

+23-18
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616

1717
package de.kosit.validationtool.impl.tasks;
1818

19+
import java.util.Collections;
1920
import java.util.Optional;
2021

2122
import de.kosit.validationtool.impl.xvrl.XVRLBuilder;
2223
import de.kosit.validationtool.model.xvrl.XVRLReport;
23-
import org.oclc.purl.dsdl.svrl.FailedAssert;
2424

2525
import lombok.RequiredArgsConstructor;
2626
import lombok.extern.slf4j.Slf4j;
@@ -47,39 +47,39 @@ public class ComputeAcceptanceAction implements CheckAction {
4747

4848
@Override
4949
public ProcessStepResult check(final Process results) {
50-
AcceptRecommendation acceptRecommendation = AcceptRecommendation.UNDEFINED;
50+
final ProcessStepResult stepResult = new ProcessStepResult();
51+
Result<AcceptRecommendation, XMLSyntaxError> result = new Result<>(AcceptRecommendation.UNDEFINED);
5152
if (!results.isStopped() && results.getResult(DocumentParseAction.class).isValid()) {
5253
if (preCondtionsMatch(results)) {
5354
final Result<Scenario, String> scenarioSelection = results.getResult(ScenarioSelectionAction.class);
5455
final Optional<XPathSelector> acceptMatch = scenarioSelection.getObject().getAcceptSelector();
5556
if (results.getResult(SchemaValidationAction.class).isValid() && acceptMatch.isPresent()) {
56-
acceptRecommendation = evaluateAcceptanceMatch(results, acceptMatch.get());
57+
result = evaluateAcceptanceMatch(results, acceptMatch.get());
5758
} else {
58-
acceptRecommendation = evaluateSchemaAndSchematron(results);
59+
result = evaluateSchemaAndSchematron(results);
5960
}
6061
} else {
61-
acceptRecommendation = AcceptRecommendation.REJECT;
62+
XMLSyntaxError xmlSyntaxError = new XMLSyntaxError();
63+
xmlSyntaxError.setMessage("Pre-Conditions not Matched");
64+
result = new Result<>(AcceptRecommendation.REJECT, Collections.singleton(xmlSyntaxError));
6265
}
6366
}
64-
65-
final ProcessStepResult stepResult = new ProcessStepResult();
66-
Result<Object, XMLSyntaxError> result = new Result<>(acceptRecommendation);
6767
stepResult.setResult(result);
6868
stepResult.setType(ComputeAcceptanceAction.class);
6969
stepResult.setReport(generateXVRLReport(result));
7070
return stepResult;
7171
}
7272

73-
private static XVRLReport generateXVRLReport(final Result<Object, XMLSyntaxError> currentResult) {
73+
private static XVRLReport generateXVRLReport(final Result<AcceptRecommendation, XMLSyntaxError> currentResult) {
7474
// TODO create report here
7575
return XVRLBuilder.builder().name("Compute Acceptance Validator").addErrors(currentResult.getErrors()).build();
7676
}
7777

78-
private static AcceptRecommendation evaluateSchemaAndSchematron(final Process results) {
78+
private static Result<AcceptRecommendation, XMLSyntaxError> evaluateSchemaAndSchematron(final Process results) {
7979
if (results.getResult(SchemaValidationAction.class).isValid() && isSchematronValid(results)) {
80-
return AcceptRecommendation.ACCEPTABLE;
80+
return new Result<>(AcceptRecommendation.ACCEPTABLE);
8181
}
82-
return AcceptRecommendation.REJECT;
82+
return new Result<>(AcceptRecommendation.REJECT);
8383

8484
}
8585

@@ -88,20 +88,25 @@ private static boolean isSchematronValid(final Process results) {
8888
}
8989

9090
private static boolean hasSchematronErrors(final Process results) {
91-
return results.getReportInput().getValidationResultsSchematron().stream().map(e -> e.getResults().getSchematronOutput())
92-
.flatMap(e -> e.getActivePatternAndFiredRuleAndFailedAssert().stream()).anyMatch(FailedAssert.class::isInstance);
91+
XVRLReport report = results.getReport(SchematronValidationAction.class);
92+
if (report == null) {
93+
return false;
94+
}
95+
return !report.getAllErrors().isEmpty();
9396
}
9497

95-
private static AcceptRecommendation evaluateAcceptanceMatch(final Process results, final XPathSelector selector) {
98+
private static Result<AcceptRecommendation, XMLSyntaxError> evaluateAcceptanceMatch(final Process results, final XPathSelector selector) {
9699
try {
97100
final Result<XdmNode, XMLSyntaxError> report = results.getResult(CreateReportAction.class);
98101
selector.setContextItem(report.getObject());
99-
return selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT;
102+
AcceptRecommendation effectiveBooleanValue = selector.effectiveBooleanValue() ? AcceptRecommendation.ACCEPTABLE : AcceptRecommendation.REJECT;
103+
return new Result<>(effectiveBooleanValue);
100104
} catch (final SaxonApiException e) {
101105
final String msg = String.format("Error evaluating accept recommendation: %s", selector.getUnderlyingXPathContext().toString());
102106
log.error(msg, e);
103-
results.stopProcessing(msg);
104-
return AcceptRecommendation.REJECT;
107+
XMLSyntaxError xmlSyntaxError = new XMLSyntaxError();
108+
xmlSyntaxError.setMessage(msg);
109+
return new Result<>(AcceptRecommendation.REJECT, Collections.singletonList(xmlSyntaxError));
105110
}
106111
}
107112

Diff for: src/main/java/de/kosit/validationtool/impl/tasks/CreateDocumentIdentificationAction.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,14 @@
3333
public class CreateDocumentIdentificationAction implements CheckAction {
3434

3535
@Override
36-
public ProcessStepResult check(final Process transporter) {
36+
public ProcessStepResult check(final Process process) {
3737
final DocumentIdentificationType i = new DocumentIdentificationType();
3838
final DocumentIdentificationType.DocumentHash h = new DocumentIdentificationType.DocumentHash();
39-
h.setHashAlgorithm(transporter.getInput().getDigestAlgorithm());
40-
h.setHashValue(transporter.getInput().getHashCode());
39+
h.setHashAlgorithm(process.getInput().getDigestAlgorithm());
40+
h.setHashValue(process.getInput().getHashCode());
4141
i.setDocumentHash(h);
42-
i.setDocumentReference(transporter.getInput().getName());
43-
transporter.getReportInput().setDocumentIdentification(i);
44-
addDocumentIdentification(transporter);
42+
i.setDocumentReference(process.getInput().getName());
43+
addDocumentIdentification(process);
4544

4645
ProcessStepResult processStepResult = new ProcessStepResult();
4746
processStepResult.setType(CreateDocumentIdentificationAction.class);

0 commit comments

Comments
 (0)