42
42
*/
43
43
public class TransformFromPkgTest {
44
44
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
+
45
49
private static Path getConfigFile () {
46
50
final ClassLoader loader = TransformFromPkgTest .class .getClassLoader ();
47
51
final char separator = System .getProperty ("file.separator" ).charAt (0 );
@@ -55,32 +59,53 @@ private static Path getConfigFile() {
55
59
}
56
60
}
57
61
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
+
58
88
@ ClassRule
59
89
public static ExistXmldbEmbeddedServer existXmldbEmbeddedServer = new ExistXmldbEmbeddedServer (true , false , true , getConfigFile ());
60
90
61
91
@ 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
+ }
79
97
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
+ }
81
104
105
+ @ Test
106
+ public void testImportXmldbSchemeDoubleSlash () throws XMLDBException {
107
+ final String xquery = getQuery ("xmldb://" + moduleLocation );
82
108
final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
83
- assertNotNull (result );
84
- assertEquals (1 , result .getSize ());
109
+ assertTransformationResult (result );
85
110
}
86
111
}
0 commit comments