#58 Fix schematron evaluation

add tests with schematron
This commit is contained in:
Andreas Penski (init) 2020-07-28 17:05:59 +02:00
parent 5a7c6775b1
commit ecf1e1cef4
17 changed files with 340 additions and 12 deletions

View file

@ -77,7 +77,7 @@ public class InputFactoryTest {
public void testHashCodeGeneration() throws IOException {
final byte[] s1 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode();
final byte[] s2 = drain(InputFactory.read(Simple.SIMPLE_VALID.toURL())).getHashCode();
final byte[] s3 = drain(InputFactory.read(Simple.INVALID.toURL())).getHashCode();
final byte[] s3 = drain(InputFactory.read(Simple.SCHEMA_INVALID.toURL())).getHashCode();
assertThat(s1).isNotEmpty();
assertThat(s1).isEqualTo(s2);
assertThat(s3).isNotEmpty();

View file

@ -141,7 +141,7 @@ public class CommandlineApplicationTest {
final String[] args = new String[] { "-s", Paths.get(Simple.SCENARIOS).toString(), "-o", this.output.toString(), "-r",
Paths.get(Simple.REPOSITORY_URI).toString(), Paths.get(Simple.EXAMPLES).toString() };
CommandLineApplication.mainProgram(args);
assertThat(this.commandLine.getErrorOutput()).contains("Processing 6 object(s) completed");
assertThat(this.commandLine.getErrorOutput()).contains("Processing 8 object(s) completed");
}
@Test

View file

@ -50,7 +50,7 @@ public class SchemaBuilderTest {
@Test
public void testInvalidSchema() {
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.INVALID);
final SchemaBuilder builder = schema("myname").schemaLocation(Simple.SCHEMA_INVALID);
final Result<Pair<ValidateWithXmlSchema, Schema>, String> result = builder.build(Simple.createContentRepository());
assertThat(result).isNotNull();
assertThat(result.isValid()).isFalse();

View file

@ -38,7 +38,7 @@ public class CheckHandlerIT extends BaseIT {
@Test
@Ignore // no default error report yet
public void internalServerErrorTest() throws IOException {
try ( final InputStream io = Simple.INVALID.toURL().openStream() ) {
try ( final InputStream io = Simple.SCHEMA_INVALID.toURL().openStream() ) {
given().contentType(APPLICATION_XML).body(toContent(io)).when().post("/").then().statusCode(200);
}
}

View file

@ -20,9 +20,11 @@
package de.kosit.validationtool.impl;
import static de.kosit.validationtool.api.InputFactory.read;
import static de.kosit.validationtool.impl.Helper.Simple.FOO_SCHEMATRON_INVALID;
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.REJECTED;
import static de.kosit.validationtool.impl.Helper.Simple.SCHEMATRON_INVALID;
import static de.kosit.validationtool.impl.Helper.Simple.UNKNOWN;
import static org.assertj.core.api.Assertions.assertThat;
@ -48,8 +50,6 @@ import de.kosit.validationtool.impl.Helper.Simple;
*/
public class DefaultCheckTest {
public static final int MULTI_COUNT = 5;
private DefaultCheck implementation;
@ -67,6 +67,8 @@ public class DefaultCheckTest {
assertThat(doc).isNotNull();
assertThat(doc.getReport()).isNotNull();
assertThat(doc.isAcceptable()).isTrue();
assertThat(doc.isSchematronValid()).isTrue();
assertThat(doc.isSchemaValid()).isTrue();
assertThat(doc.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
}
@ -157,4 +159,37 @@ public class DefaultCheckTest {
assertThat(result.getReportDocument()).isNotNull();
}
@Test
public void testSchematronFailed() {
final Result result = this.implementation.checkInput(read(SCHEMATRON_INVALID));
assertThat(result).isNotNull();
assertThat(result.isWellformed()).isTrue();
assertThat(result.isSchemaValid()).isTrue();
assertThat(result.getFailedAsserts()).isNotEmpty();
assertThat(result.isSchematronValid()).isFalse();
assertThat(result.isProcessingSuccessful()).isTrue();
// acceptMatch overules schematron!!!
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.ACCEPTABLE);
assertThat(result.isAcceptable()).isTrue();
assertThat(result.getReport()).isNotNull();
assertThat(result.getReportDocument()).isNotNull();
}
@Test
public void testSchematronFailedWithoutAcceptMatch() {
final Result result = this.implementation.checkInput(read(FOO_SCHEMATRON_INVALID));
assertThat(result).isNotNull();
assertThat(result.isWellformed()).isTrue();
assertThat(result.isSchemaValid()).isTrue();
result.getFailedAsserts();
assertThat(result.isSchematronValid()).isFalse();
assertThat(result.getFailedAsserts()).isNotEmpty();
assertThat(result.isProcessingSuccessful()).isTrue();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
assertThat(result.isAcceptable()).isFalse();
assertThat(result.getReport()).isNotNull();
assertThat(result.getReportDocument()).isNotNull();
}
}

View file

@ -58,13 +58,17 @@ public class Helper {
public static final URI FOO = Simple.ROOT.resolve("input/foo.xml");
public static final URI FOO_SCHEMATRON_INVALID = EXAMPLES.resolve("foo-schematron-invalid.xml");
public static final URI REJECTED = Simple.ROOT.resolve("input/withManualReject.xml");
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
public static final URI REPOSITORY_URI = ROOT.resolve("repository/");
public static final URI INVALID = ROOT.resolve("input/simple-invalid.xml");
public static final URI SCHEMA_INVALID = ROOT.resolve("input/simple-schema-invalid.xml");
public static final URI SCHEMATRON_INVALID = ROOT.resolve("input/simple-schematron-invalid.xml");
public static final URI NOT_WELLFORMED = ROOT.resolve("input/simple-not-wellformed.xml");
@ -95,6 +99,7 @@ public class Helper {
public static final URI SCENARIOS = ROOT.resolve("scenarios.xml");
public static final URI SCENARIOS_ILLFORMED = ROOT.resolve("scenarios-illformed.xml");
}
public static class Resolving {

View file

@ -38,7 +38,7 @@ public class SimpleScenarioCheckTest {
@Test
public void testInvalid() throws MalformedURLException {
final Result result = this.implementation.checkInput(InputFactory.read(Simple.INVALID.toURL()));
final Result result = this.implementation.checkInput(InputFactory.read(Simple.SCHEMA_INVALID.toURL()));
assertThat(result).isNotNull();
assertThat(result.getAcceptRecommendation()).isEqualTo(AcceptRecommendation.REJECT);
assertThat(result.getSchemaViolations()).isNotEmpty();

View file

@ -78,7 +78,7 @@ public class SchemaValidatorActionTest {
@Test
public void testValidationFailure() throws MalformedURLException {
final Input input = InputFactory.read(Simple.INVALID.toURL());
final Input input = InputFactory.read(Simple.SCHEMA_INVALID.toURL());
final CheckAction.Bag bag = createBag(input);
this.service.check(bag);
assertThat(bag.getSchemaValidationResult().isValid()).isFalse();