use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class SeqOpTest method assertSeq.
private void assertSeq(String[] expected, String q) throws XMLDBException {
ResourceSet rs = query.query(q);
assertEquals(expected.length, rs.getSize());
List<String> a = Arrays.asList(expected);
List<Object> r = new ArrayList<>((int) rs.getSize());
for (int i = 0; i < rs.getSize(); i++) {
r.add(rs.getResource(i).getContent());
}
if (!a.equals(r)) {
fail("expected " + a + ", got " + r);
}
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class StoredModuleTest method testRelativeImportDb.
@Test
public void testRelativeImportDb() throws Exception {
String collection2Name = "module2";
String collection3Name = "module2/module3";
String query = "import module namespace mod2 = 'urn:module2' " + "at 'xmldb:exist:/" + collection2Name + "/module2.xqm'; " + "mod2:showMe()";
Collection c2 = createCollection(collection2Name);
writeModule(c2, "module2.xqm", module2);
writeModule(c2, "module3.xqm", module3b);
writeModule(c2, "module4.xqm", module4);
Collection c3 = createCollection(collection3Name);
writeModule(c3, "module3.xqm", module3a);
// test relative module import in subfolder
ResourceSet rs = existEmbeddedServer.executeQuery(query);
String r = (String) rs.getResource(0).getContent();
assertEquals("hi from module 3a", r);
// test relative module import in same folder, and using ".."
writeModule(c2, "module2.xqm", module2b);
rs = existEmbeddedServer.executeQuery(query);
r = (String) rs.getResource(0).getContent();
assertEquals("hi from module 4", r);
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class StoredModuleTest method testQuery.
@Test
public void testQuery() throws Exception {
Collection c = createCollection("test");
writeModule(c, "test.xqm", MODULE);
String query = "import module namespace itg-modules = \"http://localhost:80/itg/xquery\" at " + "\"xmldb:exist://" + XmldbURI.ROOT_COLLECTION + "/test/test.xqm\"; itg-modules:check-coll()";
String[] cols = { "one", "two", "three" };
final XQueryService xqService = (XQueryService) existEmbeddedServer.getRoot().getService("XQueryService", "1.0");
xqService.setNamespace("itg-modules", "http://localhost:80/itg/xquery");
CompiledExpression compiledQuery = xqService.compile(query);
for (int i = 0; i < cols.length; i++) {
xqService.declareVariable("itg-modules:coll", cols[i]);
ResourceSet result = xqService.execute(compiledQuery);
result.getResource(0).getContent();
}
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class InternalModuleTest method moduleVariablesQuery.
private void moduleVariablesQuery(final EXistXQueryService queryService, final Source query, final long expectedCount) throws XMLDBException {
// this variation of execute will use the XQueryPool for caching
final ResourceSet result = queryService.execute(query);
assertNotNull(result);
assertEquals(1, result.getSize());
final LocalXMLResource resource = (LocalXMLResource) result.getResource(0);
assertNotNull(resource);
final Node actualDoc = resource.getContentAsDOM();
final javax.xml.transform.Source expected = Input.fromString("<variables><var1>" + expectedCount + "</var1></variables>").build();
final javax.xml.transform.Source actual = Input.fromNode(actualDoc).build();
final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
assertFalse(diff.toString(), diff.hasDifferences());
}
use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.
the class NamespaceUpdateTest method updateAttribute.
@Test
public void updateAttribute() throws XMLDBException {
XQueryService service = (XQueryService) testCollection.getService("XQueryService", "1.0");
String query = "declare namespace t='http://www.foo.com';\n" + "<test xmlns='http://www.foo.com'>\n" + "{\n" + " update insert attribute { 'ID' } { 'myid' } into /t:test\n" + "}\n" + "</test>";
service.query(query);
query = "declare namespace t='http://www.foo.com';\n" + "/t:test/@ID/string(.)";
ResourceSet result = service.query(query);
assertEquals(1, result.getSize());
assertEquals("myid", result.getResource(0).getContent().toString());
}
Aggregations