From b4abb1e0a1a02e041422aa62d98af7dfa157eeec Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Sat, 13 Jan 2024 15:51:36 +0100 Subject: [PATCH] Add a reproducer for #189 'Undefined ID' not thrown when validating with SimpleNsStreamWriter --- src/test/java/failing/TestRelaxNG189.java | 62 +++++++++++++++++++ src/test/java/failing/TestW3CSchema189.java | 29 +++++++++ src/test/java/wstxtest/msv/TestW3CSchema.java | 4 +- 3 files changed, 93 insertions(+), 2 deletions(-) create mode 100644 src/test/java/failing/TestRelaxNG189.java create mode 100644 src/test/java/failing/TestW3CSchema189.java diff --git a/src/test/java/failing/TestRelaxNG189.java b/src/test/java/failing/TestRelaxNG189.java new file mode 100644 index 0000000..45a6e34 --- /dev/null +++ b/src/test/java/failing/TestRelaxNG189.java @@ -0,0 +1,62 @@ +package failing; + +import javax.xml.stream.*; + +import org.codehaus.stax2.validation.*; + +import wstxtest.vstream.BaseValidationTest; + +/** + * A reproducer for https://github.com/FasterXML/woodstox/issues/189 + * Move to {@link wstxtest.vstream.TestRelaxNG} once fixed. + */ +public class TestRelaxNG189 + extends BaseValidationTest +{ + + /** + * Test case for testing handling ID/IDREF/IDREF attributes, using + * schema datatype library. + */ + public void testSimpleIdAttrsWriter() + throws XMLStreamException + { + final String schemaDef = + "\n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +" \n" + +"" + ; + + XMLValidationSchema schema = parseRngSchema(schemaDef); + + String XML; + + // And then invalid one, with dangling ref + XML = "" + +" \n" + +"" + ; + verifyFailure(XML, schema, "reference to undefined id", + "Undefined ID", true, false, true); + + // and another one with some of refs undefined + XML = "" + +" \n" + +"" + ; + verifyFailure(XML, schema, "reference to undefined id", + "Undefined ID", true, false, true); + } + +} diff --git a/src/test/java/failing/TestW3CSchema189.java b/src/test/java/failing/TestW3CSchema189.java new file mode 100644 index 0000000..a505652 --- /dev/null +++ b/src/test/java/failing/TestW3CSchema189.java @@ -0,0 +1,29 @@ +package failing; + +import javax.xml.stream.XMLStreamException; + +import org.codehaus.stax2.validation.XMLValidationSchema; + +import wstxtest.msv.TestW3CSchema; + +/** + */ +public class TestW3CSchema189 + extends TestW3CSchema +{ + + /** + * A reproducer for https://github.com/FasterXML/woodstox/issues/189 + * Move to {@link TestW3CSchema} once fixed. + */ + public void testSimpleNonNsUndefinedIdWriter189() throws XMLStreamException + { + XMLValidationSchema schema = parseW3CSchema(SIMPLE_NON_NS_SCHEMA); + String XML = "" + + "FG" + + ""; + verifyFailure(XML, schema, "undefined referenced id ('m3')", + "Undefined ID 'm3'", true, false, true); + } + +} diff --git a/src/test/java/wstxtest/msv/TestW3CSchema.java b/src/test/java/wstxtest/msv/TestW3CSchema.java index 45de883..d894cba 100644 --- a/src/test/java/wstxtest/msv/TestW3CSchema.java +++ b/src/test/java/wstxtest/msv/TestW3CSchema.java @@ -24,7 +24,7 @@ public class TestW3CSchema /** * Sample schema, using sample 'personal.xsd' found from the web */ - final static String SIMPLE_NON_NS_SCHEMA = "\n" + protected final static String SIMPLE_NON_NS_SCHEMA = "\n" + "\n" + "\n" + "\n" @@ -173,7 +173,7 @@ public void testSimpleNonNsUndefinedId() throws XMLStreamException + "FG" + ""; verifyFailure(XML, schema, "undefined referenced id ('m3')", - "Undefined ID 'm3'"); + "Undefined ID 'm3'", true, true, false); } public void testSimpleDataTypes() throws XMLStreamException