From 07c2e871876ef9e18fe71d058a247e9a82046c5a Mon Sep 17 00:00:00 2001 From: Juri Leino Date: Mon, 9 Dec 2024 21:57:56 +0100 Subject: [PATCH] [hotfix] fix and extend TransformFromPkgTest - load the module from existdb instead of an external source - test with and without xmldb: scheme - fix template under test to actually do something - ensure that the output is checked for correctness --- .../transform/TransformFromPkgTest.java | 65 +++++++++++++------ 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java b/exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java index 7b1e3b32bd3..cfe796e3990 100644 --- a/exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java +++ b/exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java @@ -42,6 +42,10 @@ */ public class TransformFromPkgTest { + private static final String moduleLocation = "/db/system/repo/functx-1.0.1/functx/functx.xsl"; + private static final String inputXml = "bonjourno"; + private static final String expectedOutput = "hello"; + private static Path getConfigFile() { final ClassLoader loader = TransformFromPkgTest.class.getClassLoader(); final char separator = System.getProperty("file.separator").charAt(0); @@ -55,32 +59,53 @@ private static Path getConfigFile() { } } + private static String getQuery(final String importLocation) { + final String xslt = "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " " + + " \n" + + " " + + " \n" + + " \n" + + ""; + + return "transform:transform(" + inputXml + ", " + xslt + ", ())"; + } + + private static void assertTransformationResult(ResourceSet result) throws XMLDBException { + assertNotNull(result); + assertEquals(1, result.getSize()); + assertEquals(expectedOutput, result.getResource(0).getContent()); + } + @ClassRule public static ExistXmldbEmbeddedServer existXmldbEmbeddedServer = new ExistXmldbEmbeddedServer(true, false, true, getConfigFile()); @Test - public void transformWithModuleFromPkg() throws XMLDBException { - final String xslt = - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \n" + - ""; - - final String xml = "bonjourno"; + public void testImportNoScheme() throws XMLDBException { + final String xquery = getQuery(moduleLocation); + final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery); + assertTransformationResult(result); + } - final String xquery = "transform:transform(" + xml + ", " + xslt + ", ())"; + @Test + public void testImportXmldbScheme() throws XMLDBException { + final String xquery = getQuery("xmldb:" + moduleLocation); + final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery); + assertTransformationResult(result); + } + @Test + public void testImportXmldbSchemeDoubleSlash() throws XMLDBException { + final String xquery = getQuery("xmldb://" + moduleLocation); final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery); - assertNotNull(result); - assertEquals(1, result.getSize()); + assertTransformationResult(result); } }