|
From: <et...@us...> - 2011-09-26 17:24:10
|
Revision: 4451
http://mxquery.svn.sourceforge.net/mxquery/?rev=4451&view=rev
Author: etterth
Date: 2011-09-26 17:24:02 +0000 (Mon, 26 Sep 2011)
Log Message:
-----------
- added XSLT for creation of update testsuite
Added Paths:
-----------
trunk/XQIB_Testing/XQUTStoJsUnit.xsl
Added: trunk/XQIB_Testing/XQUTStoJsUnit.xsl
===================================================================
--- trunk/XQIB_Testing/XQUTStoJsUnit.xsl (rev 0)
+++ trunk/XQIB_Testing/XQUTStoJsUnit.xsl 2011-09-26 17:24:02 UTC (rev 4451)
@@ -0,0 +1,255 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
+ xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" exclude-result-prefixes="xd" version="2.0"
+ xpath-default-namespace="http://www.w3.org/2005/02/query-test-update">
+ <xd:doc scope="stylesheet">
+ <xd:desc>
+ <xd:p><xd:b>Created on:</xd:b> Oct 27, 2010</xd:p>
+ <xd:p><xd:b>Author:</xd:b> To</xd:p>
+ <xd:p/>
+ </xd:desc>
+ </xd:doc>
+ <xsl:variable name="outputpath">upd-test/ch/ethz/mxquery</xsl:variable>
+ <xsl:variable name="packageprefix">ch.ethz.mxquery</xsl:variable>
+ <xsl:variable name="testsuitepath"
+ >xquts</xsl:variable>
+ <xsl:variable name="executionpath"
+ >http://127.0.0.1:8090/test/tests</xsl:variable>
+ <xsl:variable name="relativetestdir">http://127.0.0.1:8090/test/tests/</xsl:variable>
+ <xsl:template match="/">
+ <xsl:for-each select="test-suite/test-group">
+ <xsl:call-template name="test-group">
+ <xsl:with-param name="currentpath" select="$outputpath"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:template>
+ <xsl:template name="test-group">
+ <xsl:param name="currentpath"/>
+ <xsl:variable name="name">
+ <xsl:call-template name="getJavaString">
+ <xsl:with-param name="string" select="@name"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="./test-case">
+ <xsl:variable name="classname" select="concat($name, 'class')"></xsl:variable>
+ <xsl:result-document href="{$currentpath}/{$classname}.java" method="text">
+ <xsl:call-template name="createJava">
+ <xsl:with-param name="name" select="$classname"/>
+ </xsl:call-template>
+ </xsl:result-document>
+ </xsl:when>
+
+
+ </xsl:choose>
+ <xsl:for-each select="./test-group">
+ <xsl:call-template name="test-group">
+ <xsl:with-param name="currentpath"
+ select="concat($currentpath, '/' , $name)"/>
+ </xsl:call-template>
+ </xsl:for-each>
+ </xsl:template>
+
+ <xsl:template name="escapeandputintoquotations">
+ <xsl:param name="str"></xsl:param>
+ <xsl:variable name="escapebackslashes"
+ select="replace($str, '\\', '\\\\')"/>
+ <xsl:variable name="replacequots"
+ select="replace($escapebackslashes, '"', '\\"')"/>
+ <xsl:variable name="replaceRs" select="replace($replacequots, '
','')"/>
+ <!-- <xsl:variable name="replaceNewlines" select="replace($replaceRs, '
','\\n" + 
"')"/>-->
+ <xsl:variable name="replaceNewlines" select="replace($replaceRs,'
','\\n')"/>"<xsl:value-of select="$replaceNewlines" disable-output-escaping="yes"/>"</xsl:template>
+
+
+ <xsl:template name="getFileContentsAsString">
+ <xsl:param name="filepath"/>
+
+ <xsl:variable name="cleanfilepath" select="replace($filepath, '/+', '/')"/>
+
+ <xsl:variable name="justtext" select="unparsed-text($cleanfilepath)"/>
+ <xsl:variable name="escapedString">
+ <xsl:call-template name="escapeandputintoquotations">
+ <xsl:with-param name="str" select="$justtext"></xsl:with-param>
+ </xsl:call-template>
+ </xsl:variable>
+ <xsl:choose>
+ <xsl:when test="string-length($escapedString)> 60000">
+ new StringBuilder()
+ <xsl:analyze-string select="$justtext" regex="(.{{1,60000}})" flags="s">
+ <xsl:matching-substring
+ >.append(<xsl:call-template name="escapeandputintoquotations">
+ <xsl:with-param name="str" select="regex-group(1)"/>
+ </xsl:call-template>)
+ </xsl:matching-substring>
+
+ </xsl:analyze-string>
+ .toString()
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="$escapedString"></xsl:value-of>
+ </xsl:otherwise>
+ </xsl:choose>
+
+ </xsl:template>
+
+ <xsl:template name="getQuery">
+ <xsl:call-template name="getFileContentsAsString">
+ <xsl:with-param name="filepath">
+ <xsl:value-of
+ select="concat($testsuitepath, '/Queries/XQuery/',
+ ../@FilePath, '/', ./query/@name, '.xq')"
+ />
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+ <xsl:template name="resolveURI">
+ <xsl:value-of
+ select="concat(substring($testsuitepath,6), '/TestSources/', ./text(), '.xml')"/>
+ </xsl:template>
+ <xsl:template name="getInputQuery">
+ <xsl:call-template name="getFileContentsAsString">
+ <xsl:with-param name="filepath">
+ <xsl:value-of
+ select="concat($testsuitepath, '/Queries/XQuery/',
+ ./parent::node()/@FilePath, '/', ./@name, '.xq')"
+ />
+ </xsl:with-param>
+ </xsl:call-template>
+ </xsl:template>
+
+
+ <xsl:template name="getOutput"> {<xsl:variable name="filepath" select="../@FilePath"/>
+ <xsl:for-each select="./output-file"><xsl:call-template name="getFileContentsAsString">
+ <xsl:with-param name="filepath">
+ <xsl:value-of
+ select="concat($testsuitepath, '/ExpectedTestResults/',
+ $filepath, '/', ./text())"
+ />
+ </xsl:with-param>
+ </xsl:call-template><xsl:if test="position() != last()">, </xsl:if>
+ </xsl:for-each>} </xsl:template>
+
+ <xsl:template name="getVariable">
+ <xsl:variable name="varname" select="./text()"/>
+ <!--<xsl:call-template name="getFileContentsAsString">
+ <xsl:with-param name="filepath">-->
+ <xsl:value-of
+ select="concat($executionpath, '/',
+ //source[@ID = $varname]/@FileName)"
+ />
+ <!--</xsl:with-param>
+ </xsl:call-template>-->
+ </xsl:template>
+
+ <xsl:template name="getJavaString">
+ <xsl:param name="string"/>
+ <xsl:value-of select="replace(replace($string, ' ',''), '-','_')"/>
+ </xsl:template>
+ <xsl:template name="createJava">
+ <xsl:param name="name"/>
+ <xsl:variable name="currentTestGroup" select="."/>
+ package <xsl:value-of select="$packageprefix"/><xsl:for-each
+ select="ancestor::node()[local-name() = 'test-group']"><xsl:if test="not(. is $currentTestGroup)"
+ >.</xsl:if><xsl:call-template
+ name="getJavaString"><xsl:with-param name="string" select="./@name"
+ /></xsl:call-template></xsl:for-each>;
+ import org.junit.Test;
+ import ch.ethz.mxquery.testsuite.XQueryTestBase;
+ import ch.ethz.mxquery.testsuite.XQueryTestCase;
+ public class <xsl:value-of select="$name"/> extends XQueryTestBase{ <xsl:for-each
+ select="./test-case[@name != 'prolog-version-2']">
+ <xsl:variable name="casename"><xsl:call-template name="getJavaString"
+ ><xsl:with-param name="string" select="@name"
+ /></xsl:call-template></xsl:variable>
+ @Test
+ public void test_<xsl:value-of
+ select="$casename"/>() throws Exception{
+ String query;
+ XQueryTestCase testcase;
+ <xsl:for-each select="state">
+ query = <xsl:call-template
+ name="getQuery"/>; <!-- module -->
+ testcase = new XQueryTestCase(driver,query); <xsl:for-each
+ select="module"><xsl:variable name="currentmodule" select="."/>
+ testcase.addModuleLocation("<xsl:value-of select="./@namespace"
+ />", "<xsl:value-of
+ select="concat($relativetestdir, root(.)//module[@ID = $currentmodule/text()]/@FileName, '.xq')"/>"); </xsl:for-each>
+ <!-- input-file -->
+ <xsl:for-each select="input-file"><xsl:variable name="sourceid" select="text()"/>
+ <xsl:variable name="source" select="//source[@ID = $sourceid]"/>
+ <xsl:choose>
+ <xsl:when test="$source/@schema">
+ testcase.addSchemaMapping("<xsl:value-of
+ select="//schema[@ID = $source/@schema]/@uri"/>", "<xsl:value-of
+ select="concat($relativetestdir, //schema[@ID = $source/@schema]/@FileName)"
+ />");
+ testcase.addVariable("<xsl:value-of select="./@variable"/>",
+ "<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:for-each>
+ <!--PreparedStatement prep = prepareQuery(query, false,false,
+ false, false, false);<xsl:for-each select="input-file"><xsl:variable
+ name="sourceid" select="text()"/>
+ <xsl:variable name="source" select="//source[@ID = $sourceid]"/>
+ addVariable(prep,"<xsl:value-of select="./@variable"/>",
+ "<xsl:call-template name="getVariable"/>"); </xsl:for-each> -->
+ <xsl:for-each select="input-URI"> testcase.addInputURI("<xsl:value-of
+ select="./@variable"/>", "'<xsl:call-template name="resolveURI"/>'"); </xsl:for-each>
+ <xsl:for-each select="input-query">testcase.addInputQuery("<xsl:value-of
+ select="./@variable"/>", <xsl:call-template name="getInputQuery"/>);
+ </xsl:for-each>
+ testcase.execute();
+ <xsl:variable name="CompareType"><xsl:choose>
+ <xsl:when test="./output-file[1]/@compare">"<xsl:value-of
+ select="./output-file[1]/@compare"/>"</xsl:when>
+ <xsl:otherwise>null</xsl:otherwise>
+ </xsl:choose>
+ </xsl:variable>
+ do {
+ <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">
+ if (errorcode.equals("<xsl:value-of select="./text()">
+ </xsl:value-of>"))
+ match=true;
+ </xsl:for-each>
+ if (match)
+ break;
+ throw new AssertionError(errorcode + " was thrown\nwhile " + expectedoutput[0] + "was expected");
+ }
+ testcase.assertXMLEqual(<xsl:value-of select="$CompareType"/>, expectedoutput);
+ </xsl:when>
+ <xsl:when test="../@scenario=('runtime-error', 'parse-error')">
+ String errorcode = testcase.getErrorCode();
+ String[] errorcodes = {
+ <xsl:for-each select="./expected-error">
+ "<xsl:value-of select="text()"/>"
+ <xsl:if test="./following-sibling::expected-error">,</xsl:if>
+ </xsl:for-each>
+ };
+ if (errorcode == null)
+ throw new AssertionError("nothing was thrown\nwhile the error" + errorcodes[0] + "was expected");
+ for (String testcode:errorcodes){
+ if (errorcode.equals(testcode))
+ match=true;
+ }
+ if (match)
+ break;
+ throw new AssertionError(errorcode + " was thrown\nwhile the error" + errorcodes [0] + "was expected");
+ </xsl:when>
+ </xsl:choose>
+ } while (false);
+ </xsl:for-each>
+ };
+ </xsl:for-each>
+ }
+ </xsl:template>
+</xsl:stylesheet>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|