diff --git a/src/test/java/failing/TestInvalidAttributeValue190.java b/src/test/java/failing/TestInvalidAttributeValue190.java new file mode 100644 index 0000000..edac3cb --- /dev/null +++ b/src/test/java/failing/TestInvalidAttributeValue190.java @@ -0,0 +1,74 @@ +package failing; + +import stax2.BaseStax2Test; + +import java.io.StringReader; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.stream.*; + +import org.codehaus.stax2.XMLStreamReader2; +import org.codehaus.stax2.validation.ValidationProblemHandler; +import org.codehaus.stax2.validation.XMLValidationException; +import org.codehaus.stax2.validation.XMLValidationProblem; +import org.codehaus.stax2.validation.XMLValidationSchema; +import org.codehaus.stax2.validation.XMLValidationSchemaFactory; + +import com.ctc.wstx.sw.RepairingNsStreamWriter; + +public class TestInvalidAttributeValue190 + extends BaseStax2Test +{ + /* A reproducer for https://github.com/FasterXML/woodstox/issues/190 */ + public void testInvalidAttributeValue() throws Exception + { + final String DOC = ""; + + final String INPUT_DTD = +"\n" ++"\n" +; + + XMLInputFactory f = getInputFactory(); + setCoalescing(f, true); + + XMLValidationSchemaFactory schemaFactory = + XMLValidationSchemaFactory.newInstance(XMLValidationSchema.SCHEMA_ID_DTD); + XMLValidationSchema schema = schemaFactory.createSchema(new StringReader(INPUT_DTD)); + XMLStreamReader2 sr = (XMLStreamReader2)f.createXMLStreamReader( + new StringReader(DOC)); + + final List probs = new ArrayList(); + + sr.validateAgainst(schema); + sr.setValidationProblemHandler(new ValidationProblemHandler() { + @Override + public void reportProblem(XMLValidationProblem problem) + throws XMLValidationException { + probs.add(problem); + } + }); + + assertTokenType(START_ELEMENT, sr.next()); + assertEquals("root", sr.getLocalName()); + + final String verboseValue = sr.getAttributeValue(null, "verbose"); + + assertEquals("yes", verboseValue); + + assertEquals(1, probs.size()); + assertEquals("Element has no attribute \"verbose\"", probs.get(0).getMessage()); + + // now do the same on the writer side + // and make sure that the reported problems are the same + { + // RepairingNsStreamWriter + StringWriter writer = new StringWriter(); + RepairingNsStreamWriter sw = (RepairingNsStreamWriter) stax2.BaseStax2Test.constructStreamWriter(writer, true, true); + validateWriter(DOC, probs, f, schema, writer, sw); + } + + } +} diff --git a/src/test/java/failing/TestRelaxNG190.java b/src/test/java/failing/TestRelaxNG190.java new file mode 100644 index 0000000..658e274 --- /dev/null +++ b/src/test/java/failing/TestRelaxNG190.java @@ -0,0 +1,43 @@ +package failing; + +import java.io.StringWriter; + +import javax.xml.stream.*; + +import org.codehaus.stax2.validation.*; + +import com.ctc.wstx.sw.RepairingNsStreamWriter; + +/** + * A reproducer for https://github.com/FasterXML/woodstox/issues/190 + * Move to {@link wstxtest.vstream.TestRelaxNG} once fixed. + */ +public class TestRelaxNG190 + extends wstxtest.vstream.TestRelaxNG +{ + + public void testPartialValidationOk() + throws XMLStreamException + { + /* Hmmh... RelaxNG does define expected root. So need to + * wrap the doc... + */ + String XML = + "\n" + +"\n" + +"\n" + +" foobar\n" + +" Foo Bar\n" + +"\n" + +"" + ; + XMLValidationSchema schema = parseRngSchema(SIMPLE_RNG_SCHEMA); + { + StringWriter writer = new StringWriter(); + RepairingNsStreamWriter sw = (RepairingNsStreamWriter) constructStreamWriter(writer, true, true); + _testPartialValidationOk(XML, schema, sw, writer); + } + } + + +} diff --git a/src/test/java/wstxtest/vstream/TestInvalidAttributeValue.java b/src/test/java/wstxtest/vstream/TestInvalidAttributeValue.java index 4f89cc0..cd9c400 100644 --- a/src/test/java/wstxtest/vstream/TestInvalidAttributeValue.java +++ b/src/test/java/wstxtest/vstream/TestInvalidAttributeValue.java @@ -16,7 +16,6 @@ import org.codehaus.stax2.validation.XMLValidationSchema; import org.codehaus.stax2.validation.XMLValidationSchemaFactory; -import com.ctc.wstx.sw.RepairingNsStreamWriter; import com.ctc.wstx.sw.SimpleNsStreamWriter; public class TestInvalidAttributeValue @@ -69,12 +68,5 @@ public void reportProblem(XMLValidationProblem problem) SimpleNsStreamWriter sw = (SimpleNsStreamWriter) stax2.BaseStax2Test.constructStreamWriter(writer, true, false); validateWriter(DOC, probs, f, schema, writer, sw); } - { - // RepairingNsStreamWriter - StringWriter writer = new StringWriter(); - RepairingNsStreamWriter sw = (RepairingNsStreamWriter) stax2.BaseStax2Test.constructStreamWriter(writer, true, true); - validateWriter(DOC, probs, f, schema, writer, sw); - } - } } diff --git a/src/test/java/wstxtest/vstream/TestRelaxNG.java b/src/test/java/wstxtest/vstream/TestRelaxNG.java index 6fac4b1..9817d31 100644 --- a/src/test/java/wstxtest/vstream/TestRelaxNG.java +++ b/src/test/java/wstxtest/vstream/TestRelaxNG.java @@ -18,7 +18,7 @@ public class TestRelaxNG extends BaseValidationTest { - final static String SIMPLE_RNG_SCHEMA = + protected final static String SIMPLE_RNG_SCHEMA = "\n" +" \n" +" \n" @@ -500,7 +500,7 @@ public void testPartialValidationOk() } } - private void _testPartialValidationOk(String XML, XMLValidationSchema schema, XMLStreamWriter2 sw, StringWriter writer) throws XMLStreamException { + protected void _testPartialValidationOk(String XML, XMLValidationSchema schema, XMLStreamWriter2 sw, StringWriter writer) throws XMLStreamException { XMLStreamReader2 sr = getReader(XML); assertTokenType(START_ELEMENT, sr.next()); sw.copyEventFromReader(sr, false);