Search in sources :

Example 36 with DBBroker

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

the class TransformTest method cleanupResources.

@AfterClass
public static void cleanupResources() throws EXistException, PermissionDeniedException, IOException, TriggerException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        deleteCollection(broker, transaction, TEST_IDS_COLLECTION);
        deleteCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION);
        deleteCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION);
        deleteCollection(broker, transaction, TEST_TWO_NODES_COLLECTION);
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 37 with DBBroker

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

the class TransformTest method transform1.

private static void transform1(final XmldbURI collectionUri) 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, getCountDescendantsXquery(collectionUri), null);
        assertNotNull(sequence);
        assertTrue(sequence.hasOne());
        final Source expected = Input.fromString("<count-descendants>1</count-descendants>").build();
        final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Node.class).getOwnerDocument()).build();
        final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
        assertFalse(diff.toString(), diff.hasDifferences());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Diff(org.xmlunit.diff.Diff) XQuery(org.exist.xquery.XQuery) Node(org.w3c.dom.Node) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source)

Example 38 with DBBroker

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

the class TransformTest method transform_twoNodesCountDescendants.

private static void transform_twoNodesCountDescendants() 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, COUNT_DESCENDANTS_TWO_NODES_QUERY, null);
        assertNotNull(sequence);
        assertTrue(sequence.hasOne());
        final Source expected = Input.fromString("<counts><count1>2</count1><count2>1</count2></counts>").build();
        final Source actual = Input.fromDocument(sequence.itemAt(0).toJavaObject(Node.class).getOwnerDocument()).build();
        final Diff diff = DiffBuilder.compare(expected).withTest(actual).checkForSimilar().build();
        assertFalse(diff.toString(), diff.hasDifferences());
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Diff(org.xmlunit.diff.Diff) XQuery(org.exist.xquery.XQuery) Node(org.w3c.dom.Node) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringInputSource(org.exist.util.StringInputSource) Source(javax.xml.transform.Source)

Example 39 with DBBroker

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

the class TransformTest method storeResources.

@BeforeClass
public static void storeResources() throws EXistException, PermissionDeniedException, IOException, SAXException, LockException {
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        createCollection(broker, transaction, TEST_IDS_COLLECTION, Tuple(LIST_OPS_XSLT_NAME, LIST_OPS_XSLT), Tuple(INPUT_LIST_XML_NAME, INPUT_XML), Tuple(DICTIONARY_XML_NAME, DICTIONARY_XML));
        createCollection(broker, transaction, TEST_DOCUMENT_XSLT_COLLECTION, Tuple(DOCUMENT_XSLT_NAME, DOCUMENT_XSLT));
        createCollection(broker, transaction, TEST_SIMPLE_XML_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_COLLECTION)));
        createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_COMMENT), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_COMMENT_COLLECTION)));
        createCollection(broker, transaction, TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION, Tuple(SIMPLE_XML_NAME, SIMPLE_XML_WITH_TWO_COMMENTS), Tuple(COUNT_DESCENDANTS_XSLT_NAME, getCountDescendantsXslt(TEST_SIMPLE_XML_WITH_TWO_COMMENTS_COLLECTION)));
        createCollection(broker, transaction, TEST_TWO_NODES_COLLECTION, Tuple(TWO_NODES_XML_NAME, TWO_NODES_XML), Tuple(COUNT_DESCENDANTS_TWO_NODES_XSLT_NAME, COUNT_DESCENDANTS_TWO_NODES_XSLT));
        transaction.commit();
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) Txn(org.exist.storage.txn.Txn) BrokerPool(org.exist.storage.BrokerPool)

Example 40 with DBBroker

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

the class TransformTest method keys.

/**
 * {@see https://github.com/eXist-db/exist/issues/1506}
 */
@Test
public void keys() 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, LIST_OPS_XQUERY, null);
        assertNotNull(sequence);
        assertEquals(1, sequence.getItemCount());
        final Item item = sequence.itemAt(0);
        assertTrue(item instanceof Element);
        final Element dsn_flat = ((Element) item);
        assertEquals("DSN_FLAT", dsn_flat.getNodeName());
        final NodeList nodeList = dsn_flat.getElementsByTagName("listOpsEntry");
        assertEquals(4, nodeList.getLength());
        assertEquals("id: IRCANTEC doEntiteAff: false doGenerateB20: true ", nodeList.item(0).getTextContent());
        assertEquals("id: CIBTP doEntiteAff: true doGenerateB20: true ", nodeList.item(1).getTextContent());
        assertEquals("id: AGIRC-ARRCO doEntiteAff: true doGenerateB20: false ", nodeList.item(2).getTextContent());
        assertEquals("id: CTIP-FFSA-FNMF doEntiteAff: true doGenerateB20: true ", nodeList.item(3).getTextContent());
    }
}
Also used : Item(org.exist.xquery.value.Item) DBBroker(org.exist.storage.DBBroker) XQuery(org.exist.xquery.XQuery) Element(org.w3c.dom.Element) NodeList(org.w3c.dom.NodeList) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool)

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