Search in sources :

Example 76 with BrokerPool

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

the class ImportModuleTest method noSuchModuleWithoutLocationHint.

/**
 * Checks that XQST0059 is raised if the module to be imported cannot be found (when there is no location hint).
 */
@Test
public void noSuchModuleWithoutLocationHint() throws EXistException, IOException, PermissionDeniedException {
    final String query = "import module namespace impl = \"http://example.com/impl\";\n" + "<result>\n" + "    <impl1>{impl:f1(\"to impl1\")}</impl1>" + "</result>\n";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // execute query
        try {
            final Tuple2<XQueryContext, Sequence> contextAndResult = withCompiledQuery(broker, source, compiledXQuery -> {
                final Sequence result = executeQuery(broker, compiledXQuery);
                return Tuple(compiledXQuery.getContext(), result);
            });
            transaction.commit();
            fail("expected XQST0059");
        } catch (final XPathException e) {
            transaction.commit();
            assertEquals(ErrorCodes.XQST0059, e.getErrorCode());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) Test(org.junit.Test)

Example 77 with BrokerPool

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

the class ImportModuleTest method emptyNamespace.

/**
 * Checks that XQST0088 is raised if the namespace part of an `import module` statement is empty.
 */
@Test
public void emptyNamespace() throws EXistException, IOException, PermissionDeniedException, LockException, SAXException {
    final String module = "xquery version \"1.0\";\n" + "module namespace impl = \"http://example.com/impl\";\n" + "declare function impl:f1($a as xs:string) as xs:string {\n" + "    $a\n" + "};\n";
    final String query = "import module namespace impl = \"\" at \"xmldb:exist:///db/impl1.xqm\";\n" + "<result>\n" + "    <impl1>{impl:f1(\"to impl1\")}</impl1>" + "</result>\n";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // store module
        storeModules(broker, transaction, "/db", Tuple("impl1.xqm", module));
        // execute query
        try {
            final Tuple2<XQueryContext, Sequence> contextAndResult = withCompiledQuery(broker, source, compiledXQuery -> {
                final Sequence result = executeQuery(broker, compiledXQuery);
                return Tuple(compiledXQuery.getContext(), result);
            });
            transaction.commit();
            fail("expected XQST0088");
        } catch (final XPathException e) {
            transaction.commit();
            assertEquals(ErrorCodes.XQST0088, e.getErrorCode());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) Test(org.junit.Test)

Example 78 with BrokerPool

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

the class ImportModuleTest method prefixSameAsOtherNamespaceDeclaration.

/**
 * Checks that XQST0033 is raised if the prefix part of an `import module` statement is the same as the prefix
 * of a namespace declaration within the same module.
 */
@Test
public void prefixSameAsOtherNamespaceDeclaration() throws EXistException, IOException, SAXException, PermissionDeniedException, LockException {
    final String module = "xquery version \"1.0\";\n" + "module namespace impl = \"http://example.com/impl\";\n" + "declare function impl:f1($a as xs:string) as xs:string {\n" + "    $a\n" + "};\n";
    final String query = "declare namespace impl = \"http://example.com/impl\";\n" + "import module namespace impl = \"http://example.com/impl\" at \"xmldb:exist:///db/impl1.xqm\";\n" + "<result>\n" + "    <impl1>{impl:f1(\"to impl1\")}</impl1>" + "</result>\n";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // store module
        storeModules(broker, transaction, "/db", Tuple("impl1.xqm", module));
        // execute query
        try {
            final Tuple2<XQueryContext, Sequence> contextAndResult = withCompiledQuery(broker, source, compiledXQuery -> {
                final Sequence result = executeQuery(broker, compiledXQuery);
                return Tuple(compiledXQuery.getContext(), result);
            });
            transaction.commit();
            fail("expected XQST0033");
        } catch (final XPathException e) {
            transaction.commit();
            assertEquals(ErrorCodes.XQST0033, e.getErrorCode());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) Test(org.junit.Test)

Example 79 with BrokerPool

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

the class ImportModuleTest method cyclic1.

/**
 * Checks that XQST0093 is raised if there exists a sequence of modules M1 ... Mi ... M1.
 */
@Ignore("eXist-db does not have cyclic import checks, but it should!")
@Test
public void cyclic1() throws EXistException, IOException, PermissionDeniedException, LockException, SAXException {
    final String module1 = "xquery version \"1.0\";\n" + "module namespace impl1 = \"http://example.com/impl1\";\n" + "import module namespace impl2 = \"http://example.com/impl2\"" + "        at \"xmldb:exist:///db/impl2.xqm\";\n" + "declare function impl1:f1($a as xs:string) as xs:string {\n" + "    $a\n" + "};\n";
    final String module2 = "xquery version \"1.0\";\n" + "module namespace impl2 = \"http://example.com/impl2\";\n" + "import module namespace impl1 = \"http://example.com/impl1\"" + "        at \"xmldb:exist:///db/impl1.xqm\";\n" + "declare function impl2:f1($a as xs:string) as xs:string {\n" + "    $a\n" + "};\n";
    final String query = "import module namespace impl1 = \"http://example.com/impl1\"" + "        at \"xmldb:exist:///db/impl1.xqm\";\n" + "<result>\n" + "    <impl1>{impl1:f1(\"to impl1\")}</impl1>" + "</result>\n";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // store modules
        storeModules(broker, transaction, "/db", Tuple("impl1.xqm", module1), Tuple("impl2.xqm", module2));
        // execute query
        try {
            final Tuple2<XQueryContext, Sequence> contextAndResult = withCompiledQuery(broker, source, compiledXQuery -> {
                final Sequence result = executeQuery(broker, compiledXQuery);
                return Tuple(compiledXQuery.getContext(), result);
            });
            transaction.commit();
            fail("expected XQST0093");
        } catch (final XPathException e) {
            transaction.commit();
            assertEquals(ErrorCodes.XQST0093, e.getErrorCode());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 80 with BrokerPool

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

the class ImportModuleTest method prefixSameAsModuleDeclaration.

/**
 * Checks that XQST0033 is raised if the prefix part of an `import module` statement is the same as the prefix
 * of the library module in which it resides.
 */
@Test
public void prefixSameAsModuleDeclaration() throws EXistException, IOException, SAXException, PermissionDeniedException, LockException {
    final String module1 = "xquery version \"1.0\";\n" + "module namespace impl = \"http://example.com/impl\";\n" + "import module namespace impl = \"http://example.com/impl\" at \"xmldb:exist:///db/impl2.xqm\";\n" + "declare function impl:f1($a as xs:string) as xs:string {\n" + "    $a\n" + "};\n";
    final String module2 = "xquery version \"1.0\";\n" + "module namespace impl = \"http://example.com/impl\";\n" + "declare function impl:f1($a as xs:string, $b as xs:string) as xs:string {\n" + "    fn:concat($a, ' ', $b)\n" + "};\n";
    final String query = "declare namespace impl = \"http://example.com/impl\";\n" + "import module namespace impl = \"http://example.com/impl\" at \"xmldb:exist:///db/impl1.xqm\";\n" + "<result>\n" + "    <impl1>{impl:f1(\"to impl1\")}</impl1>" + "</result>\n";
    final BrokerPool pool = existEmbeddedServer.getBrokerPool();
    final Source source = new StringSource(query);
    try (final DBBroker broker = pool.get(Optional.of(pool.getSecurityManager().getSystemSubject()));
        final Txn transaction = pool.getTransactionManager().beginTransaction()) {
        // store modules
        storeModules(broker, transaction, "/db", Tuple("impl1.xqm", module1), Tuple("impl2.xqm", module2));
        // execute query
        try {
            final Tuple2<XQueryContext, Sequence> contextAndResult = withCompiledQuery(broker, source, compiledXQuery -> {
                final Sequence result = executeQuery(broker, compiledXQuery);
                return Tuple(compiledXQuery.getContext(), result);
            });
            transaction.commit();
            fail("expected XQST0033");
        } catch (final XPathException e) {
            transaction.commit();
            assertEquals(ErrorCodes.XQST0033, e.getErrorCode());
        }
    }
}
Also used : DBBroker(org.exist.storage.DBBroker) StringSource(org.exist.source.StringSource) Txn(org.exist.storage.txn.Txn) Sequence(org.exist.xquery.value.Sequence) BrokerPool(org.exist.storage.BrokerPool) StringSource(org.exist.source.StringSource) StringInputSource(org.exist.util.StringInputSource) Source(org.exist.source.Source) Test(org.junit.Test)

Aggregations

BrokerPool (org.exist.storage.BrokerPool)381 DBBroker (org.exist.storage.DBBroker)300 Txn (org.exist.storage.txn.Txn)180 Sequence (org.exist.xquery.value.Sequence)157 Test (org.junit.Test)115 XQuery (org.exist.xquery.XQuery)105 Collection (org.exist.collections.Collection)71 StringInputSource (org.exist.util.StringInputSource)66 TransactionManager (org.exist.storage.txn.TransactionManager)61 Source (org.exist.source.Source)43 StringSource (org.exist.source.StringSource)40 CompiledXQuery (org.exist.xquery.CompiledXQuery)38 Path (java.nio.file.Path)22 XmldbURI (org.exist.xmldb.XmldbURI)21 XPathException (org.exist.xquery.XPathException)21 Properties (java.util.Properties)20 LockedDocument (org.exist.dom.persistent.LockedDocument)20 InputSource (org.xml.sax.InputSource)20 IOException (java.io.IOException)19 XQueryContext (org.exist.xquery.XQueryContext)19