Skip to content

Commit 56551ac

Browse files
authored
Merge pull request #5575 from line-o/backport/5574
[6.x.x] Backport #5574
2 parents 5cbb4cc + 07c2e87 commit 56551ac

File tree

1 file changed

+45
-20
lines changed

1 file changed

+45
-20
lines changed

exist-core/src/test/java/org/exist/xquery/functions/transform/TransformFromPkgTest.java

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@
4242
*/
4343
public class TransformFromPkgTest {
4444

45+
private static final String moduleLocation = "/db/system/repo/functx-1.0.1/functx/functx.xsl";
46+
private static final String inputXml = "<x>bonjourno</x>";
47+
private static final String expectedOutput = "<r xmlns:functx=\"http://www.functx.com\">hello</r>";
48+
4549
private static Path getConfigFile() {
4650
final ClassLoader loader = TransformFromPkgTest.class.getClassLoader();
4751
final char separator = System.getProperty("file.separator").charAt(0);
@@ -55,32 +59,53 @@ private static Path getConfigFile() {
5559
}
5660
}
5761

62+
private static String getQuery(final String importLocation) {
63+
final String xslt = "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n" +
64+
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
65+
" xmlns:functx=\"http://www.functx.com\"\n" +
66+
" exclude-result-prefixes=\"xs\"\n" +
67+
" version=\"2.0\">\n" +
68+
" \n" +
69+
" <xsl:import href=\"" + importLocation + "\"/>\n" +
70+
" \n" +
71+
" <xsl:template match=\"/\">\n" +
72+
" <r>" +
73+
" <xsl:value-of select=\"functx:replace-first(., 'bonjourno', 'hello')\"/>\n" +
74+
" </r>" +
75+
" </xsl:template>\n" +
76+
" \n" +
77+
"</xsl:stylesheet>";
78+
79+
return "transform:transform(" + inputXml + ", " + xslt + ", ())";
80+
}
81+
82+
private static void assertTransformationResult(ResourceSet result) throws XMLDBException {
83+
assertNotNull(result);
84+
assertEquals(1, result.getSize());
85+
assertEquals(expectedOutput, result.getResource(0).getContent());
86+
}
87+
5888
@ClassRule
5989
public static ExistXmldbEmbeddedServer existXmldbEmbeddedServer = new ExistXmldbEmbeddedServer(true, false, true, getConfigFile());
6090

6191
@Test
62-
public void transformWithModuleFromPkg() throws XMLDBException {
63-
final String xslt =
64-
"<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"\n" +
65-
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n" +
66-
" xmlns:functx=\"http://www.functx.com\"\n" +
67-
" exclude-result-prefixes=\"xs\"\n" +
68-
" version=\"2.0\">\n" +
69-
" \n" +
70-
" <xsl:import href=\"http://www.functx.com/functx.xsl\"/>\n" +
71-
" \n" +
72-
" <xsl:template match=\"/\">\n" +
73-
" <xsl:value-of select=\"functx:replace-first('hello', 'he', 'ho')\"/>\n" +
74-
" </xsl:template>\n" +
75-
" \n" +
76-
"</xsl:stylesheet>";
77-
78-
final String xml = "<x>bonjourno</x>";
92+
public void testImportNoScheme() throws XMLDBException {
93+
final String xquery = getQuery(moduleLocation);
94+
final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
95+
assertTransformationResult(result);
96+
}
7997

80-
final String xquery = "transform:transform(" + xml + ", " + xslt + ", ())";
98+
@Test
99+
public void testImportXmldbScheme() throws XMLDBException {
100+
final String xquery = getQuery("xmldb:" + moduleLocation);
101+
final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
102+
assertTransformationResult(result);
103+
}
81104

105+
@Test
106+
public void testImportXmldbSchemeDoubleSlash() throws XMLDBException {
107+
final String xquery = getQuery("xmldb://" + moduleLocation);
82108
final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
83-
assertNotNull(result);
84-
assertEquals(1, result.getSize());
109+
assertTransformationResult(result);
85110
}
86111
}

0 commit comments

Comments
 (0)