use of org.exist.storage.DBBroker 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());
}
}
}
use of org.exist.storage.DBBroker 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());
}
}
}
use of org.exist.storage.DBBroker 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());
}
}
}
use of org.exist.storage.DBBroker 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());
}
}
}
use of org.exist.storage.DBBroker 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());
}
}
}
Aggregations