Project

Profile

Help

Bug #2634 » TestSaxonStreamFallback.java

TestNG test reproducing "No watch found for xsl:element" - Gunther Rademacher, 2016-02-22 14:49

 
import java.io.ByteArrayInputStream;

import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;

import org.testng.Assert;
import org.testng.annotations.Test;

import com.saxonica.config.EnterpriseConfiguration;

import net.sf.saxon.Configuration;
import net.sf.saxon.lib.FeatureKeys;
import net.sf.saxon.lib.StandardURIResolver;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.XQueryCompiler;
import net.sf.saxon.s9api.XQueryEvaluator;
import net.sf.saxon.s9api.XQueryExecutable;
import net.sf.saxon.s9api.XdmItem;
import net.sf.saxon.trans.XPathException;

public class TestSaxonStreamFallback {

@Test
public void testSaxonStreamingFallback() throws SaxonApiException {
Configuration configuration = new EnterpriseConfiguration();
configuration.setBooleanProperty(FeatureKeys.STREAMING_FALLBACK, true);
Assert.assertTrue(configuration.getBooleanProperty(FeatureKeys.STREAMING_FALLBACK));
Assert.assertTrue(configuration.getBooleanProperty(FeatureKeys.GENERATE_BYTE_CODE));
Assert.assertEquals(configuration.getConfigurationProperty(FeatureKeys.OPTIMIZATION_LEVEL), "10");
Processor processor = new Processor(configuration);
XQueryCompiler xqueryCompiler = processor.newXQueryCompiler();
String query = "for $x in saxon:stream(doc('uriresolver:resolve')/*/*/element {node-name()} {node()}) return $x";
XQueryExecutable xqueryExecutable = xqueryCompiler.compile(query);
long count = 0;
XQueryEvaluator xqueryEvaluator = xqueryExecutable.load();
xqueryEvaluator.setURIResolver(new StandardURIResolver() {
@Override
public Source resolve(String href, String base) throws XPathException {
return new StreamSource(new ByteArrayInputStream((
"<xml>" +
" <row><name>A</name><value>1</value></row>" +
" <row><name>B</name><value>2</value></row>" +
" <row><name>C</name><value>3</value></row>" +
"</xml>"
).getBytes()));
}
});
try {
for (XdmItem xdmItem : xqueryEvaluator)
++count;
}
finally {
xqueryEvaluator.close();
}
Assert.assertEquals(count, 3);
}

}
(1-1/2)