mirror of
https://github.com/itplr-kosit/validator.git
synced 2026-05-25 16:55:39 +00:00
#50 (fix) Validator creates invalid createReportInput xml in case of no scenrio match
This commit is contained in:
parent
610348d3bd
commit
a1a7328b8f
5 changed files with 31 additions and 3 deletions
|
|
@ -164,6 +164,7 @@ public class ScenarioRepository {
|
|||
|
||||
private ScenarioType createFallback() {
|
||||
final ScenarioType t = new ScenarioType();
|
||||
t.setFallback(true);
|
||||
t.setName("Fallback-Scenario");
|
||||
final CreateReportType reportType = new CreateReportType();
|
||||
reportType.setResource(this.scenarios.getNoScenarioReport().getResource());
|
||||
|
|
|
|||
|
|
@ -66,6 +66,10 @@ public abstract class BaseScenario {
|
|||
private ResourceType resourceType;
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean fallback;
|
||||
|
||||
private XPathExecutable matchExecutable;
|
||||
|
||||
private XPathExecutable acceptExecutable;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
package de.kosit.validationtool.impl.tasks;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import de.kosit.validationtool.impl.ScenarioRepository;
|
||||
import de.kosit.validationtool.impl.model.Result;
|
||||
|
|
@ -35,6 +36,7 @@ import net.sf.saxon.s9api.XdmNode;
|
|||
* @author Andreas Penski
|
||||
*/
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class ScenarioSelectionAction implements CheckAction {
|
||||
|
||||
private final ScenarioRepository repository;
|
||||
|
|
@ -47,16 +49,21 @@ public class ScenarioSelectionAction implements CheckAction {
|
|||
if (results.getParserResult().isValid()) {
|
||||
scenarioTypeResult = determineScenario(results.getParserResult().getObject());
|
||||
} else {
|
||||
scenarioTypeResult = new Result<>(repository.getFallbackScenario());
|
||||
scenarioTypeResult = new Result<>(this.repository.getFallbackScenario());
|
||||
}
|
||||
results.setScenarioSelectionResult(scenarioTypeResult);
|
||||
report.setScenario(scenarioTypeResult.getObject());
|
||||
if (!scenarioTypeResult.getObject().isFallback()) {
|
||||
report.setScenario(scenarioTypeResult.getObject());
|
||||
log.error("Schenario {} identified for {}", scenarioTypeResult.getObject().getName(), results.getInput().getName());
|
||||
} else {
|
||||
log.error("No valid schenario configuration found for {}", results.getInput().getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Result<ScenarioType, String> determineScenario(final XdmNode document) {
|
||||
final Result<ScenarioType, String> result = this.repository.selectScenario(document);
|
||||
if (result.isInvalid()) {
|
||||
return new Result<>(repository.getFallbackScenario());
|
||||
return new Result<>(this.repository.getFallbackScenario());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ package de.kosit.validationtool.impl;
|
|||
import static de.kosit.validationtool.api.InputFactory.read;
|
||||
import static de.kosit.validationtool.impl.Helper.Simple.GARBAGE;
|
||||
import static de.kosit.validationtool.impl.Helper.Simple.NOT_WELLFORMED;
|
||||
import static de.kosit.validationtool.impl.Helper.Simple.UNKNOWN;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.io.File;
|
||||
|
|
@ -115,6 +116,17 @@ public class DefaultCheckTest {
|
|||
assertThat(result.isProcessingSuccessful()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoScenario() {
|
||||
final Result result = this.implementation.checkInput(read(UNKNOWN));
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result.isWellformed()).isTrue();
|
||||
assertThat(result.isProcessingSuccessful()).isTrue();
|
||||
assertThat(result.isSchemaValid()).isFalse();
|
||||
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
|
||||
assertThat(result.isAcceptable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNotWellFormed() {
|
||||
final Result result = this.implementation.checkInput(read(NOT_WELLFORMED));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue