Set<String> extectedError = new HashSet<String>();
try {
broker = db.get(db.getSecurityManager().getSystemSubject());
xquery = broker.getXQueryService();
final XQueryContext context = new XQueryContext(db, AccessContext.TEST);
broker.getConfiguration().setProperty(XQueryContext.PROPERTY_XQUERY_RAISE_ERROR_ON_FAILED_RETRIEVAL, true);
String query = "declare namespace qt='" + QT_NS + "';\n" + "let $testCases := xmldb:document('/db/QT3/" + file + "')\n"
+ "let $tc := $testCases//qt:test-case[@name eq \"" + tcName + "\"]\n" + "return $tc";
XQuery xqs = broker.getXQueryService();
Sequence results = xqs.execute(query, null, AccessContext.TEST);
Assert.assertFalse("", results.isEmpty());
ElementImpl TC = (ElementImpl) results.toNodeSet().get(0).getNode();
Sequence contextSequence = null;
NodeList expected = null;
String nodeName = "";
// compile & evaluate
String caseScript = null;
List<String> staticDocs = new ArrayList<String>();
NodeList childNodes = TC.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node child = childNodes.item(i);
switch (child.getNodeType()) {
case Node.ATTRIBUTE_NODE:
// String name = ((Attr)child).getName();
// if (name.equals("scenario"))
// scenario = ((Attr)child).getValue();
break;
case Node.ELEMENT_NODE:
nodeName = ((ElementImpl) child).getLocalName();
if (nodeName.equals("test")) {
ElementImpl el = ((ElementImpl) child);
caseScript = el.getNodeValue();
} else if (nodeName.equals("environment")) {
ElementImpl el = ((ElementImpl) child);
String ref = el.getAttribute("ref");
if (!(ref == null || "empty".equals(ref) || ref.isEmpty())) {
Assert.assertNull(contextSequence);
String contextDoc = getEnviroment(file, ref);
staticDocs.add(contextDoc);
} else {
NodeList _childNodes = el.getChildNodes();
for (int j = 0; j < _childNodes.getLength(); j++) {
Node _child = _childNodes.item(j);
switch (_child.getNodeType()) {
case Node.ELEMENT_NODE:
nodeName = ((ElementImpl) _child).getLocalName();
if (nodeName.equals("param")) {
el = ((ElementImpl) _child);
Variable var = new VariableImpl(QName.parse(context, el.getAttribute("name")));
String type = el.getAttribute("as");
if ("xs:date".equals(type)) {
var.setStaticType(Type.DATE);
Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
Assert.assertEquals(1, res.getItemCount());
var.setValue(res);
} else if ("xs:dateTime".equals(type)) {
var.setStaticType(Type.DATE_TIME);
Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
Assert.assertEquals(1, res.getItemCount());
var.setValue(res);
} else if ("xs:string".equals(type)) {
var.setStaticType(Type.STRING);
Sequence res = xquery.execute(el.getAttribute("select"), null, AccessContext.TEST);
Assert.assertEquals(1, res.getItemCount());
var.setValue(res);
} else {
Assert.fail("unknown type '" + type + "'");
}
context.declareGlobalVariable(var);
}
}
}
}
} else if (nodeName.equals("result")) {
ElementImpl el = ((ElementImpl) child);
possibleErrors(el, extectedError);
NodeList anyOf = el.getElementsByTagNameNS(QT_NS, "any-of");
for (int j = 0; j < anyOf.getLength(); j++) {
el = (ElementImpl) anyOf.item(j);
possibleErrors(el, extectedError);
}
expected = el.getChildNodes();
}
break;
default:
;
}
}
if (staticDocs.size() > 0) {
XmldbURI contextDocs[] = new XmldbURI[staticDocs.size()];
int i = 0;
for (String path : staticDocs) {
contextDocs[i++] = XmldbURI.createInternal(path);
}
context.setStaticallyKnownDocuments(contextDocs);
}
final CompiledXQuery compiled = xquery.compile(context, xquery3declaration + caseScript);
result = xquery.execute(compiled, contextSequence);
for (int i = 0; i < expected.getLength(); i++) {