Search in sources :

Example 86 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method namespaceURI.

@Test
public void namespaceURI() throws XMLDBException {
    String query = "let $var := <a xmlns='aaa'/> " + "return " + "$var[fn:namespace-uri() = 'aaa']/fn:namespace-uri()";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    String r = (String) result.getResource(0).getContent();
    assertEquals("aaa", r);
    query = "for $a in <test><a xmlns=\"aaa\"><b><c/></b></a></test>//* " + "return namespace-uri($a)";
    result = existEmbeddedServer.executeQuery(query);
    assertEquals(result.getSize(), 3);
    r = (String) result.getResource(0).getContent();
    assertEquals("aaa", r);
    r = (String) result.getResource(1).getContent();
    assertEquals("aaa", r);
    r = (String) result.getResource(2).getContent();
    assertEquals("aaa", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 87 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method floor.

@Test
public void floor() throws XMLDBException {
    String query = "let $a := <a><b>-1</b><b>-2</b></a> " + "return $a/b[abs(floor(.))]";
    ResourceSet result = existEmbeddedServer.executeQuery(query);
    assertEquals(2, result.getSize());
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 88 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method name_empty.

@Test
public void name_empty() throws XPathException, XMLDBException {
    final ResourceSet result = existEmbeddedServer.executeQuery("fn:name(())");
    final String r = (String) result.getResource(0).getContent();
    assertEquals("", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 89 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class XQueryFunctionsTest method secondsFromDateTime.

/**
 * Bugfix 3070
 *
 * @see http://svn.sourceforge.net/exist/?rev=3070&view=rev
 *
 * seconds-from-dateTime() returned wrong value when dateTime had
 * no millesecs available. Special value was returned.
 */
@Test
public void secondsFromDateTime() throws XMLDBException {
    ResourceSet result = existEmbeddedServer.executeQuery("seconds-from-dateTime(xs:dateTime(\"2005-12-22T13:35:21.000\") )");
    String r = (String) result.getResource(0).getContent();
    assertEquals("21", r);
    result = existEmbeddedServer.executeQuery("seconds-from-dateTime(xs:dateTime(\"2005-12-22T13:35:21\") )");
    r = (String) result.getResource(0).getContent();
    assertEquals("21", r);
}
Also used : ResourceSet(org.xmldb.api.base.ResourceSet)

Example 90 with ResourceSet

use of org.xmldb.api.base.ResourceSet in project exist by eXist-db.

the class BackupRestoreSecurityPrincipalsTest method restoreConflictingUsername.

/**
 * 1. With an empty database we create three
 *    users: 'frank', 'joe', and 'jack'.
 *
 * 2. We create a backup of the database which contains
 *    the three users from (1).
 *
 * 3. We destroy the database, restart the server,
 *    and start again with a clean database.
 *
 * 4. With an (again) empty database we create two
 *    users: 'frank', and 'jack'.
 *
 * 5. We then try and restore the database backup from (2), which
 *    contains the original 'frank', 'joe', and 'jack' users.
 *
 * frank will have the same username and user id in the current
 * database and the backup we are trying to restore.
 *
 * joe does not exist in the current database, but his user id
 * in the backup will collide with that of jack in the current database.
 *
 * jack will have a different user id in the backup when compared to the current
 * database, however he will have the same username.
 *
 * We want to make sure that after the restore, all three users are present
 * that they have distinct and expected user ids and that any resources
 * that were owned by them are still correctly owner by them (and not some other user).
 */
@Test
public void restoreConflictingUsername() throws PermissionDeniedException, EXistException, SAXException, ParserConfigurationException, IOException, URISyntaxException, XMLDBException, IllegalAccessException, ClassNotFoundException, InstantiationException {
    // creates a database with new users: 'frank(id=11)', 'joe(id=12)', and 'jack(id=13)'
    createInitialUsers(FRANK_USER, JOE_USER, JACK_USER);
    // create a backup of the database (which has the initial users)
    final Path backupFile = backupDatabase();
    // reset database to empty
    server.restart(true);
    // create new users: 'frank(id=11)' and 'jack(id=12)'
    createInitialUsers(FRANK_USER, JACK_USER);
    final String accountQuery = "declare namespace c = 'http://exist-db.org/Configuration';\n" + "for $account in //c:account\n" + "return\n" + "<user id='{$account/@id}' name='{$account/c:name}'/>";
    final XPathQueryService xqs = (XPathQueryService) server.getRoot().getService("XPathQueryService", "1.0");
    final SecurityManagerImpl sm = (SecurityManagerImpl) BrokerPool.getInstance().getSecurityManager();
    // check the current user accounts
    ResourceSet result = xqs.query(accountQuery);
    assertUser(RealmImpl.ADMIN_ACCOUNT_ID, SecurityManager.DBA_USER, ((XMLResource) result.getResource(0)).getContentAsDOM());
    assertUser(RealmImpl.GUEST_ACCOUNT_ID, SecurityManager.GUEST_USER, ((XMLResource) result.getResource(1)).getContentAsDOM());
    assertUser(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 1, "frank", ((XMLResource) result.getResource(2)).getContentAsDOM());
    assertUser(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 2, "jack", ((XMLResource) result.getResource(3)).getContentAsDOM());
    // check the last user id
    // last account id should be that of 'jack'
    assertEquals(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 2, sm.getLastAccountId());
    // create a test collection and give everyone access
    final CollectionManagementService cms = (CollectionManagementService) server.getRoot().getService("CollectionManagementService", "1.0");
    final Collection test = cms.createCollection("test");
    final UserManagementService testUms = (UserManagementService) test.getService("UserManagementService", "1.0");
    testUms.chmod("rwxrwxrwx");
    // create and store a new document as 'frank'
    final Collection frankTest = DatabaseManager.getCollection("xmldb:exist:///db/test", FRANK_USER, FRANK_USER);
    final String FRANKS_DOCUMENT = "franks-document.xml";
    final Resource frankDoc = frankTest.createResource(FRANKS_DOCUMENT, XMLResource.RESOURCE_TYPE);
    frankDoc.setContent("<hello>frank</hello>");
    frankTest.storeResource(frankDoc);
    // create and store a new document as 'jack'
    final Collection jackTest = DatabaseManager.getCollection("xmldb:exist:///db/test", JACK_USER, JACK_USER);
    final String JACKS_DOCUMENT = "jacks-document.xml";
    final Resource jackDoc = jackTest.createResource(JACKS_DOCUMENT, XMLResource.RESOURCE_TYPE);
    jackDoc.setContent("<hello>jack</hello>");
    jackTest.storeResource(jackDoc);
    // restore the database backup
    final EXistRestoreService service = (EXistRestoreService) server.getRoot().getService("RestoreService", "1.0");
    service.restore(backupFile.normalize().toAbsolutePath().toString(), null, new NullRestoreServiceTaskListener(), false);
    // check the current user accounts after the restore
    result = xqs.query(accountQuery);
    assertUser(RealmImpl.ADMIN_ACCOUNT_ID, SecurityManager.DBA_USER, ((XMLResource) result.getResource(0)).getContentAsDOM());
    assertUser(RealmImpl.GUEST_ACCOUNT_ID, SecurityManager.GUEST_USER, ((XMLResource) result.getResource(1)).getContentAsDOM());
    assertUser(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 1, FRANK_USER, ((XMLResource) result.getResource(2)).getContentAsDOM());
    assertUser(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 2, JACK_USER, ((XMLResource) result.getResource(3)).getContentAsDOM());
    assertUser(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 3, JOE_USER, ((XMLResource) result.getResource(4)).getContentAsDOM());
    // check the last user id after the restore
    // last account id should be that of 'joe'
    assertEquals(SecurityManagerImpl.INITIAL_LAST_ACCOUNT_ID + 3, sm.getLastAccountId());
    // check the owner of frank's document after restore
    final Resource fDoc = test.getResource(FRANKS_DOCUMENT);
    final Permission franksDocPermissions = testUms.getPermissions(fDoc);
    assertEquals(FRANK_USER, franksDocPermissions.getOwner().getName());
    // check the owner of jack's document after restore
    final Resource jDoc = test.getResource(JACKS_DOCUMENT);
    final Permission jacksDocPermissions = testUms.getPermissions(jDoc);
    assertEquals(JACK_USER, jacksDocPermissions.getOwner().getName());
}
Also used : Path(java.nio.file.Path) CollectionManagementService(org.xmldb.api.modules.CollectionManagementService) EXistRestoreService(org.exist.xmldb.EXistRestoreService) XPathQueryService(org.xmldb.api.modules.XPathQueryService) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) NullRestoreServiceTaskListener(org.exist.xmldb.NullRestoreServiceTaskListener) Collection(org.xmldb.api.base.Collection) UserManagementService(org.exist.xmldb.UserManagementService) ResourceSet(org.xmldb.api.base.ResourceSet)

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