-
-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[bugfix] allow module imports in one-off xqueries
fixes #5525 - add functx to autodeploy for xquery tests - add tests for one-off queries with module imports - of a registered module without location hint - of a module with location hint - change XQueryContext to allow imports again - change SourceFactory to work with contextPath set to "."
- Loading branch information
Showing
5 changed files
with
143 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
exist-core/src/test/java/org/exist/xquery/ModuleImportTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package org.exist.xquery; | ||
|
||
import com.evolvedbinary.j8fu.Either; | ||
import org.exist.EXistException; | ||
import org.exist.security.PermissionDeniedException; | ||
import org.exist.test.XQueryCompilationTest; | ||
import org.exist.xquery.value.Sequence; | ||
import org.exist.xquery.value.StringValue; | ||
import org.junit.Test; | ||
|
||
import static org.exist.test.XQueryAssertions.assertThatXQResult; | ||
import static org.exist.test.XQueryAssertions.assertXQStaticError; | ||
import static org.hamcrest.Matchers.equalTo; | ||
|
||
/** | ||
* Ensure library module imports work in one-off queries | ||
* needs functx to be installed => conf.xml => triggers => autodeploy | ||
* | ||
* @author <a href="mailto:[email protected]">Juri Leino</a> | ||
*/ | ||
public class ModuleImportTest extends XQueryCompilationTest { | ||
@Test | ||
public void importLibraryWithoutLocation() throws EXistException, PermissionDeniedException { | ||
final Sequence expected = new StringValue("xs:integer"); | ||
|
||
final String query = "import module namespace functx='http://www.functx.com';" + | ||
"functx:atomic-type(4)"; | ||
final Either<XPathException, Sequence> actual = executeQuery(query); | ||
|
||
assertThatXQResult(actual, equalTo(expected)); | ||
} | ||
@Test | ||
public void importLibraryFromDbLocation() throws EXistException, PermissionDeniedException { | ||
final Sequence expected = new StringValue("xs:integer"); | ||
|
||
final String query = "import module namespace functx='http://www.functx.com'" + | ||
" at '/db/system/repo/functx-1.0.1/functx/functx.xq';" + | ||
"functx:atomic-type(4)"; | ||
final Either<XPathException, Sequence> actual = executeQuery(query); | ||
|
||
assertThatXQResult(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void importLibraryFromXMLDBLocation() throws EXistException, PermissionDeniedException { | ||
final Sequence expected = new StringValue("xs:integer"); | ||
|
||
final String query = "import module namespace functx='http://www.functx.com'" + | ||
" at 'xmldb:///db/system/repo/functx-1.0.1/functx/functx.xq';" + | ||
"functx:atomic-type(4)"; | ||
final Either<XPathException, Sequence> actual = executeQuery(query); | ||
|
||
assertThatXQResult(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void importLibraryFromExistXMLDBLocation() throws EXistException, PermissionDeniedException { | ||
final Sequence expected = new StringValue("xs:integer"); | ||
|
||
final String query = "import module namespace functx='http://www.functx.com'" + | ||
" at 'xmldb:exist:///db/system/repo/functx-1.0.1/functx/functx.xq';" + | ||
"functx:atomic-type(4)"; | ||
final Either<XPathException, Sequence> actual = executeQuery(query); | ||
|
||
assertThatXQResult(actual, equalTo(expected)); | ||
} | ||
|
||
@Test | ||
public void importLibraryFromUnknownLocation() throws EXistException, PermissionDeniedException { | ||
|
||
final String query = "import module namespace functx='http://www.functx.com'" + | ||
" at 'unknown:///db/system/repo/functx-1.0.1/functx/functx.xq';" + | ||
"functx:atomic-type(4)"; | ||
final String expectedMessage = "error found while loading module functx: Source for module 'http://www.functx.com' not found module location hint URI 'unknown:///db/system/repo/functx-1.0.1/functx/functx.xq'."; | ||
|
||
assertXQStaticError(ErrorCodes.XQST0059, -1,-1, expectedMessage, compileQuery(query)); | ||
} | ||
|
||
@Test | ||
public void importLibraryFromRelativeLocation() throws EXistException, PermissionDeniedException { | ||
final String query = "import module namespace functx='http://www.functx.com'" + | ||
" at './functx.xq';" + | ||
"functx:atomic-type(4)"; | ||
final String expectedMessage = "error found while loading module functx: Source for module 'http://www.functx.com' not found module location hint URI './functx.xq'."; | ||
|
||
assertXQStaticError(ErrorCodes.XQST0059, -1,-1, expectedMessage, compileQuery(query)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters