Search in sources :

Example 41 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class TransformTest method xslDocument.

@Ignore("https://github.com/eXist-db/exist/issues/2096")
@Test
public void xslDocument() throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final XQuery xquery = pool.getXQueryService();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()))) {
        final Sequence sequence = xquery.execute(broker, DOCUMENT_XSLT_QUERY, null);
        assertNotNull(sequence);
        assertTrue(sequence.hasOne());
        final Item item = sequence.itemAt(0);
        assertEquals(Type.DOCUMENT, item.getType());
        final Source expected = Input.fromString("<elem1/>").build();
        final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Document.class)).build();
        final Diff diff = DiffBuilder.compare(actual).withTest(expected).checkForSimilar().build();
        assertFalse(diff.toString(), diff.hasDifferences());
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) Diff(org.xmlunit.diff.Diff) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source)

Example 42 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class GroupMembershipFunctionRemoveGroupMemberTest method setup.

@Before
public void setup() throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    // create user with personal group as primary group
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = createUser(broker, sm, USER1_NAME, USER1_PWD);
        final Group otherGroup1 = createGroup(broker, sm, OTHER_GROUP1_NAME);
        addUserToGroup(sm, user1, otherGroup1);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP1_NAME);
        final Group otherGroup2 = createGroup(broker, sm, OTHER_GROUP2_NAME);
        addUserToGroup(sm, user1, otherGroup2);
        addUserAsGroupManager(USER1_NAME, OTHER_GROUP2_NAME);
        transaction.commit();
    }
    // check that the user is as we expect
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        final Account user1 = sm.getAccount(USER1_NAME);
        assertEquals(USER1_NAME, user1.getPrimaryGroup());
        final String[] user1Groups = user1.getGroups();
        assertArrayEquals(new String[] { USER1_NAME, OTHER_GROUP1_NAME, OTHER_GROUP2_NAME }, user1Groups);
        for (final String user1Group : user1Groups) {
            assertNotNull(sm.getGroup(user1Group));
        }
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool) Before(org.junit.Before)

Example 43 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class PermissionsFunctionChmodTest method cleanupDb.

@AfterClass
public static void cleanupDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final SecurityManager sm = pool.getSecurityManager();
    try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        removeUser(sm, USER2_NAME);
        removeUser(sm, USER1_NAME);
        removeCollection(broker, transaction, TestConstants.TEST_COLLECTION_URI);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) SecurityManager(org.exist.security.SecurityManager) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 44 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class AccountManagementFunctionRemoveAccountTest method xqueryRemoveAccount.

private Sequence xqueryRemoveAccount(final String username, final Optional<Subject> asUser) throws EXistException, PermissionDeniedException, XPathException {
    final BrokerPool pool = existWebServer.getBrokerPool();
    final String query = "import module namespace sm = 'http://exist-db.org/xquery/securitymanager';\n" + "sm:remove-account('" + username + "')";
    try (final DBBroker broker = pool.get(asUser)) {
        final XQuery xquery = existWebServer.getBrokerPool().getXQueryService();
        final Sequence result = xquery.execute(broker, query, null);
        return result;
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

Example 45 with DBBroker

use of org.exist.storage.DBBroker in project exist by eXist-db.

the class ParseHtmlTest method parseHtml.

@Test
public void parseHtml() throws EXistException, PermissionDeniedException, XPathException {
    final String query = "util:parse-html(\"<p>hello <img src='1.jpg'></p>\")";
    final XQuery xquery = server.getBrokerPool().getXQueryService();
    try (final DBBroker broker = server.getBrokerPool().getBroker()) {
        final Sequence result = xquery.execute(broker, query, null);
        assertEquals(1, result.getItemCount());
        assertTrue(result.itemAt(0) instanceof DocumentImpl);
        final Source expected = Input.fromString("<?xml version=\"1.0\" encoding=\"UTF-8\"?><HTML><head xmlns=\"http://www.w3.org/1999/xhtml\"/><BODY><p>hello <img src=\"1.jpg\"/></p></BODY></HTML>").build();
        final Source actual = Input.fromDocument((DocumentImpl) result.itemAt(0)).build();
        final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForIdentical().build();
        assertFalse(diff.toString(), diff.hasDifferences());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Diff(org.xmlunit.diff.Diff) XQuery(org.exist.xquery.XQuery) Sequence(org.exist.xquery.value.Sequence) DocumentImpl(org.exist.dom.memtree.DocumentImpl) Source(javax.xml.transform.Source) Test(org.junit.Test)

Aggregations

DBBroker (org.exist.storage.DBBroker)468 BrokerPool (org.exist.storage.BrokerPool)304 Txn (org.exist.storage.txn.Txn)219 Sequence (org.exist.xquery.value.Sequence)185 Test (org.junit.Test)170 XQuery (org.exist.xquery.XQuery)108 Collection (org.exist.collections.Collection)93 TransactionManager (org.exist.storage.txn.TransactionManager)70 EXistException (org.exist.EXistException)66 StringInputSource (org.exist.util.StringInputSource)66 PermissionDeniedException (org.exist.security.PermissionDeniedException)44 Source (org.exist.source.Source)42 StringSource (org.exist.source.StringSource)41 XmldbURI (org.exist.xmldb.XmldbURI)41 CompiledXQuery (org.exist.xquery.CompiledXQuery)39 IOException (java.io.IOException)38 QName (org.exist.dom.QName)37 LockedDocument (org.exist.dom.persistent.LockedDocument)36 Database (org.exist.Database)35 XPathException (org.exist.xquery.XPathException)30