forked from FasterXML/woodstox
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a reproducer for FasterXML#190 'Element <root> has no attribute "…
…verbose"' not thrown from RepairingNsStreamWriter when validating against a DTD schema
- Loading branch information
Showing
4 changed files
with
119 additions
and
10 deletions.
There are no files selected for viewing
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,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 = "<root note=\"note\" verbose=\"yes\"/>"; | ||
|
||
final String INPUT_DTD = | ||
"<!ELEMENT root ANY>\n" | ||
+"<!ATTLIST root note CDATA #IMPLIED>\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<XMLValidationProblem> probs = new ArrayList<XMLValidationProblem>(); | ||
|
||
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 <root> 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); | ||
} | ||
|
||
} | ||
} |
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,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 = | ||
"<dummy>\n" | ||
+"<dict>\n" | ||
+"<term type=\"name\">\n" | ||
+" <word>foobar</word>\n" | ||
+" <description>Foo Bar</description>\n" | ||
+"</term></dict>\n" | ||
+"</dummy>" | ||
; | ||
XMLValidationSchema schema = parseRngSchema(SIMPLE_RNG_SCHEMA); | ||
{ | ||
StringWriter writer = new StringWriter(); | ||
RepairingNsStreamWriter sw = (RepairingNsStreamWriter) constructStreamWriter(writer, true, true); | ||
_testPartialValidationOk(XML, schema, sw, writer); | ||
} | ||
} | ||
|
||
|
||
} |
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
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