Skip to content

Commit

Permalink
Added test for #170
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Jul 15, 2024
1 parent 84be42e commit 6fcd205
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
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"));
}
}
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>
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>

0 comments on commit 6fcd205

Please sign in to comment.