0
|
1 |
"{ Package: 'stx:goodies/xmlsuite/xpath' }"
|
|
2 |
|
|
3 |
"{ NameSpace: XMLv2 }"
|
|
4 |
|
|
5 |
TestCase subclass:#XPathDocumentAdaptorTests
|
|
6 |
instanceVariableNames:'documentAdaptor'
|
|
7 |
classVariableNames:''
|
|
8 |
poolDictionaries:''
|
|
9 |
category:'XML Suite-XPath-Tests'
|
|
10 |
!
|
|
11 |
|
|
12 |
|
|
13 |
!XPathDocumentAdaptorTests class methodsFor:'defaults'!
|
|
14 |
|
|
15 |
testedURI
|
|
16 |
^'file://bookstore.xml'.
|
|
17 |
|
|
18 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
19 |
! !
|
|
20 |
|
|
21 |
!XPathDocumentAdaptorTests class methodsFor:'test documents'!
|
|
22 |
|
|
23 |
bookstore
|
|
24 |
|
|
25 |
^'<bookstore xmlns="urn:xmlsuite:bookstore:ns"><book><title lang="eng" xmlns:ns2="urn:xmlsuite:bookstore:ns2" ns2:withPictures="yes">Harry Potter</title><price>29.99</price><parentalAdvisory>50+</parentalAdvisory><description></description></book><book><title lang="eng">Learning XML</title><price>39.95</price></book><book><title>1984</title><price>19.84</price></book></bookstore>'
|
|
26 |
|
|
27 |
"Created: / 16-11-2006 / 23:19:29 / janfrog"
|
|
28 |
"Modified: / 10-12-2006 / 19:56:15 / janfrog"
|
|
29 |
! !
|
|
30 |
|
|
31 |
!XPathDocumentAdaptorTests class methodsFor:'testing'!
|
|
32 |
|
|
33 |
isAbstract
|
|
34 |
|
|
35 |
^self == XPathDocumentAdaptorTests
|
|
36 |
|
|
37 |
"Created: / 16-11-2006 / 23:09:11 / janfrog"
|
|
38 |
! !
|
|
39 |
|
|
40 |
!XPathDocumentAdaptorTests methodsFor:'helpers'!
|
|
41 |
|
|
42 |
apply: collection
|
|
43 |
|
|
44 |
^self apply: collection to: documentAdaptor document
|
|
45 |
|
|
46 |
"Created: / 16-11-2006 / 23:27:17 / janfrog"
|
|
47 |
"Modified: / 21-11-2006 / 23:20:41 / janfrog"
|
|
48 |
!
|
|
49 |
|
|
50 |
apply: collection to: node
|
|
51 |
|
|
52 |
^collection
|
|
53 |
inject:node
|
|
54 |
into:[:nodeIdOrCollection :selector|
|
|
55 |
nodeIdOrCollection isCollection
|
|
56 |
ifTrue:[nodeIdOrCollection perform:selector]
|
|
57 |
ifFalse:[documentAdaptor perform:selector with:nodeIdOrCollection]]
|
|
58 |
|
|
59 |
"Created: / 21-11-2006 / 23:20:22 / janfrog"
|
|
60 |
! !
|
|
61 |
|
|
62 |
!XPathDocumentAdaptorTests methodsFor:'initialization & release'!
|
|
63 |
|
|
64 |
createDocumentAdaptor
|
|
65 |
|
|
66 |
self subclassResponsibility
|
|
67 |
|
|
68 |
"Created: / 16-11-2006 / 23:22:53 / janfrog"
|
|
69 |
!
|
|
70 |
|
|
71 |
setUp
|
|
72 |
|
|
73 |
documentAdaptor := self createDocumentAdaptor.
|
|
74 |
|
|
75 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
76 |
!
|
|
77 |
|
|
78 |
tearDown
|
|
79 |
|
|
80 |
documentAdaptor releaseResources
|
|
81 |
|
|
82 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
83 |
"Modified: / 31-10-2007 / 10:25:03 / janfrog"
|
|
84 |
! !
|
|
85 |
|
|
86 |
!XPathDocumentAdaptorTests methodsFor:'tests - misc'!
|
|
87 |
|
|
88 |
test_invalid_id
|
|
89 |
|
|
90 |
self
|
|
91 |
should:[documentAdaptor xpathChildOf:nil]
|
|
92 |
raise: XPathInvalidNodeIdError
|
|
93 |
|
|
94 |
"Created: / 10-12-2006 / 19:53:21 / janfrog"
|
|
95 |
!
|
|
96 |
|
|
97 |
test_releaseResources
|
|
98 |
|
|
99 |
documentAdaptor releaseResources.
|
|
100 |
self
|
|
101 |
should:[documentAdaptor xpathDocument]
|
|
102 |
raise: XPathDocumentAdaptorReleasedError
|
|
103 |
|
|
104 |
"Created: / 10-12-2006 / 19:52:01 / janfrog"
|
|
105 |
! !
|
|
106 |
|
|
107 |
!XPathDocumentAdaptorTests methodsFor:'tests - xpath axes'!
|
|
108 |
|
|
109 |
testAncestor
|
|
110 |
"Selects all ancestors (parent, grandparent, etc.) of the current node"
|
|
111 |
|
|
112 |
| childNode ancestorsCollection |
|
|
113 |
|
|
114 |
childNode := self apply:#(xpathChildOf: first
|
|
115 |
xpathChildOf: first
|
|
116 |
xpathChildOf: first ).
|
|
117 |
"first item xpathChild first item xpathChild first item xpathChild first item."
|
|
118 |
ancestorsCollection := documentAdaptor xpathAncestorOf: childNode.
|
|
119 |
|
|
120 |
self assert: ancestorsCollection size = 3.
|
|
121 |
|
|
122 |
"reverse document order"
|
|
123 |
self assert:(documentAdaptor xpathIsDocument: ancestorsCollection third ).
|
|
124 |
self assert:(documentAdaptor xpathNameOf: ancestorsCollection second) = 'bookstore'.
|
|
125 |
self assert:(documentAdaptor xpathIsElement: ancestorsCollection second).
|
|
126 |
self assert:(documentAdaptor xpathNameOf: ancestorsCollection first) = 'book'.
|
|
127 |
self assert:(documentAdaptor xpathIsElement: ancestorsCollection first).
|
|
128 |
|
|
129 |
childNode := self apply:#().
|
|
130 |
"(XQueryAccessedNode new documentAdaptor:documentAdaptor; xpathDocument) first item."
|
|
131 |
ancestorsCollection := documentAdaptor xpathAncestorOf: childNode.
|
|
132 |
|
|
133 |
self assert: ancestorsCollection size = 0.
|
|
134 |
|
|
135 |
"Modified: / 02-11-2006 / 12:56:36 / ked"
|
|
136 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
137 |
"Modified: / 21-11-2006 / 23:28:04 / janfrog"
|
|
138 |
!
|
|
139 |
|
|
140 |
testAncestorOrSelf
|
|
141 |
"Selects all ancestors (parent, grandparent, etc.) of the current node and the current node itself"
|
|
142 |
|
|
143 |
| childNode ancestorsCollection |
|
|
144 |
|
|
145 |
childNode := self apply:#(xpathChildOf: first "root element"
|
|
146 |
xpathChildOf: first
|
|
147 |
xpathChildOf: first ).
|
|
148 |
ancestorsCollection := documentAdaptor xpathAncestorOrSelfOf: childNode.
|
|
149 |
|
|
150 |
self assert: ancestorsCollection size = 4.
|
|
151 |
|
|
152 |
"reverse document order"
|
|
153 |
self assert:(documentAdaptor xpathIsDocument: ancestorsCollection fourth ).
|
|
154 |
self assert:(documentAdaptor xpathNameOf: ancestorsCollection third ) = 'bookstore'.
|
|
155 |
self assert:(documentAdaptor xpathIsElement: ancestorsCollection third ).
|
|
156 |
self assert:(documentAdaptor xpathNameOf: ancestorsCollection second ) = 'book'.
|
|
157 |
self assert:(documentAdaptor xpathIsElement: ancestorsCollection second ).
|
|
158 |
self assert:(documentAdaptor xpathNameOf: ancestorsCollection first ) = 'title'.
|
|
159 |
self assert:(documentAdaptor xpathIsElement: ancestorsCollection first ).
|
|
160 |
|
|
161 |
childNode := self apply:#().
|
|
162 |
ancestorsCollection := documentAdaptor xpathAncestorOrSelfOf:childNode .
|
|
163 |
|
|
164 |
self assert: ancestorsCollection size = 1.
|
|
165 |
|
|
166 |
"reverse document order"
|
|
167 |
self assert:(documentAdaptor xpathIsDocument:ancestorsCollection first).
|
|
168 |
|
|
169 |
"Modified: / 02-11-2006 / 12:57:00 / ked"
|
|
170 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
171 |
"Modified: / 21-11-2006 / 23:04:10 / janfrog"
|
|
172 |
!
|
|
173 |
|
|
174 |
testAttribute
|
|
175 |
"Selects all attributes of the current node"
|
|
176 |
|
|
177 |
| childNode attributesCollection attributeNode |
|
|
178 |
|
|
179 |
childNode := self apply:#(xpathChildOf: first "root element"
|
|
180 |
xpathChildOf: first
|
|
181 |
xpathChildOf: first ).
|
|
182 |
attributesCollection := documentAdaptor xpathAttributeOf:childNode.
|
|
183 |
|
|
184 |
self assert: attributesCollection size = 2.
|
|
185 |
|
|
186 |
self assert:(attributesCollection anySatisfy:
|
|
187 |
[:node | (documentAdaptor xpathNameOf:node) = 'lang'
|
|
188 |
and:[(documentAdaptor xpathValueOf:node) = 'eng']]).
|
|
189 |
|
|
190 |
self assert:(attributesCollection anySatisfy:
|
|
191 |
[:node | (documentAdaptor xpathNameOf:node) = 'ns2:withPictures'
|
|
192 |
and:[(documentAdaptor xpathValueOf:node) = 'yes']]).
|
|
193 |
|
|
194 |
attributeNode := attributesCollection detect:
|
|
195 |
[:node | (documentAdaptor xpathNameOf:node) = 'lang'].
|
|
196 |
|
|
197 |
" TODO - nikoli podle XDM
|
|
198 |
self should: [ attributeNodeHandlingCollection := documentAdaptor xpathAncestorOf: attributeNode. ] raise: Exception.
|
|
199 |
"
|
|
200 |
" TODO - mozna ano, mozna ne
|
|
201 |
self should: [ attributeNodeHandlingCollection := documentAdaptor xpathFollowingSibling. ] raise: Exception.
|
|
202 |
"
|
|
203 |
|
|
204 |
childNode := self apply:#(xpathChildOf: first "root element"
|
|
205 |
xpathChildOf: third
|
|
206 |
xpathChildOf: first ).
|
|
207 |
|
|
208 |
|
|
209 |
"
|
|
210 |
(XQueryAccessedNode new documentAdaptor:documentAdaptor; xpathDocument)
|
|
211 |
xpathChild first item
|
|
212 |
xpathChild third item
|
|
213 |
xpathChild first item."
|
|
214 |
|
|
215 |
|
|
216 |
attributesCollection := documentAdaptor xpathAttributeOf:childNode.
|
|
217 |
|
|
218 |
self assert: attributesCollection size = 0.
|
|
219 |
|
|
220 |
"Modified: / 02-11-2006 / 12:55:40 / ked"
|
|
221 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
222 |
"Modified: / 10-12-2006 / 19:57:02 / janfrog"
|
|
223 |
!
|
|
224 |
|
|
225 |
testChild
|
|
226 |
"Selects all children of the current node"
|
|
227 |
|
|
228 |
| parentNode childrenCollection anotherChildrenCollection |
|
|
229 |
|
|
230 |
parentNode := self apply:#(
|
|
231 |
xpathChildOf: first
|
|
232 |
xpathChildOf: first
|
|
233 |
).
|
|
234 |
|
|
235 |
childrenCollection := documentAdaptor xpathChildOf:parentNode.
|
|
236 |
|
|
237 |
self assert: childrenCollection size = 4.
|
|
238 |
|
|
239 |
"document order"
|
|
240 |
self assert:(documentAdaptor xpathNameOf: childrenCollection first ) = 'title'.
|
|
241 |
self assert:(documentAdaptor xpathIsElement: childrenCollection first ).
|
|
242 |
self assert:(documentAdaptor xpathNameOf: childrenCollection second ) = 'price'.
|
|
243 |
self assert:(documentAdaptor xpathIsElement: childrenCollection second ).
|
|
244 |
self assert:(documentAdaptor xpathNameOf: childrenCollection third ) = 'parentalAdvisory'.
|
|
245 |
self assert:(documentAdaptor xpathIsElement: childrenCollection third ).
|
|
246 |
self assert:(documentAdaptor xpathNameOf: childrenCollection fourth ) = 'description'.
|
|
247 |
self assert:(documentAdaptor xpathIsElement: childrenCollection fourth).
|
|
248 |
|
|
249 |
anotherChildrenCollection := documentAdaptor xpathChildOf:childrenCollection first.
|
|
250 |
|
|
251 |
self assert: anotherChildrenCollection size = 1.
|
|
252 |
|
|
253 |
self assert:(documentAdaptor xpathValueOf: anotherChildrenCollection first) = 'Harry Potter'.
|
|
254 |
self assert:(documentAdaptor xpathIsText: anotherChildrenCollection first).
|
|
255 |
|
|
256 |
anotherChildrenCollection := documentAdaptor xpathChildOf: anotherChildrenCollection first.
|
|
257 |
|
|
258 |
self assert: anotherChildrenCollection size = 0.
|
|
259 |
|
|
260 |
anotherChildrenCollection := documentAdaptor xpathChildOf: childrenCollection fourth.
|
|
261 |
|
|
262 |
self assert: anotherChildrenCollection size = 0.
|
|
263 |
|
|
264 |
"Modified: / 02-11-2006 / 12:57:42 / ked"
|
|
265 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
266 |
"Modified: / 21-11-2006 / 23:15:30 / janfrog"
|
|
267 |
!
|
|
268 |
|
|
269 |
testDescendant
|
|
270 |
"Selects all descendants (children, grandchildren, etc.) of the current node"
|
|
271 |
|
|
272 |
| parentNode descendantsCollection anotherDescendantsCollection |
|
|
273 |
|
|
274 |
parentNode := self apply:#(
|
|
275 |
xpathChildOf: first
|
|
276 |
xpathChildOf: first
|
|
277 |
).
|
|
278 |
descendantsCollection := documentAdaptor xpathDescendantOf: parentNode.
|
|
279 |
|
|
280 |
self assert: descendantsCollection size = 7.
|
|
281 |
|
|
282 |
"document order"
|
|
283 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection first ) = 'title'.
|
|
284 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection first ).
|
|
285 |
self assert:(documentAdaptor xpathValueOf: descendantsCollection second ) = 'Harry Potter'.
|
|
286 |
self assert:(documentAdaptor xpathIsText: descendantsCollection second ).
|
|
287 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection third ) = 'price'.
|
|
288 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection third ).
|
|
289 |
self assert:(documentAdaptor xpathValueOf: descendantsCollection fourth ) = '29.99'.
|
|
290 |
self assert:(documentAdaptor xpathIsText: descendantsCollection fourth ).
|
|
291 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection fifth ) = 'parentalAdvisory'.
|
|
292 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection fifth ).
|
|
293 |
self assert:(documentAdaptor xpathValueOf: descendantsCollection sixth ) = '50+'.
|
|
294 |
self assert:(documentAdaptor xpathIsText: descendantsCollection sixth ).
|
|
295 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection seventh ) = 'description'.
|
|
296 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection seventh ).
|
|
297 |
|
|
298 |
anotherDescendantsCollection := documentAdaptor xpathDescendantOf: descendantsCollection fifth.
|
|
299 |
|
|
300 |
self assert: anotherDescendantsCollection size = 1.
|
|
301 |
|
|
302 |
anotherDescendantsCollection := documentAdaptor xpathDescendantOf:descendantsCollection sixth.
|
|
303 |
|
|
304 |
self assert: anotherDescendantsCollection size = 0.
|
|
305 |
|
|
306 |
anotherDescendantsCollection := documentAdaptor xpathDescendantOf:descendantsCollection seventh.
|
|
307 |
|
|
308 |
self assert: anotherDescendantsCollection size = 0.
|
|
309 |
|
|
310 |
"Modified: / 02-11-2006 / 12:58:07 / ked"
|
|
311 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
312 |
"Modified: / 07-12-2006 / 00:18:57 / janfrog"
|
|
313 |
!
|
|
314 |
|
|
315 |
testDescendantOrSelf
|
|
316 |
"Selects all descendants (children, grandchildren, etc.) of the current node and the current node itself"
|
|
317 |
|
|
318 |
| parentNode descendantsCollection anotherDescendantsCollection |
|
|
319 |
|
|
320 |
parentNode := self apply:#(
|
|
321 |
xpathChildOf: first
|
|
322 |
xpathChildOf: second
|
|
323 |
).
|
|
324 |
descendantsCollection := documentAdaptor xpathDescendantOrSelfOf: parentNode .
|
|
325 |
|
|
326 |
self assert: descendantsCollection size = 5.
|
|
327 |
|
|
328 |
"document order"
|
|
329 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection first) = 'book'.
|
|
330 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection first ).
|
|
331 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection second) = 'title'.
|
|
332 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection second).
|
|
333 |
self assert:(documentAdaptor xpathValueOf: descendantsCollection third) = 'Learning XML'.
|
|
334 |
self assert:(documentAdaptor xpathIsText: descendantsCollection third).
|
|
335 |
self assert:(documentAdaptor xpathNameOf: descendantsCollection fourth) = 'price'.
|
|
336 |
self assert:(documentAdaptor xpathIsElement: descendantsCollection fourth).
|
|
337 |
self assert:(documentAdaptor xpathValueOf: descendantsCollection fifth) = '39.95'.
|
|
338 |
self assert:(documentAdaptor xpathIsText: descendantsCollection fifth).
|
|
339 |
|
|
340 |
anotherDescendantsCollection := documentAdaptor xpathDescendantOrSelfOf: descendantsCollection fourth.
|
|
341 |
|
|
342 |
self assert: anotherDescendantsCollection size = 2.
|
|
343 |
|
|
344 |
anotherDescendantsCollection := documentAdaptor xpathDescendantOrSelfOf: descendantsCollection fifth.
|
|
345 |
|
|
346 |
self assert: anotherDescendantsCollection size = 1.
|
|
347 |
|
|
348 |
"Modified: / 02-11-2006 / 12:58:24 / ked"
|
|
349 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
350 |
"Modified: / 07-12-2006 / 00:22:50 / janfrog"
|
|
351 |
!
|
|
352 |
|
|
353 |
testDocument
|
|
354 |
"Retrieves document element of the document"
|
|
355 |
|
|
356 |
| document |
|
|
357 |
|
|
358 |
document := self apply:#().
|
|
359 |
|
|
360 |
self assert:(documentAdaptor xpathIsDocument:document).
|
|
361 |
|
|
362 |
"Modified: / 28-10-2006 / 23:37:11 / ked"
|
|
363 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
364 |
"Modified: / 21-11-2006 / 23:16:51 / janfrog"
|
|
365 |
!
|
|
366 |
|
|
367 |
testFollowing
|
|
368 |
"Selects everything in the document after the closing tag of the current node"
|
|
369 |
|
|
370 |
| node followingsCollection |
|
|
371 |
|
|
372 |
node := self apply:#(xpathChildOf: first
|
|
373 |
xpathChildOf: second
|
|
374 |
xpathChildOf: second ).
|
|
375 |
|
|
376 |
self assert:(documentAdaptor xpathNameOf: node) = 'price'.
|
|
377 |
self assert:(documentAdaptor xpathIsElement: node).
|
|
378 |
|
|
379 |
followingsCollection := documentAdaptor xpathFollowingOf: node.
|
|
380 |
|
|
381 |
self assert: followingsCollection size = 5.
|
|
382 |
|
|
383 |
"document order"
|
|
384 |
self assert:(documentAdaptor xpathNameOf: followingsCollection first ) = 'book'.
|
|
385 |
self assert:(documentAdaptor xpathIsElement: followingsCollection first ).
|
|
386 |
self assert:(documentAdaptor xpathNameOf: followingsCollection second) = 'title'.
|
|
387 |
self assert:(documentAdaptor xpathIsElement: followingsCollection second).
|
|
388 |
self assert:(documentAdaptor xpathValueOf: followingsCollection third) = '1984'.
|
|
389 |
self assert:(documentAdaptor xpathIsText: followingsCollection third).
|
|
390 |
self assert:(documentAdaptor xpathNameOf: followingsCollection fourth) = 'price'.
|
|
391 |
self assert:(documentAdaptor xpathIsElement: followingsCollection fourth).
|
|
392 |
self assert:(documentAdaptor xpathValueOf: followingsCollection fifth) = '19.84'.
|
|
393 |
self assert:(documentAdaptor xpathIsText: followingsCollection fifth).
|
|
394 |
|
|
395 |
node := self apply:#(xpathChildOf: first
|
|
396 |
xpathChildOf: third
|
|
397 |
xpathChildOf: second ).
|
|
398 |
|
|
399 |
"
|
|
400 |
node := (XQueryAccessedNode new documentAdaptor:documentAdaptor; xpathDocument) first item xpathChild first item xpathChild third item xpathChild second item.
|
|
401 |
"
|
|
402 |
self assert:(documentAdaptor xpathNameOf: node ) = 'price'.
|
|
403 |
self assert:(documentAdaptor xpathIsElement: node ).
|
|
404 |
|
|
405 |
followingsCollection := documentAdaptor xpathFollowingOf:node .
|
|
406 |
|
|
407 |
self assert: followingsCollection size = 0.
|
|
408 |
|
|
409 |
"Modified: / 02-11-2006 / 12:58:59 / ked"
|
|
410 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
411 |
"Modified: / 21-11-2006 / 23:33:12 / janfrog"
|
|
412 |
!
|
|
413 |
|
|
414 |
testFollowingSibling
|
|
415 |
"Selects all siblings after the current node"
|
|
416 |
|
|
417 |
| node followingSiblingsCollection anotherFollowingSiblingsCollection |
|
|
418 |
|
|
419 |
node := self apply:#(
|
|
420 |
xpathChildOf: first
|
|
421 |
xpathChildOf: first
|
|
422 |
xpathChildOf: first
|
|
423 |
).
|
|
424 |
|
|
425 |
self assert:(documentAdaptor xpathNameOf: node ) = 'title'.
|
|
426 |
self assert:(documentAdaptor xpathIsElement: node).
|
|
427 |
|
|
428 |
followingSiblingsCollection :=documentAdaptor xpathFollowingSiblingOf: node .
|
|
429 |
|
|
430 |
self assert: followingSiblingsCollection size = 3.
|
|
431 |
|
|
432 |
"document order"
|
|
433 |
self assert:(documentAdaptor xpathNameOf: followingSiblingsCollection first ) = 'price'.
|
|
434 |
self assert:(documentAdaptor xpathIsElement: followingSiblingsCollection first).
|
|
435 |
self assert:(documentAdaptor xpathNameOf: followingSiblingsCollection second ) = 'parentalAdvisory'.
|
|
436 |
self assert:(documentAdaptor xpathIsElement: followingSiblingsCollection second).
|
|
437 |
self assert:(documentAdaptor xpathNameOf: followingSiblingsCollection third ) = 'description'.
|
|
438 |
self assert:(documentAdaptor xpathIsElement: followingSiblingsCollection third).
|
|
439 |
|
|
440 |
anotherFollowingSiblingsCollection := documentAdaptor xpathFollowingSiblingOf: followingSiblingsCollection third .
|
|
441 |
|
|
442 |
self assert: anotherFollowingSiblingsCollection size = 0.
|
|
443 |
|
|
444 |
"Modified: / 02-11-2006 / 13:29:37 / ked"
|
|
445 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
446 |
"Modified: / 07-12-2006 / 00:27:22 / janfrog"
|
|
447 |
!
|
|
448 |
|
|
449 |
testParent
|
|
450 |
"Selects the parent of the current node"
|
|
451 |
|
|
452 |
| childrenCollection parentNode documentNode |
|
|
453 |
|
|
454 |
childrenCollection := self apply:#(xpathChildOf: first
|
|
455 |
xpathChildOf: ).
|
|
456 |
parentNode := documentAdaptor xpathParentOf:childrenCollection first.
|
|
457 |
|
|
458 |
self assert:(documentAdaptor xpathIsElement:parentNode).
|
|
459 |
self assert:(documentAdaptor xpathNameOf: parentNode) = 'bookstore'.
|
|
460 |
|
|
461 |
"parentNode := dataAccessor to: childrenCollection apply:#(first getChildPointersOf: first getChildPointersOf: first getParentPointerOf:)."
|
|
462 |
|
|
463 |
parentNode := self apply:#(xpathChildOf: first
|
|
464 |
xpathChildOf: first
|
|
465 |
xpathChildOf: first).
|
|
466 |
|
|
467 |
|
|
468 |
self assert:(documentAdaptor xpathIsElement:parentNode).
|
|
469 |
self assert:(documentAdaptor xpathNameOf: parentNode) = 'title'.
|
|
470 |
|
|
471 |
documentNode := self apply:#().
|
|
472 |
parentNode := documentAdaptor xpathParentOf:documentNode .
|
|
473 |
|
|
474 |
self assert: parentNode isNil
|
|
475 |
|
|
476 |
"Modified: / 02-11-2006 / 13:29:52 / ked"
|
|
477 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
478 |
"Modified: / 21-11-2006 / 23:23:21 / janfrog"
|
|
479 |
!
|
|
480 |
|
|
481 |
testPreceding
|
|
482 |
"Selects everything in the document that is before the start tag of the current node"
|
|
483 |
|
|
484 |
| node precedingsCollection |
|
|
485 |
|
|
486 |
node := self apply:#(xpathChildOf: first
|
|
487 |
xpathChildOf: second
|
|
488 |
xpathChildOf: second).
|
|
489 |
|
|
490 |
self assert:(documentAdaptor xpathNameOf: node) = 'price'.
|
|
491 |
self assert:(documentAdaptor xpathIsElement: node).
|
|
492 |
|
|
493 |
precedingsCollection := documentAdaptor xpathPrecedingOf: node.
|
|
494 |
|
|
495 |
self assert: precedingsCollection size = 10.
|
|
496 |
|
|
497 |
"document order"
|
|
498 |
self assert:(documentAdaptor xpathNameOf: precedingsCollection first) = 'title'.
|
|
499 |
self assert:(documentAdaptor xpathIsElement: precedingsCollection first).
|
|
500 |
self assert:(documentAdaptor xpathValueOf: precedingsCollection second) = 'Learning XML'.
|
|
501 |
self assert:(documentAdaptor xpathIsText: precedingsCollection second).
|
|
502 |
self assert:(documentAdaptor xpathNameOf: precedingsCollection third) = 'book'.
|
|
503 |
self assert:(documentAdaptor xpathIsElement: precedingsCollection third).
|
|
504 |
self assert:(documentAdaptor xpathNameOf: precedingsCollection fourth) = 'title'.
|
|
505 |
self assert:(documentAdaptor xpathIsElement: precedingsCollection fourth).
|
|
506 |
self assert:(documentAdaptor xpathValueOf: precedingsCollection fifth) = 'Harry Potter'.
|
|
507 |
self assert:(documentAdaptor xpathIsText: precedingsCollection fifth).
|
|
508 |
self assert:(documentAdaptor xpathNameOf: precedingsCollection sixth) = 'price'.
|
|
509 |
self assert:(documentAdaptor xpathIsElement: precedingsCollection sixth).
|
|
510 |
self assert:(documentAdaptor xpathValueOf: precedingsCollection seventh) = '29.99'.
|
|
511 |
self assert:(documentAdaptor xpathIsText: precedingsCollection seventh).
|
|
512 |
self assert:(documentAdaptor xpathNameOf: (precedingsCollection at:8)) = 'parentalAdvisory'.
|
|
513 |
self assert:(documentAdaptor xpathIsElement: (precedingsCollection at:8)).
|
|
514 |
self assert:(documentAdaptor xpathValueOf: (precedingsCollection at:9)) = '50+'.
|
|
515 |
self assert:(documentAdaptor xpathIsText: (precedingsCollection at:9)).
|
|
516 |
self assert:(documentAdaptor xpathNameOf: (precedingsCollection at:10)) = 'description'.
|
|
517 |
self assert:(documentAdaptor xpathIsElement: (precedingsCollection at:10)).
|
|
518 |
|
|
519 |
node := self apply:#().
|
|
520 |
precedingsCollection := documentAdaptor xpathPrecedingOf: node .
|
|
521 |
|
|
522 |
self assert: precedingsCollection size = 0.
|
|
523 |
|
|
524 |
node := (documentAdaptor xpathChildOf:node) first .
|
|
525 |
precedingsCollection := documentAdaptor xpathPrecedingOf: node.
|
|
526 |
|
|
527 |
self assert: precedingsCollection size = 0.
|
|
528 |
|
|
529 |
"Modified: / 02-11-2006 / 13:52:09 / ked"
|
|
530 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
531 |
"Modified: / 07-12-2006 / 00:34:56 / janfrog"
|
|
532 |
!
|
|
533 |
|
|
534 |
testPrecedingSibling
|
|
535 |
"Selects all siblings before the current node"
|
|
536 |
|
|
537 |
| node precedingSiblingsCollection |
|
|
538 |
|
|
539 |
node := self apply:#(xpathChildOf: first
|
|
540 |
xpathChildOf: second
|
|
541 |
xpathChildOf: second).
|
|
542 |
|
|
543 |
|
|
544 |
self assert:(documentAdaptor xpathNameOf: node) = 'price'.
|
|
545 |
self assert:(documentAdaptor xpathIsElement: node).
|
|
546 |
|
|
547 |
precedingSiblingsCollection := documentAdaptor xpathPrecedingSiblingOf: node.
|
|
548 |
|
|
549 |
self assert: precedingSiblingsCollection size = 1.
|
|
550 |
|
|
551 |
self assert:(documentAdaptor xpathNameOf: precedingSiblingsCollection first ) = 'title'.
|
|
552 |
self assert:(documentAdaptor xpathIsElement: precedingSiblingsCollection first).
|
|
553 |
|
|
554 |
node := self apply:#().
|
|
555 |
precedingSiblingsCollection := documentAdaptor xpathPrecedingSiblingOf: node.
|
|
556 |
|
|
557 |
self assert: precedingSiblingsCollection size = 0.
|
|
558 |
|
|
559 |
node := (documentAdaptor xpathChildOf: node) first.
|
|
560 |
precedingSiblingsCollection := documentAdaptor xpathPrecedingSiblingOf: node.
|
|
561 |
|
|
562 |
self assert: precedingSiblingsCollection size = 0.
|
|
563 |
|
|
564 |
"Modified: / 02-11-2006 / 13:52:32 / ked"
|
|
565 |
"Created: / 16-11-2006 / 23:08:32 / janfrog"
|
|
566 |
"Modified: / 07-12-2006 / 00:37:36 / janfrog"
|
|
567 |
! !
|
|
568 |
|
|
569 |
!XPathDocumentAdaptorTests methodsFor:'tests - xpath values'!
|
|
570 |
|
|
571 |
testLocalName
|
|
572 |
|
|
573 |
| node |
|
|
574 |
node := self apply:#(xpathChildOf: first).
|
|
575 |
|
|
576 |
self assert:(documentAdaptor xpathLocalNameOf:node) = 'bookstore'.
|
|
577 |
|
|
578 |
|
|
579 |
node := self apply:#(xpathChildOf: first
|
|
580 |
xpathChildOf: first
|
|
581 |
xpathChildOf: first
|
|
582 |
xpathAttributeOf: second).
|
|
583 |
|
|
584 |
self assert:(documentAdaptor xpathLocalNameOf:node) = 'withPictures'.
|
|
585 |
|
|
586 |
"Created: / 10-12-2006 / 19:57:58 / janfrog"
|
|
587 |
!
|
|
588 |
|
|
589 |
testNamespace
|
|
590 |
|
|
591 |
| node |
|
|
592 |
node := self apply:#(xpathChildOf: first).
|
|
593 |
|
|
594 |
self assert:(documentAdaptor xpathNamespaceOf:node) = 'urn:xmlsuite:bookstore:ns'.
|
|
595 |
|
|
596 |
node := self apply:#(xpathChildOf: first
|
|
597 |
xpathChildOf: first
|
|
598 |
xpathChildOf: first
|
|
599 |
xpathAttributeOf: second).
|
|
600 |
|
|
601 |
self assert:(documentAdaptor xpathNamespaceOf:node) = 'urn:xmlsuite:bookstore:ns2'.
|
|
602 |
|
|
603 |
"Created: / 10-12-2006 / 19:59:19 / janfrog"
|
|
604 |
! !
|
|
605 |
|
|
606 |
!XPathDocumentAdaptorTests class methodsFor:'documentation'!
|
|
607 |
|
|
608 |
version
|
|
609 |
^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/xpath/XMLv2__XPathDocumentAdaptorTests.st,v 1.5 2007-10-31 09:38:48 vranyj1 Exp $'
|
|
610 |
! !
|