-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
ph-schematron-pure/src/test/java/com/helger/schematron/pure/supplementary/Issue170Test.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,61 @@ | ||
/* | ||
* Copyright (C) 2014-2024 Philip Helger (www.helger.com) | ||
* philip[at]helger[dot]com | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.helger.schematron.pure.supplementary; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import java.io.File; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import org.junit.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.helger.commons.io.resource.FileSystemResource; | ||
import com.helger.schematron.pure.SchematronResourcePure; | ||
import com.helger.schematron.pure.errorhandler.LoggingPSErrorHandler; | ||
import com.helger.schematron.svrl.SVRLHelper; | ||
import com.helger.schematron.svrl.SVRLMarshaller; | ||
import com.helger.schematron.svrl.jaxb.SchematronOutputType; | ||
|
||
public final class Issue170Test | ||
{ | ||
private static final Logger LOGGER = LoggerFactory.getLogger (Issue170Test.class); | ||
|
||
public static void validateAndProduceSVRL (@Nonnull final File aSchematron, final File aXML) throws Exception | ||
{ | ||
final SchematronResourcePure aSCH = SchematronResourcePure.fromFile (aSchematron); | ||
aSCH.validateCompletely (new LoggingPSErrorHandler ()); | ||
|
||
// Perform validation | ||
final SchematronOutputType aSVRL = aSCH.applySchematronValidationToSVRL (new FileSystemResource (aXML)); | ||
assertNotNull (aSVRL); | ||
if (true) | ||
LOGGER.info (new SVRLMarshaller ().getAsString (aSVRL)); | ||
|
||
assertEquals (1, SVRLHelper.getAllFailedAssertionsAndSuccessfulReports (aSVRL).size ()); | ||
} | ||
|
||
@Test | ||
public void testIssue () throws Exception | ||
{ | ||
validateAndProduceSVRL (new File ("src/test/resources/external/issues/github170/schematron.sch"), | ||
new File ("src/test/resources/external/issues/github170/test.xml")); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
ph-schematron-pure/src/test/resources/external/issues/github170/schematron.sch
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,14 @@ | ||
<schema xmlns="http://purl.oclc.org/dsdl/schematron" queryBinding="xpath2"> | ||
<pattern> | ||
<rule context="/xml"> | ||
<let name="stringVar" value="'foo'"/> | ||
<rule context="/*"> | ||
<assert role="ERROR" test="$stringVar eq 'bar'">error message</assert> | ||
</rule> | ||
</rule> | ||
<rule context="/xml/owner"> | ||
<let name="booleanVar" value="1 eq 1"/> | ||
<assert role="ERROR" test="$booleanVar eq true()">error message</assert> | ||
</rule> | ||
</pattern> | ||
</schema> |
9 changes: 9 additions & 0 deletions
9
ph-schematron-pure/src/test/resources/external/issues/github170/test.xml
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,9 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<xml> | ||
<owner id="o1" /> | ||
<car id="c1" owner="o1" /> | ||
|
||
<owner id="o2" /> | ||
<car id="c2" owner="o2" /> | ||
<car id="c3" owner="o2" /> | ||
</xml> |