Skip to content

Commit f5cc10a

Browse files
authored
Refactor Woodstox-specific tests into their own Java package (#621)
1 parent 6a125c3 commit f5cc10a

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

src/test/java/com/fasterxml/jackson/dataformat/xml/stream/dos/DeepNestingParserTest.java

-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.fasterxml.jackson.dataformat.xml.stream.dos;
22

3-
import com.ctc.wstx.stax.WstxInputFactory;
4-
53
import com.fasterxml.jackson.core.JsonParser;
64
import com.fasterxml.jackson.core.exc.StreamReadException;
75

@@ -22,17 +20,6 @@ public void testDeepDoc() throws Exception
2220
}
2321
}
2422

25-
public void testDeepDocWithCustomDepthLimit() throws Exception
26-
{
27-
final WstxInputFactory wstxInputFactory = new WstxInputFactory();
28-
wstxInputFactory.getConfig().setMaxElementDepth(2000);
29-
final XmlMapper xmlMapper = new XmlMapper(wstxInputFactory);
30-
final String XML = createDeepNestedDoc(1050);
31-
try (JsonParser p = xmlMapper.createParser(XML)) {
32-
while (p.nextToken() != null) { }
33-
}
34-
}
35-
3623
private String createDeepNestedDoc(final int depth) {
3724
StringBuilder sb = new StringBuilder();
3825
sb.append("<root>");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.fasterxml.jackson.dataformat.xml.woodstox;
2+
3+
import com.ctc.wstx.stax.WstxInputFactory;
4+
5+
import com.fasterxml.jackson.core.JsonParser;
6+
7+
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
8+
import com.fasterxml.jackson.dataformat.xml.XmlTestBase;
9+
10+
public class DeepNestingWoodstoxParserTest extends XmlTestBase
11+
{
12+
// Try using Woodstox-specific settings above and beyond
13+
// what Jackson-core would provide
14+
public void testDeepDocWithWoodstoxLimits() throws Exception
15+
{
16+
final WstxInputFactory wstxInputFactory = new WstxInputFactory();
17+
wstxInputFactory.getConfig().setMaxElementDepth(2000);
18+
final XmlMapper xmlMapper = new XmlMapper(wstxInputFactory);
19+
final String XML = createDeepNestedDoc(1050);
20+
try (JsonParser p = xmlMapper.createParser(XML)) {
21+
while (p.nextToken() != null) { }
22+
}
23+
}
24+
25+
private String createDeepNestedDoc(final int depth) {
26+
StringBuilder sb = new StringBuilder();
27+
sb.append("<root>");
28+
for (int i = 0; i < depth; i++) {
29+
sb.append("<leaf>");
30+
}
31+
sb.append("abc");
32+
for (int i = 0; i < depth; i++) {
33+
sb.append("</leaf>");
34+
}
35+
sb.append("</root>");
36+
return sb.toString();
37+
}
38+
}

src/test/java/com/fasterxml/jackson/dataformat/xml/deser/NonNamespaceAwareDeser422Test.java renamed to src/test/java/com/fasterxml/jackson/dataformat/xml/woodstox/NonNamespaceAwareDeser422Test.java

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
package com.fasterxml.jackson.dataformat.xml.deser;
1+
package com.fasterxml.jackson.dataformat.xml.woodstox;
22

33
import java.util.List;
44

55
import javax.xml.stream.XMLInputFactory;
66

7-
import com.ctc.wstx.stax.WstxInputFactory;
8-
97
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
108

119
import com.fasterxml.jackson.dataformat.xml.XmlFactory;
@@ -14,7 +12,9 @@
1412
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
1513
import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
1614

17-
// [dataformat-xml#422]
15+
// [dataformat-xml#422]: while setting itself is NOT Woodstox-specific,
16+
// many/most Stax implementations do not offer non-namespace-aware mode
17+
// so let's separate this into Woodstox-specific section
1818
public class NonNamespaceAwareDeser422Test extends XmlTestBase
1919
{
2020
// [dataformat-xml#422]
@@ -55,7 +55,7 @@ static class RssItem {
5555

5656
public void testBigDocIssue422() throws Exception
5757
{
58-
final XMLInputFactory xmlInputFactory = new WstxInputFactory();
58+
final XMLInputFactory xmlInputFactory = XMLInputFactory.newInstance();
5959
xmlInputFactory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
6060
final XmlMapper xmlMapper = XmlMapper.builder(XmlFactory.builder()
6161
.xmlInputFactory(xmlInputFactory)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* Package that contains <a href="https://github.com/FasterXML/woodstox/">Woodstox</a>
3+
* - specific tests, distinct from general Stax-backed tests.
4+
*
5+
* @since 2.17
6+
*/
7+
package com.fasterxml.jackson.dataformat.xml.woodstox;

0 commit comments

Comments
 (0)