63
64 //One iteration of xml transformation test case. It will be called from each
65 //TestWorker task defined in WarningsTestBase class.
66 void doOneTestIteration() throws Exception {
67 // Prepare output stream
68 StringWriter xmlResultString = new StringWriter();
69 StreamResult xmlResultStream = new StreamResult(xmlResultString);
70 // Prepare xml source stream
71 Source src = new StreamSource(new StringReader(xml));
72 Transformer t = createTransformer();
73 //Transform the xml
74 t.transform(src, xmlResultStream);
75 }
76
77 //Create transformer from xsl test string
78 Transformer createTransformer() throws Exception {
79 // Prepare sources for transormation
80 Source xslsrc = new StreamSource(new StringReader(xsl));
81
82 // Create factory and transformer
83 TransformerFactory tf = TransformerFactory.newInstance();
84 Transformer t = tf.newTransformer(xslsrc);
85
86 // Set URI Resolver to return the newly constructed xml
87 // stream source object from xml test string
88 t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
89 return t;
90 }
91
92 //Xsl and Xml contents used in the transformation test
93 private static final String xsl = "<xsl:stylesheet version='2.0'"
94 + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
95 + " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
96 + " <xsl:template match='/'>"
97 + " <test>Simple Transformation Result. No warnings should be printed to console</test>"
98 + " </xsl:template>"
99 + "</xsl:stylesheet>";
100 private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
101 }
102
|
63
64 //One iteration of xml transformation test case. It will be called from each
65 //TestWorker task defined in WarningsTestBase class.
66 void doOneTestIteration() throws Exception {
67 // Prepare output stream
68 StringWriter xmlResultString = new StringWriter();
69 StreamResult xmlResultStream = new StreamResult(xmlResultString);
70 // Prepare xml source stream
71 Source src = new StreamSource(new StringReader(xml));
72 Transformer t = createTransformer();
73 //Transform the xml
74 t.transform(src, xmlResultStream);
75 }
76
77 //Create transformer from xsl test string
78 Transformer createTransformer() throws Exception {
79 // Prepare sources for transormation
80 Source xslsrc = new StreamSource(new StringReader(xsl));
81
82 // Create factory and transformer
83 TransformerFactory tf;
84 // newTransformer() method doc states that different transformer
85 // factories can be used concurrently by different Threads.
86 synchronized (TransformerFactory.class) {
87 tf = TransformerFactory.newInstance();
88 }
89 Transformer t = tf.newTransformer(xslsrc);
90
91 // Set URI Resolver to return the newly constructed xml
92 // stream source object from xml test string
93 t.setURIResolver((String href, String base) -> new StreamSource(new StringReader(xml)));
94 return t;
95 }
96
97 //Xsl and Xml contents used in the transformation test
98 private static final String xsl = "<xsl:stylesheet version='2.0'"
99 + " xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>"
100 + " <xsl:output method='xml' indent='yes' omit-xml-declaration='yes'/>"
101 + " <xsl:template match='/'>"
102 + " <test>Simple Transformation Result. No warnings should be printed to console</test>"
103 + " </xsl:template>"
104 + "</xsl:stylesheet>";
105 private static final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><root></root>";
106 }
107
|