22
22
package org .exist .xquery .functions .fn .transform ;
23
23
24
24
import org .exist .xquery .XPathException ;
25
+ import org .exist .xquery .XQueryContext ;
25
26
import org .exist .xquery .value .AnyURIValue ;
26
27
import org .junit .jupiter .api .Test ;
27
28
29
+ import javax .xml .transform .Source ;
30
+ import javax .xml .transform .TransformerException ;
28
31
import java .math .BigDecimal ;
29
32
import java .net .URISyntaxException ;
30
33
@@ -49,20 +52,23 @@ void versionNumbers() throws Transform.PendingException {
49
52
assertEquals (Options .XSLTVersion .fromDecimal (new BigDecimal ("3.1" )), Options .XSLTVersion .fromDecimal (new BigDecimal ("3.1" )));
50
53
}
51
54
52
- @ Test void badVersionNumber () throws Transform .PendingException {
55
+ @ Test
56
+ void badVersionNumber () throws Transform .PendingException {
53
57
54
58
assertThrows (Transform .PendingException .class , () -> {
55
59
Options .XSLTVersion version311 = Options .XSLTVersion .fromDecimal (new BigDecimal ("3.11" ));
56
60
});
57
61
}
58
62
59
- @ Test public void emptyResolution () throws XPathException , URISyntaxException {
63
+ @ Test
64
+ public void emptyResolution () throws XPathException , URISyntaxException {
60
65
var base = new AnyURIValue ("" );
61
66
var relative = new AnyURIValue ("path/to/functions1.xsl" );
62
67
assertEquals (new AnyURIValue ("path/to/functions1.xsl" ), URIResolution .resolveURI (relative , base ));
63
68
}
64
69
65
- @ Test public void resolution () throws XPathException , URISyntaxException {
70
+ @ Test
71
+ public void resolution () throws XPathException , URISyntaxException {
66
72
var base = new AnyURIValue ("xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" );
67
73
var relative = new AnyURIValue ("functions1.xsl" );
68
74
assertEquals (new AnyURIValue ("xmldb:exist:/db/apps/fn_transform/functions1.xsl" ),
@@ -107,4 +113,67 @@ void versionNumbers() throws Transform.PendingException {
107
113
assertEquals (new AnyURIValue ("https://127.0.0.1:8088/a/b/c/functions1.xsl" ),
108
114
URIResolution .resolveURI (relative5 , base5 ));
109
115
}
116
+
117
+ /**
118
+ * Create some UT coverage of the CompileTimeURIResolver
119
+ * This is more significantly exercised by XQTS tests
120
+ * Results are the same as above, wrapped in a {@code Source}
121
+ *
122
+ * @throws TransformerException
123
+ */
124
+ @ Test
125
+ public void resolverObject () throws TransformerException {
126
+ var resolver = new URIResolution .CompileTimeURIResolver (new XQueryContext (), null ) {
127
+ @ Override protected SourceWithLocation resolveDocument (final String location ) {
128
+ return new SourceWithLocation ("RESOLVED::" + location );
129
+ }
130
+ };
131
+
132
+ assertEquals ("RESOLVED::xmldb:exist:/db/apps/fn_transform/functions1.xsl" ,
133
+ ((SourceWithLocation )resolver .resolve ("functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
134
+ assertEquals ("RESOLVED::xmldb:exist:/functions1.xsl" ,
135
+ ((SourceWithLocation )resolver .resolve ("/functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
136
+
137
+ assertEquals ("RESOLVED::xmldb:exist:/fn_transform/functions1.xsl" ,
138
+ ((SourceWithLocation )resolver .resolve ("/fn_transform/functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
139
+
140
+ assertEquals ("RESOLVED::xmldb:exist:/fn_transform/functions1.xsl" ,
141
+ ((SourceWithLocation )resolver .resolve ("/fn_transform/functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
142
+
143
+ assertEquals ("RESOLVED::https://127.0.0.1:8088/db/apps/fn_transform/functions1.xsl" ,
144
+ ((SourceWithLocation )resolver .resolve ("functions1.xsl" , "https://127.0.0.1:8088/db/apps/fn_transform/tei-toc2.xsl" )).location );
145
+
146
+ assertEquals ("RESOLVED::https://127.0.0.1:8088/db/apps/fn_transform/functions1.xsl" ,
147
+ ((SourceWithLocation )resolver .resolve ("functions1.xsl" , "https://127.0.0.1:8088/db/apps/fn_transform/" )).location );
148
+
149
+ assertEquals ("RESOLVED::https://127.0.0.1:8088/functions1.xsl" ,
150
+ ((SourceWithLocation )resolver .resolve ("/functions1.xsl" , "https://127.0.0.1:8088/db/apps/fn_transform/" )).location );
151
+
152
+ assertEquals ("RESOLVED::xmldb:exist:///a/b/c/functions1.xsl" ,
153
+ ((SourceWithLocation )resolver .resolve ("xmldb:exist:///a/b/c/functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
154
+
155
+ assertEquals ("RESOLVED::https://127.0.0.1:8088/a/b/c/functions1.xsl" ,
156
+ ((SourceWithLocation )resolver .resolve ("https://127.0.0.1:8088/a/b/c/functions1.xsl" , "xmldb:exist:///db/apps/fn_transform/tei-toc2.xsl" )).location );
157
+ }
158
+
159
+ /**
160
+ * Skeleton implementation for test
161
+ */
162
+ private static class SourceWithLocation implements Source {
163
+
164
+ final String location ;
165
+ SourceWithLocation (final String location ) {
166
+ this .location = location ;
167
+ }
168
+
169
+ @ Override
170
+ public void setSystemId (String systemId ) {
171
+
172
+ }
173
+
174
+ @ Override
175
+ public String getSystemId () {
176
+ return null ;
177
+ }
178
+ }
110
179
}
0 commit comments