Skip to content

Commit

Permalink
Merge pull request #5575 from line-o/backport/5574
Browse files Browse the repository at this point in the history
[6.x.x] Backport #5574
  • Loading branch information
reinhapa authored Dec 10, 2024
2 parents 5cbb4cc + 07c2e87 commit 56551ac
Showing 1 changed file with 45 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<x>bonjourno</x>";
private static final String expectedOutput = "<r xmlns:functx=\"http://www.functx.com\">hello</r>";

private static Path getConfigFile() {
final ClassLoader loader = TransformFromPkgTest.class.getClassLoader();
final char separator = System.getProperty("file.separator").charAt(0);
Expand All @@ -55,32 +59,53 @@ private static Path getConfigFile() {
}
}

private static String getQuery(final String importLocation) {
final String xslt = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n" +
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
" xmlns:functx=\"http://www.functx.com\"\n" +
" exclude-result-prefixes=\"xs\"\n" +
" version=\"2.0\">\n" +
" \n" +
" <xsl:import href=\"" + importLocation + "\"/>\n" +
" \n" +
" <xsl:template match=\"/\">\n" +
" <r>" +
" <xsl:value-of select=\"functx:replace-first(., 'bonjourno', 'hello')\"/>\n" +
" </r>" +
" </xsl:template>\n" +
" \n" +
"</xsl:stylesheet>";

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 =
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n" +
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
" xmlns:functx=\"http://www.functx.com\"\n" +
" exclude-result-prefixes=\"xs\"\n" +
" version=\"2.0\">\n" +
" \n" +
" <xsl:import href=\"http://www.functx.com/functx.xsl\"/>\n" +
" \n" +
" <xsl:template match=\"/\">\n" +
" <xsl:value-of select=\"functx:replace-first('hello', 'he', 'ho')\"/>\n" +
" </xsl:template>\n" +
" \n" +
"</xsl:stylesheet>";

final String xml = "<x>bonjourno</x>";
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);
}
}

0 comments on commit 56551ac

Please sign in to comment.