Search in sources :

Example 66 with ResourceSet

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);
    }
}
Also used : ArrayList(java.util.ArrayList) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 67 with ResourceSet

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);
}
Also used : Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 68 with ResourceSet

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();
    }
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) Collection(org.xmldb.api.base.Collection) ResourceSet(org.xmldb.api.base.ResourceSet) CompiledExpression(org.xmldb.api.base.CompiledExpression)

Example 69 with ResourceSet

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());
}
Also used : LocalXMLResource(org.exist.xmldb.LocalXMLResource) Diff(org.xmlunit.diff.Diff) Node(org.w3c.dom.Node) ResourceSet(org.xmldb.api.base.ResourceSet)

Example 70 with ResourceSet

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());
}
Also used : XQueryService(org.xmldb.api.modules.XQueryService) ResourceSet(org.xmldb.api.base.ResourceSet) Test(org.junit.Test)

Aggregations

ResourceSet (org.xmldb.api.base.ResourceSet)383 XPathQueryService (org.xmldb.api.modules.XPathQueryService)123 Test (org.junit.Test)117 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)100 XMLResource (org.xmldb.api.modules.XMLResource)80 Collection (org.xmldb.api.base.Collection)55 Resource (org.xmldb.api.base.Resource)45 XQueryService (org.xmldb.api.modules.XQueryService)29 XMLDBException (org.xmldb.api.base.XMLDBException)23 EXistResource (org.exist.xmldb.EXistResource)20 BinaryResource (org.xmldb.api.modules.BinaryResource)17 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 Node (org.w3c.dom.Node)11 IndexQueryService (org.exist.xmldb.IndexQueryService)9 Diff (org.xmlunit.diff.Diff)9 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)8 UserManagementService (org.exist.xmldb.UserManagementService)8 Source (javax.xml.transform.Source)7 ResourceIterator (org.xmldb.api.base.ResourceIterator)7 XUpdateQueryService (org.xmldb.api.modules.XUpdateQueryService)6