use of org.exist.storage.txn.Txn 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.txn.Txn 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());
}
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class ImportModuleTest method noSuchModuleWithLocationHint.
/**
* Checks that XQST0059 is raised if the module to be imported cannot be found (when there is a location hint).
*/
@Test
public void noSuchModuleWithLocationHint() throws EXistException, IOException, PermissionDeniedException {
final String query = "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()) {
// 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.txn.Txn in project exist by eXist-db.
the class ImportModuleTest method functionSameAsOtherModule.
/**
* Checks that XQST0034 is raised if two modules contain a function of the same name and arity.
*/
@Test
public void functionSameAsOtherModule() throws EXistException, IOException, PermissionDeniedException, LockException, SAXException {
final String module1 = "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 module2 = "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 = \"http://example.com/impl\"" + " at \"xmldb:exist:///db/impl1.xqm\", \"xmldb:exist:///db/impl2.xqm\";\n" + "<result>\n" + " <impl1>{impl:f1(\"to impl1\")}</impl1>" + " <impl2>{impl:f1(\"to impl1\")}</impl2>" + "</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 XQST0034");
} catch (final XPathException e) {
transaction.commit();
assertEquals(ErrorCodes.XQST0034, e.getErrorCode());
assertTrue(e.getMessage().contains("{http://example.com/impl}f1#1"));
}
}
}
use of org.exist.storage.txn.Txn in project exist by eXist-db.
the class ImportModuleTest method functionDuplicateNsInMainModule.
/**
* Checks that XQST0034 is raised if a main module contains two functions of the same name and arity.
*/
@Test
public void functionDuplicateNsInMainModule() throws EXistException, IOException, PermissionDeniedException, LockException, TriggerException, XPathException {
final String query = "declare namespace ns1 = 'http://ns1';\n" + "declare namespace ns12 = 'http://ns1';\n" + "\n" + "declare function ns1:f1($a as xs:string) as xs:string {\n" + " <first>{$a}</first>\n" + "};\n" + "\n" + "declare function ns12:f1($a as xs:string) as xs:string {\n" + " <second>{$a}</second>\n" + "};\n" + "\n" + "<result>\n" + " <impl1>{ns1:f1(\"to impl1\")}</impl1>" + " <impl2>{ns12:f1(\"to impl1\")}</impl2>" + "</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 XQST0034");
} catch (final XPathException e) {
transaction.commit();
assertEquals(ErrorCodes.XQST0034, e.getErrorCode());
assertTrue(e.getMessage().contains("{http://ns1}f1#1"));
}
}
}
Aggregations