String query = "declare namespace catalog=\"http://www.w3.org/2005/02/query-test-XQTSCatalog\";\n"+
"let $XQTSCatalog := xmldb:document('/db/XQTS/XQTSCatalog.xml')\n"+
"let $tc := $XQTSCatalog/catalog:test-suite//catalog:test-group[@name eq \""+testGroup+"\"]/catalog:test-case[@name eq \""+testCase+"\"]\n"+
"return $tc";
Sequence results = xquery.execute(query, null, AccessContext.TEST);
Assert.assertFalse("", !results.hasOne());
ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode();
//collect test case information
String folder = "";
String scenario = "";
String script = "";
//DateTimeValue scriptDateTime = null;
NodeListImpl inputFiles = new NodeListImpl();
NodeListImpl outputFiles = new NodeListImpl();
ElementImpl contextItem = null;
NodeListImpl modules = new NodeListImpl();
String expectedError = "";
String name = null;
NodeList childNodes = TC.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
switch (child.getNodeType()) {
case Node.ATTRIBUTE_NODE:
name = ((Attr)child).getName();
if (name.equals("FilePath"))
folder = ((Attr)child).getValue();
else if (name.equals("scenario"))
scenario = ((Attr)child).getValue();
break;
case Node.ELEMENT_NODE:
name = ((ElementImpl) child).getLocalName();
if (name.equals("query")) {
ElementImpl el = ((ElementImpl) child);
script = el.getAttribute("name");
//scriptDateTime = new DateTimeValue(el.getAttribute("date"));
}
else if (name.equals("input-file"))
inputFiles.add(child);
else if (name.equals("output-file"))
outputFiles.add(child);
else if (name.equals("contextItem"))
contextItem = (ElementImpl)child;
else if (name.equals("module"))
modules.add(child);
else if (name.equals("expected-error"))
expectedError = ((ElementImpl) child).getNodeValue();
break;
default :
;
}
}
Sequence result = null;
//compile & evaluate
File caseScript = new File(XQTS_folder+"Queries/XQuery/"+folder, script+".xq");
try {
XQueryContext context;
context = xquery.newContext(AccessContext.TEST);
//map modules' namespaces to location
Map<String, String> moduleMap = (Map<String, String>)broker.getConfiguration().getProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP);
for (int i = 0; i < modules.getLength(); i++) {
ElementImpl module = (ElementImpl)modules.item(i);
String id = module.getNodeValue();
moduleMap.put(module.getAttribute("namespace"), moduleSources.get(id));
}
broker.getConfiguration().setProperty(XQueryContext.PROPERTY_STATIC_MODULE_MAP, moduleMap);
//declare variable
for (int i = 0; i < inputFiles.getLength(); i++) {
ElementImpl inputFile = (ElementImpl)inputFiles.item(i);
String id = inputFile.getNodeValue();
//use DocUtils
//context.declareVariable(
//inputFile.getAttribute("variable"),
//DocUtils.getDocument(context, sources.get(id))
//);
//in-memory nodes
context.declareVariable(inputFile.getAttribute("variable"), loadVarFromURI(context, sources.get(id)));
}
Sequence contextSequence = null;
//set context item
if (contextItem != null) {
String id = contextItem.getNodeValue();
contextSequence = loadVarFromURI(context, sources.get(id));
}