|
From: <et...@us...> - 2011-09-27 18:08:51
|
Revision: 4452
http://mxquery.svn.sourceforge.net/mxquery/?rev=4452&view=rev
Author: etterth
Date: 2011-09-27 18:08:45 +0000 (Tue, 27 Sep 2011)
Log Message:
-----------
- Changed test infrastructure to support XQUTS
Modified Paths:
--------------
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/JsXQueryTestCase.java
trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/TestResourceManager.java
trunk/XQIB_Testing/XQUTStoJsUnit.xsl
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/JsXQueryTestCase.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/JsXQueryTestCase.java 2011-09-26 17:24:02 UTC (rev 4451)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/JsXQueryTestCase.java 2011-09-27 18:08:45 UTC (rev 4452)
@@ -4,7 +4,6 @@
import java.util.Vector;
import com.google.gwt.xml.client.XMLParser;
-import com.google.gwt.xml.client.Document;
import ch.ethz.mxquery.contextConfig.CompilerOptions;
import ch.ethz.mxquery.contextConfig.Context;
@@ -13,10 +12,13 @@
import ch.ethz.mxquery.exceptions.MXQueryException;
import ch.ethz.mxquery.exceptions.QueryLocation;
import ch.ethz.mxquery.iterators.TokenIterator;
+import ch.ethz.mxquery.iterators.browser.NodeStoreIterator;
import ch.ethz.mxquery.model.XDMIterator;
import ch.ethz.mxquery.query.PreparedStatement;
import ch.ethz.mxquery.query.XQCompiler;
import ch.ethz.mxquery.query.impl.CompilerImpl;
+import ch.ethz.mxquery.util.Hashtable;
+import ch.ethz.mxquery.util.browser.dom.Document;
import ch.ethz.mxquery.xdmio.XDMSerializer;
import ch.ethz.mxquery.xdmio.XDMSerializerSettings;
import ch.ethz.mxquery.xdmio.xmlAdapters.NonValidatingDOMAdapter;
@@ -50,6 +52,7 @@
// }
private String query;
private String errorcode;
+ private Vector<VariableWithUri> reuseVariables;
public static JsXQueryTestCase create(String query) {
return new JsXQueryTestCase(query);
@@ -62,6 +65,7 @@
private static native void n_setup(JsXQueryTestCase o) /*-{
o.addVariable = o....@ch....JsXQueryTestCase::addVariable(Ljava/lang/String;Ljava/lang/String;);
+ o.reuseVariable = o....@ch....JsXQueryTestCase::reuseVariable(Ljava/lang/String;Ljava/lang/String;);
o.addModuleLocation = o....@ch....JsXQueryTestCase::addModuleLocation(Ljava/lang/String;Ljava/lang/String;);
o.execute = o....@ch....JsXQueryTestCase::execute();
o.getResult = o....@ch....JsXQueryTestCase::getResult();
@@ -85,6 +89,12 @@
public void addVariable(String name, String xml) {
variables.add(new VariableWithUri(name, xml, false));
}
+
+ public void reuseVariable(String name, String xml) {
+ reuseVariables.add(new VariableWithUri(name, xml, false));
+ }
+ protected Hashtable<String, Document>
+ variableCache = new Hashtable<String, Document>();
public void execute() throws Exception {
XQCompiler comp = new CompilerImpl();
@@ -101,20 +111,34 @@
stat = comp.compile(ctx, query,co,null,null);
for (VariableWithUri var:variables){
-
+ Document xmldoc = TestResourceManager.getFile(var.uri);
//variables pass the fileid in the xml field
if (var.name.equals(Context.CONTEXT_ITEM.toString())) {
- com.google.gwt.xml.client.Document xmldoc = XMLParser.parse(var.uri);
- NonValidatingDOMAdapter resource = new NonValidatingDOMAdapter((Context)stat.getContext(), QueryLocation.OUTSIDE_QUERY_LOC, xmldoc);
+
+ NodeStoreIterator resource = new NodeStoreIterator(xmldoc);
stat.setContextItem(resource);
+ variableCache.put(var.uri, xmldoc);
}
else {
- System.out.println("useslow");
- stat.addExternalResource(new QName(var.name), TestResourceManager.getFile(var.uri));
+ stat.addExternalResource(new QName(var.name), new NodeStoreIterator(xmldoc));
+ variableCache.put(var.uri, xmldoc);
+ }
+ }
+ for (VariableWithUri var:reuseVariables){
+ Document xmldoc = variableCache.get(var.uri);
+ //variables pass the fileid in the xml field
+ if (var.name.equals(Context.CONTEXT_ITEM.toString())) {
+ NodeStoreIterator resource = new NodeStoreIterator(xmldoc);
+ stat.setContextItem(resource);
}
+ else {
+
+ stat.addExternalResource(new QName(var.name), new NodeStoreIterator(xmldoc));
+ }
}
+
// // add external queries!
//
Modified: trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/TestResourceManager.java
===================================================================
--- trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/TestResourceManager.java 2011-09-26 17:24:02 UTC (rev 4451)
+++ trunk/MXQuery/xqib_src/ch/ethz/mxqjs/test/TestResourceManager.java 2011-09-27 18:08:45 UTC (rev 4452)
@@ -8,12 +8,11 @@
public class TestResourceManager {
- public static XDMIterator getFile(String uri) {
+ public static Document getFile(String uri) {
SyncXmlHttpRequestWrapper xhr = new SyncXmlHttpRequestWrapper();
xhr.setUrl(uri);
xhr.send();
- Document doc = xhr.responseAsXML();
- return new NodeStoreIterator(doc);
+ return xhr.responseAsXML();
}
}
Modified: trunk/XQIB_Testing/XQUTStoJsUnit.xsl
===================================================================
--- trunk/XQIB_Testing/XQUTStoJsUnit.xsl 2011-09-26 17:24:02 UTC (rev 4451)
+++ trunk/XQIB_Testing/XQUTStoJsUnit.xsl 2011-09-27 18:08:45 UTC (rev 4452)
@@ -167,6 +167,8 @@
String query;
XQueryTestCase testcase;
<xsl:for-each select="state">
+ <xsl:variable name="initialstate" select="empty(preceding-sibling::node()[local-name() = 'state'])"/>
+ //<xsl:value-of select="$initialstate"></xsl:value-of>
query = <xsl:call-template
name="getQuery"/>; <!-- module -->
testcase = new XQueryTestCase(driver,query); <xsl:for-each
@@ -187,8 +189,16 @@
"<xsl:call-template name="getVariable"/>", true);</xsl:when>
<xsl:otherwise>
- testcase.addVariable("<xsl:value-of select="./@variable"/>",
- "<xsl:call-template name="getVariable"/>", false);</xsl:otherwise>
+ <xsl:choose>
+
+ <xsl:when test="$initialstate">testcase.addVariable("<xsl:value-of select="./@variable"/>",
+ "<xsl:call-template name="getVariable"/>", false);</xsl:when>
+ <xsl:otherwise>
+ testcase.reuseVariable("<xsl:value-of select="./@variable"/>",
+ "<xsl:call-template name="getVariable"/>");
+ </xsl:otherwise>
+ </xsl:choose>
+ </xsl:otherwise>
</xsl:choose>
</xsl:for-each>
@@ -210,10 +220,10 @@
<xsl:otherwise>null</xsl:otherwise>
</xsl:choose>
</xsl:variable>
- do {
+ do {
+ boolean match = false;
<xsl:choose>
<xsl:when test="../@scenario = 'standard'">
- boolean match = false;
String[] expectedoutput = new String[]<xsl:call-template name="getOutput"/>;
String errorcode = testcase.getErrorCode();
if (errorcode != null){<xsl:for-each select="./expected-error">
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|