Skip to content

Commit d8a9ed7

Browse files
authored
Merge pull request #5574 from line-o/hotfix/transform-test
[hotfix] fix and extend TransformFromPkgTest
2 parents 863fe85 + dba68b1 commit d8a9ed7

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
@@ -39,6 +39,10 @@
3939
*/
4040
public class TransformFromPkgTest {
4141

42+
private static final String moduleLocation = "/db/system/repo/functx-1.0.1/functx/functx.xsl";
43+
private static final String inputXml = "<x>bonjourno</x>";
44+
private static final String expectedOutput = "<r xmlns:functx=\"http://www.functx.com\">hello</r>";
45+
4246
private static Path getConfigFile() {
4347
final ClassLoader loader = TransformFromPkgTest.class.getClassLoader();
4448
final char separator = System.getProperty("file.separator").charAt(0);
@@ -52,32 +56,53 @@ private static Path getConfigFile() {
5256
}
5357
}
5458

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

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

77-
final String xquery = "transform:transform(" + xml + ", " + xslt + ", ())";
95+
@Test
96+
public void testImportXmldbScheme() throws XMLDBException {
97+
final String xquery = getQuery("xmldb:" + moduleLocation);
98+
final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
99+
assertTransformationResult(result);
100+
}
78101

102+
@Test
103+
public void testImportXmldbSchemeDoubleSlash() throws XMLDBException {
104+
final String xquery = getQuery("xmldb://" + moduleLocation);
79105
final ResourceSet result = existXmldbEmbeddedServer.executeQuery(xquery);
80-
assertNotNull(result);
81-
assertEquals(1, result.getSize());
106+
assertTransformationResult(result);
82107
}
83108
}

0 commit comments

Comments
 (0)