doc.setContent(module6);
((EXistResource) doc).setMimeType("application/xquery");
testCollection.storeResource(doc);
System.out.println("testGlobalVars 1: ========");
XQueryService service = (XQueryService) testCollection.getService("XPathQueryService", "1.0");
String query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE5_NAME + "\";\n" + "$foo:bar";
ResourceSet result = service.query(query);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "bar");
System.out.println("testGlobalVars 2: ========");
query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "$local:a";
result = service.query(query);
assertEquals(result.getSize(), 1);
assertEquals(result.getResource(0).getContent(), "abc");
System.out.println("testGlobalVars 3: ========");
boolean gotException = false;
try {
query = "xquery version \"1.0\";\n" + "import module namespace foo=\"foo\" at \"" + URI + "/test/" + MODULE6_NAME + "\";\n" + "$foo:bar";
result = service.query(query);
} catch (XMLDBException e) {
assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
gotException = true;
}
assertTrue("Duplicate global variable should generate error", gotException);
System.out.println("testGlobalVars 4: ========");
gotException = false;
try {
query = "xquery version \"1.0\";\n" + "declare variable $local:a := 'abc';" + "declare variable $local:a := 'abc';" + "$local:a";
result = service.query(query);
} catch (XMLDBException e) {
assertTrue("Test should generate err:XQST0049, got: " + e.getMessage(), e.getMessage().indexOf("err:XQST0049") > -1);
gotException = true;
}
assertTrue("Duplicate global variable should generate error", gotException);