38
38
import static org .junit .Assert .assertNotNull ;
39
39
40
40
/**
41
+ * Test transform:transform with an imported stylesheet from various
42
+ * locations
43
+ *
41
44
* @author <a href="mailto:[email protected] ">Adam Retter</a>
45
+ * @author <a href="mailto:[email protected] ">Juri Leino</a>
42
46
*/
43
- public class TransformFromPkgTest {
47
+ public class ImportStylesheetTest {
44
48
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 >" ;
49
+ private static final String XSL_DB_LOCATION = "/db/system/repo/functx-1.0.1/functx/functx.xsl" ;
50
+ private static final String INPUT_XML = "<in >bonjourno</in >" ;
51
+ private static final String EXPECTED_OUTPUT = "<out >hello</out >" ;
48
52
49
53
private static Path getConfigFile () {
50
- final ClassLoader loader = TransformFromPkgTest .class .getClassLoader ();
54
+ final ClassLoader loader = ImportStylesheetTest .class .getClassLoader ();
51
55
final char separator = System .getProperty ("file.separator" ).charAt (0 );
52
- final String packagePath = TransformFromPkgTest .class .getPackage ().getName ().replace ('.' , separator );
56
+ final String packagePath = ImportStylesheetTest .class .getPackage ().getName ().replace ('.' , separator );
53
57
54
58
try {
55
59
return Paths .get (loader .getResource (packagePath + separator + "conf.xml" ).toURI ());
@@ -60,51 +64,72 @@ private static Path getConfigFile() {
60
64
}
61
65
62
66
private static String getQuery (final String importLocation ) {
63
- final String xslt = "<xsl:stylesheet xmlns:xsl=\" http://www.w3.org/1999/XSL/Transform\" \n " +
67
+ final String xslt =
68
+ "<xsl:stylesheet xmlns:xsl=\" http://www.w3.org/1999/XSL/Transform\" \n " +
64
69
" xmlns:xs=\" http://www.w3.org/2001/XMLSchema\" \n " +
65
70
" xmlns:functx=\" http://www.functx.com\" \n " +
66
- " exclude-result-prefixes=\" xs\" \n " +
71
+ " exclude-result-prefixes=\" functx xs\" \n " +
67
72
" version=\" 2.0\" >\n " +
68
- " \n " +
69
73
" <xsl:import href=\" " + importLocation + "\" />\n " +
70
- " \n " +
71
74
" <xsl:template match=\" /\" >\n " +
72
- " <r> " +
75
+ " <out> \n " +
73
76
" <xsl:value-of select=\" functx:replace-first(., 'bonjourno', 'hello')\" />\n " +
74
- " </r> " +
77
+ " </out> \n " +
75
78
" </xsl:template>\n " +
76
- " \n " +
77
79
"</xsl:stylesheet>" ;
78
80
79
- return "transform:transform(" + inputXml + ", " + xslt + ", ())" ;
81
+ return "transform:transform(" + INPUT_XML + ", " + xslt + ", ())" ;
80
82
}
81
83
82
84
private static void assertTransformationResult (ResourceSet result ) throws XMLDBException {
83
85
assertNotNull (result );
84
86
assertEquals (1 , result .getSize ());
85
- assertEquals (expectedOutput , result .getResource (0 ).getContent ());
87
+ assertEquals (EXPECTED_OUTPUT , result .getResource (0 ).getContent ());
86
88
}
87
89
88
90
@ ClassRule
89
91
public static ExistXmldbEmbeddedServer existXmldbEmbeddedServer = new ExistXmldbEmbeddedServer (true , false , true , getConfigFile ());
90
92
91
93
@ Test
92
- public void testImportNoScheme () throws XMLDBException {
93
- final String xquery = getQuery (moduleLocation );
94
+ public void fromRegisteredImportUri () throws XMLDBException {
95
+ final String xquery = getQuery ("http://www.functx.com/functx.xsl" );
96
+ final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
97
+ assertTransformationResult (result );
98
+ }
99
+
100
+ @ Test
101
+ public void fromDbLocationWithoutScheme () throws XMLDBException {
102
+ final String xquery = getQuery (XSL_DB_LOCATION );
103
+ final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
104
+ assertTransformationResult (result );
105
+ }
106
+
107
+ @ Test
108
+ public void fromDbLocationWithXmldbScheme () throws XMLDBException {
109
+ final String xquery = getQuery ("xmldb:" + XSL_DB_LOCATION );
110
+ final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
111
+ assertTransformationResult (result );
112
+ }
113
+
114
+ @ Test
115
+ public void fromDbLocationWithXmldbSchemeDoubleSlash () throws XMLDBException {
116
+ final String xquery = getQuery ("xmldb://" + XSL_DB_LOCATION );
94
117
final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
95
118
assertTransformationResult (result );
96
119
}
97
120
121
+ /** This test fails at the moment with "unknown protocol: exist" */
98
122
@ Test
99
- public void testImportXmldbScheme () throws XMLDBException {
100
- final String xquery = getQuery ("xmldb:" + moduleLocation );
123
+ @ Ignore
124
+ public void fromDbLocationWithExistScheme () throws XMLDBException {
125
+ final String xquery = getQuery ("exist:" + XSL_DB_LOCATION );
101
126
final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
102
127
assertTransformationResult (result );
103
128
}
104
129
105
130
@ Test
106
- public void testImportXmldbSchemeDoubleSlash () throws XMLDBException {
107
- final String xquery = getQuery ("xmldb ://" + moduleLocation );
131
+ public void fromDbLocationWithExistSchemeDoubleSlash () throws XMLDBException {
132
+ final String xquery = getQuery ("exist ://" + XSL_DB_LOCATION );
108
133
final ResourceSet result = existXmldbEmbeddedServer .executeQuery (xquery );
109
134
assertTransformationResult (result );
110
135
}
0 commit comments