39
39
*/
40
40
public class TransformFromPkgTest {
41
41
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
+
42
46
private static Path getConfigFile () {
43
47
final ClassLoader loader = TransformFromPkgTest .class .getClassLoader ();
44
48
final char separator = System .getProperty ("file.separator" ).charAt (0 );
@@ -52,32 +56,53 @@ private static Path getConfigFile() {
52
56
}
53
57
}
54
58
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
+
55
85
@ ClassRule
56
86
public static ExistXmldbEmbeddedServer existXmldbEmbeddedServer = new ExistXmldbEmbeddedServer (true , false , true , getConfigFile ());
57
87
58
88
@ 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
+ }
76
94
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
+ }
78
101
102
+ @ Test
103
+ public void testImportXmldbSchemeDoubleSlash () throws XMLDBException {
104
+ final String xquery = getQuery ("xmldb://" + moduleLocation );
79
105
final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
80
- assertNotNull (result );
81
- assertEquals (1 , result .getSize ());
106
+ assertTransformationResult (result );
82
107
}
83
108
}
0 commit comments