KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jaxen > XPathTestBase


1 /*
2  * $Header: /home/projects/jaxen/scm/jaxen/src/java/test/org/jaxen/XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $
3  * $Revision: 1.36 $
4  * $Date: 2005/06/17 13:22:31 $
5  *
6  * ====================================================================
7  *
8  * Copyright (C) 2000-2002 bob mcwhirter & James Strachan.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  *
15  * 1. Redistributions of source code must retain the above copyright
16  * notice, this list of conditions, and the following disclaimer.
17  *
18  * 2. Redistributions in binary form must reproduce the above copyright
19  * notice, this list of conditions, and the disclaimer that follows
20  * these conditions in the documentation and/or other materials
21  * provided with the distribution.
22  *
23  * 3. The name "Jaxen" must not be used to endorse or promote products
24  * derived from this software without prior written permission. For
25  * written permission, please contact license@jaxen.org.
26  *
27  * 4. Products derived from this software may not be called "Jaxen", nor
28  * may "Jaxen" appear in their name, without prior written permission
29  * from the Jaxen Project Management (pm@jaxen.org).
30  *
31  * In addition, we request (but do not require) that you include in the
32  * end-user documentation provided with the redistribution and/or in the
33  * software itself an acknowledgement equivalent to the following:
34  * "This product includes software developed by the
35  * Jaxen Project (http://www.jaxen.org/)."
36  * Alternatively, the acknowledgment may be graphical using the logos
37  * available at http://www.jaxen.org/
38  *
39  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42  * DISCLAIMED. IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
43  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * ====================================================================
53  * This software consists of voluntary contributions made by many
54  * individuals on behalf of the Jaxen Project and was originally
55  * created by bob mcwhirter <bob@werken.com> and
56  * James Strachan <jstrachan@apache.org>. For more information on the
57  * Jaxen Project, please see <http://www.jaxen.org/>.
58  *
59  * $Id: XPathTestBase.java,v 1.36 2005/06/17 13:22:31 elharo Exp $
60  */

61
62
63 package org.jaxen;
64
65 import junit.framework.TestCase;
66 import org.jaxen.function.StringFunction;
67 import org.jaxen.saxpath.helpers.XPathReaderFactory;
68 import org.jaxen.pattern.Pattern;
69
70 import java.util.ArrayList JavaDoc;
71 import java.util.Iterator JavaDoc;
72 import java.util.List JavaDoc;
73
74 public abstract class XPathTestBase extends TestCase
75 {
76     protected static String JavaDoc VAR_URI = "http://jaxen.org/test-harness/var";
77     protected static String JavaDoc TESTS_XML = "xml/test/tests.xml";
78
79     protected static boolean verbose = false;
80     protected static boolean debug = false;
81     private ContextSupport contextSupport;
82
83     public XPathTestBase(String JavaDoc name)
84     {
85         super(name);
86     }
87
88     public void setUp()
89     {
90         this.contextSupport = null;
91         System.setProperty(XPathReaderFactory.DRIVER_PROPERTY,
92                 "");
93         log("-----------------------------");
94     }
95
96     public void log(String JavaDoc text)
97     {
98         log(verbose,
99                 text);
100     }
101
102     public void log(boolean actualVerbose,
103                     String JavaDoc text)
104     {
105         if (actualVerbose) System.out.println(text);
106     }
107
108     protected void assertCountXPath(int expectedSize, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
109     {
110         assertCountXPath2(expectedSize, context, xpathStr);
111     }
112
113     protected Object JavaDoc assertCountXPath2(int expectedSize, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
114     {
115         log(debug,
116                 " Select :: " + xpathStr);
117         BaseXPath xpath = new BaseXPath(xpathStr);
118         List JavaDoc results = xpath.selectNodes(getContext(context));
119         log(debug,
120                 " Expected Size :: " + expectedSize);
121         log(debug,
122                 " Result Size :: " + results.size());
123         if (expectedSize != results.size())
124         {
125             log(debug,
126                     " ## FAILED");
127             log(debug,
128                     " ## xpath: " + xpath + " = " + xpath.debug());
129             Iterator JavaDoc resultIter = results.iterator();
130             while (resultIter.hasNext())
131             {
132                 log(debug,
133                         " --> " + resultIter.next());
134             }
135         }
136         assertEquals(xpathStr,
137                 expectedSize,
138                 results.size());
139         if (expectedSize > 0)
140         {
141             return results.get(0);
142         }
143         return null;
144     }
145
146     protected void assertInvalidXPath(Object JavaDoc context, String JavaDoc xpathStr)
147     {
148         try
149         {
150             log(debug,
151                     " Select :: " + xpathStr);
152             BaseXPath xpath = new BaseXPath(xpathStr);
153             List JavaDoc results = xpath.selectNodes(getContext(context));
154             log(debug,
155                     " Result Size :: " + results.size());
156             fail("An exception was expected.");
157         }
158         catch (UnsupportedAxisException e)
159         {
160             log(debug,
161                     " ## SKIPPED -- Unsupported Axis");
162         }
163         catch (JaxenException e)
164         {
165             log(debug, " Caught expected exception " + e.getMessage());
166         }
167     }
168
169     protected void assertValueOfXPath(String JavaDoc expected, Object JavaDoc context, String JavaDoc xpathStr) throws JaxenException
170     {
171         try
172         {
173             BaseXPath xpath = new BaseXPath(xpathStr);
174             Object JavaDoc node = xpath.evaluate(getContext(context));
175             String JavaDoc result = StringFunction.evaluate(node,
176                     getNavigator());
177             log(debug,
178                     " Select :: " + xpathStr);
179             log(debug,
180                     " Expected :: " + expected);
181             log(debug,
182                     " Result :: " + result);
183             if (!expected.equals(result))
184             {
185                 log(debug,
186                         " ## FAILED");
187                 log(debug,
188                         " ## xpath: " + xpath + " = " + xpath.debug());
189             }
190             assertEquals(xpathStr,
191                     expected,
192                     result);
193         }
194         catch (UnsupportedAxisException e)
195         {
196             log(debug,
197                     " ## SKIPPED -- Unsupported Axis ");
198         }
199     }
200
201     protected Context getContext(Object JavaDoc contextNode)
202     {
203         Context context = new Context(getContextSupport());
204         List JavaDoc list = new ArrayList JavaDoc(1);
205         list.add(contextNode);
206         context.setNodeSet(list);
207         return context;
208     }
209
210     public ContextSupport getContextSupport()
211     {
212         if (this.contextSupport == null)
213         {
214             this.contextSupport = new ContextSupport(new SimpleNamespaceContext(),
215                     XPathFunctionContext.getInstance(),
216                     new SimpleVariableContext(),
217                     getNavigator());
218         }
219         return this.contextSupport;
220     }
221
222     public abstract Navigator getNavigator();
223
224     public abstract Object JavaDoc getDocument(String JavaDoc url) throws Exception JavaDoc;
225
226     public void testGetNodeType() throws FunctionCallException, UnsupportedAxisException
227     {
228         Navigator nav = getNavigator();
229         Object JavaDoc document = nav.getDocument("xml/testNamespaces.xml");
230         int count = 0;
231         Iterator JavaDoc descendantOrSelfAxisIterator = nav.getDescendantOrSelfAxisIterator(document);
232         while (descendantOrSelfAxisIterator.hasNext())
233         {
234             Object JavaDoc node = descendantOrSelfAxisIterator.next();
235             Iterator JavaDoc namespaceAxisIterator = nav.getNamespaceAxisIterator(node);
236             while (namespaceAxisIterator.hasNext())
237             {
238                 count++;
239                 assertEquals("Node type mismatch", Pattern.NAMESPACE_NODE, nav.getNodeType(namespaceAxisIterator.next()));
240             }
241         }
242         assertEquals(25, count);
243     }
244
245
246     /* test for jaxen-24
247     */

248     public void testid53371() throws JaxenException
249     {
250         Navigator nav = getNavigator();
251         String JavaDoc url = "xml/jaxen24.xml";
252         log("Document [" + url + "]");
253         Object JavaDoc document = nav.getDocument(url);
254         XPath contextpath = new BaseXPath("/body/div", nav);
255         log("Initial Context :: " + contextpath);
256         List JavaDoc list = contextpath.selectNodes(document);
257         Iterator JavaDoc iter = list.iterator();
258         while (iter.hasNext())
259         {
260             Object JavaDoc context = iter.next();
261             assertCountXPath(1, context, "preceding::*[1]");
262             assertValueOfXPath("span", context, "local-name(preceding::*[1])");
263         }
264     }
265
266     /* jaxen-58
267     */

268     public void testid53391() throws JaxenException
269     {
270         Navigator nav = getNavigator();
271         String JavaDoc url = "xml/jaxen24.xml";
272         log("Document [" + url + "]");
273         Object JavaDoc document = nav.getDocument(url);
274         XPath contextpath = new BaseXPath("/", nav);
275         log("Initial Context :: " + contextpath);
276         List JavaDoc list = contextpath.selectNodes(document);
277         Iterator JavaDoc iter = list.iterator();
278         while (iter.hasNext())
279         {
280             Object JavaDoc context = iter.next();
281             assertCountXPath(0, context, "//preceding::x");
282             assertCountXPath(0, context, "//following::x");
283             assertCountXPath(0, context, "/descendant::*/preceding::x");
284             assertCountXPath(0, context, "/descendant::node()/preceding::x");
285         }
286     }
287
288     /* test for jaxen-3
289     */

290     public void testid53430() throws JaxenException
291     {
292         Navigator nav = getNavigator();
293         String JavaDoc url = "xml/simple.xml";
294         log("Document [" + url + "]");
295         Object JavaDoc document = nav.getDocument(url);
296         XPath contextpath = new BaseXPath("/", nav);
297         log("Initial Context :: " + contextpath);
298         List JavaDoc list = contextpath.selectNodes(document);
299         Iterator JavaDoc iter = list.iterator();
300         while (iter.hasNext())
301         {
302             Object JavaDoc context = iter.next();
303             assertValueOfXPath("abd", context, "string()");
304         }
305     }
306
307     public void testid53441() throws JaxenException
308     {
309         Navigator nav = getNavigator();
310         String JavaDoc url = "xml/simple.xml";
311         log("Document [" + url + "]");
312         Object JavaDoc document = nav.getDocument(url);
313         XPath contextpath = new BaseXPath("/root", nav);
314         log("Initial Context :: " + contextpath);
315         List JavaDoc list = contextpath.selectNodes(document);
316         Iterator JavaDoc iter = list.iterator();
317         while (iter.hasNext())
318         {
319             Object JavaDoc context = iter.next();
320             assertValueOfXPath("abd", context, "string()");
321         }
322     }
323
324     public void testid53452() throws JaxenException
325     {
326         Navigator nav = getNavigator();
327         String JavaDoc url = "xml/simple.xml";
328         log("Document [" + url + "]");
329         Object JavaDoc document = nav.getDocument(url);
330         XPath contextpath = new BaseXPath("/root/a", nav);
331         log("Initial Context :: " + contextpath);
332         List JavaDoc list = contextpath.selectNodes(document);
333         Iterator JavaDoc iter = list.iterator();
334         while (iter.hasNext())
335         {
336             Object JavaDoc context = iter.next();
337             assertValueOfXPath("a", context, "string()");
338         }
339     }
340
341     public void testid53463() throws JaxenException
342     {
343         Navigator nav = getNavigator();
344         String JavaDoc url = "xml/simple.xml";
345         log("Document [" + url + "]");
346         Object JavaDoc document = nav.getDocument(url);
347         XPath contextpath = new BaseXPath("/root/c", nav);
348         log("Initial Context :: " + contextpath);
349         List JavaDoc list = contextpath.selectNodes(document);
350         Iterator JavaDoc iter = list.iterator();
351         while (iter.hasNext())
352         {
353             Object JavaDoc context = iter.next();
354             assertValueOfXPath("d", context, "string()");
355         }
356     }
357
358     /* test for jaxen-3
359     */

360     public void testid53482() throws JaxenException
361     {
362         Navigator nav = getNavigator();
363         String JavaDoc url = "xml/jaxen3.xml";
364         log("Document [" + url + "]");
365         Object JavaDoc document = nav.getDocument(url);
366         XPath contextpath = new BaseXPath("/", nav);
367         log("Initial Context :: " + contextpath);
368         List JavaDoc list = contextpath.selectNodes(document);
369         Iterator JavaDoc iter = list.iterator();
370         while (iter.hasNext())
371         {
372             Object JavaDoc context = iter.next();
373             assertCountXPath(1, context, "/Configuration/hostname/attrlist/hostname[. = 'CE-A'] ");
374         }
375     }
376
377     /* parser test cases all of which should fail
378     */

379     public void testid53502() throws JaxenException
380     {
381         Navigator nav = getNavigator();
382         String JavaDoc url = "xml/numbers.xml";
383         log("Document [" + url + "]");
384         Object JavaDoc document = nav.getDocument(url);
385         XPath contextpath = new BaseXPath("/", nav);
386         log("Initial Context :: " + contextpath);
387         List JavaDoc list = contextpath.selectNodes(document);
388         Iterator JavaDoc iter = list.iterator();
389         while (iter.hasNext())
390         {
391             Object JavaDoc context = iter.next();
392             /* repeated xpaths, jaxen-35
393             */

394             assertInvalidXPath(context, "/numbers numbers");
395             /* invalid xpath, jaxen-34
396             */

397             assertInvalidXPath(context, "/a/b[c > d]efg");
398             /* invalid xpath, jaxen-27
399             */

400             assertInvalidXPath(context, "/inv/child::");
401             /* invalid xpath, jaxen-26
402             */

403             assertInvalidXPath(context, "/invoice/@test[abcd");
404             assertInvalidXPath(context, "/invoice/@test[abcd > x");
405             /* unterminated string
406             */

407             assertInvalidXPath(context, "string-length('a");
408             /* various edge cases where code threw no exception
409             */

410             assertInvalidXPath(context, "/descendant::()");
411             assertInvalidXPath(context, "(1 + 1");
412         }
413     }
414
415     /* test cases for the use of underscores in names
416     */

417     public void testid53602() throws JaxenException
418     {
419         Navigator nav = getNavigator();
420         String JavaDoc url = "xml/underscore.xml";
421         log("Document [" + url + "]");
422         Object JavaDoc document = nav.getDocument(url);
423         XPath contextpath = new BaseXPath("/", nav);
424         log("Initial Context :: " + contextpath);
425         List JavaDoc list = contextpath.selectNodes(document);
426         Iterator JavaDoc iter = list.iterator();
427         while (iter.hasNext())
428         {
429             Object JavaDoc context = iter.next();
430             assertCountXPath(1, context, "/root/@a");
431             assertCountXPath(1, context, "/root/@_a");
432             assertCountXPath(1, context, "/root/b");
433             assertCountXPath(1, context, "/root/_b");
434             assertValueOfXPath("1", context, "/root/@a");
435             assertValueOfXPath("2", context, "/root/@_a");
436             assertValueOfXPath("1", context, "/root/b");
437             assertValueOfXPath("2", context, "/root/_b");
438         }
439     }
440
441     /* test cases for the use of = with node-sets
442     */

443     public void testid53662() throws JaxenException
444     {
445         Navigator nav = getNavigator();
446         String JavaDoc url = "xml/web.xml";
447         log("Document [" + url + "]");
448         Object JavaDoc document = nav.getDocument(url);
449         XPath contextpath = new BaseXPath("/", nav);
450         log("Initial Context :: " + contextpath);
451         List JavaDoc list = contextpath.selectNodes(document);
452         Iterator JavaDoc iter = list.iterator();
453         while (iter.hasNext())
454         {
455             Object JavaDoc context = iter.next();
456             assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'file'");
457             assertValueOfXPath("true", context, "/web-app/servlet/servlet-name = 'snoop'");
458         }
459     }
460
461     public void testid53685() throws JaxenException
462     {
463         Navigator nav = getNavigator();
464         String JavaDoc url = "xml/numbers.xml";
465         log("Document [" + url + "]");
466         Object JavaDoc document = nav.getDocument(url);
467         XPath contextpath = new BaseXPath("/", nav);
468         log("Initial Context :: " + contextpath);
469         List JavaDoc list = contextpath.selectNodes(document);
470         Iterator JavaDoc iter = list.iterator();
471         while (iter.hasNext())
472         {
473             Object JavaDoc context = iter.next();
474             assertValueOfXPath("true", context, "/numbers/set/nr = '-3'");
475             assertValueOfXPath("true", context, "/numbers/set/nr = -3");
476             assertValueOfXPath("true", context, "/numbers/set/nr = 24");
477             assertValueOfXPath("true", context, "/numbers/set/nr/@value = '9999'");
478             assertValueOfXPath("true", context, "/numbers/set/nr/@value = 9999.0");
479             assertValueOfXPath("true", context, "/numbers/set/nr/@value = 66");
480         }
481     }
482
483     /* test basic math...
484     */

485     public void testid53733() throws JaxenException
486     {
487         Navigator nav = getNavigator();
488         String JavaDoc url = "xml/numbers.xml";
489         log("Document [" + url + "]");
490         Object JavaDoc document = nav.getDocument(url);
491         XPath contextpath = new BaseXPath("/", nav);
492         log("Initial Context :: " + contextpath);
493         List JavaDoc list = contextpath.selectNodes(document);
494         Iterator JavaDoc iter = list.iterator();
495         while (iter.hasNext())
496         {
497             Object JavaDoc context = iter.next();
498             assertValueOfXPath("true", context, "(8 * 2 + 1) = 17");
499             assertValueOfXPath("true", context, "(1 + 8 * 2) = 17");
500             assertValueOfXPath("true", context, "(7 - 3 + 1) = 5");
501             assertValueOfXPath("true", context, "(8 - 4 + 5 - 6) = 3");
502             /* left-assoc tests, comments show WRONG evaluation
503             */

504             /* 3 - 2 - 1 != 2
505             */

506             assertValueOfXPath("0", context, "3 - 2 - 1");
507             /* 8 div 4 div 2 != 4
508             */

509             assertValueOfXPath("1", context, "8 div 4 div 2");
510             /* 3 mod 5 mod 7 != 1
511             */

512             assertValueOfXPath("3", context, "3 mod 7 mod 5");
513             /* 1=(2=2) is true
514             */

515             assertValueOfXPath("false", context, "1 = 2 = 2");
516             /* 2!=(3!=1) => 2!=1 => true, (2!=3)!=1 => 1!=1 => false
517             */

518             assertValueOfXPath("false", context, "2 != 3 != 1");
519             /* 3 > (2 > 1) is true
520             */

521             assertValueOfXPath("false", context, "3 > 2 > 1");
522             /* 3 >= (2 >= 2) is true
523             */

524             assertValueOfXPath("false", context, "3 >= 2 >= 2");
525             /* 1 < (2 < 3) is false
526             */

527             assertValueOfXPath("true", context, "1 < 2 < 3");
528             /* 0 <= (2 <= 3) is true
529             */

530             assertValueOfXPath("true", context, "2 <= 2 <= 3");
531         }
532     }
533
534     /* test cases for preceding axis with different node types
535     */

536     public void testid53850() throws JaxenException
537     {
538         Navigator nav = getNavigator();
539         String JavaDoc url = "xml/pi2.xml";
540         log("Document [" + url + "]");
541         Object JavaDoc document = nav.getDocument(url);
542         XPath contextpath = new BaseXPath("/a/c", nav);
543         log("Initial Context :: " + contextpath);
544         List JavaDoc list = contextpath.selectNodes(document);
545         Iterator JavaDoc iter = list.iterator();
546         while (iter.hasNext())
547         {
548             Object JavaDoc context = iter.next();
549             assertCountXPath(1, context, "//processing-instruction()");
550             assertCountXPath(1, context, "preceding-sibling::*");
551             assertCountXPath(5, context, "preceding-sibling::node()");
552             assertCountXPath(1, context, "preceding-sibling::*[1]");
553             assertCountXPath(1, context, "preceding-sibling::processing-instruction()");
554             assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::processing-instruction()");
555             assertValueOfXPath("foo", context, "preceding-sibling::*[1]");
556             assertValueOfXPath("order-by=\"x\"", context, "preceding-sibling::node()[2]");
557         }
558     }
559
560     public void testid53911() throws JaxenException
561     {
562         Navigator nav = getNavigator();
563         String JavaDoc url = "xml/id.xml";
564         log("Document [" + url + "]");
565         Object JavaDoc document = nav.getDocument(url);
566         XPath contextpath = new BaseXPath("/", nav);
567         log("Initial Context :: " + contextpath);
568         List JavaDoc list = contextpath.selectNodes(document);
569         SimpleVariableContext varContext = new SimpleVariableContext();
570         varContext.setVariableValue(null, "foobar", "foobar");
571         varContext.setVariableValue(null, "foo", "foo");
572         getContextSupport().setVariableContext(varContext);
573         Iterator JavaDoc iter = list.iterator();
574         while (iter.hasNext())
575         {
576             Object JavaDoc context = iter.next();
577             assertValueOfXPath("foobar", context, "$foobar");
578             assertCountXPath(1, context, "/foo[@id=$foobar]");
579             assertCountXPath(0, context, "/foo[@id='$foobar']");
580             assertCountXPath(1, context, "/foo[concat($foo, 'bar')=@id]");
581             assertCountXPath(0, context, "CD_Library/artist[@name=$artist]");
582         }
583     }
584
585     public void testid53957() throws JaxenException
586     {
587         Navigator nav = getNavigator();
588         String JavaDoc url = "xml/id.xml";
589         log("Document [" + url + "]");
590         Object JavaDoc document = nav.getDocument(url);
591         XPath contextpath = new BaseXPath("/", nav);
592         log("Initial Context :: " + contextpath);
593         List JavaDoc list = contextpath.selectNodes(document);
594         Iterator JavaDoc iter = list.iterator();
595         while (iter.hasNext())
596         {
597             Object JavaDoc context = iter.next();
598             /* attributes have a parent: their element
599             */

600             assertCountXPath(1, context, "/foo/@id/parent::foo");
601         }
602     }
603
604     /* attributes can also be used as context nodes
605     */

606     public void testid53975() throws JaxenException
607     {
608         Navigator nav = getNavigator();
609         String JavaDoc url = "xml/id.xml";
610         log("Document [" + url + "]");
611         Object JavaDoc document = nav.getDocument(url);
612         XPath contextpath = new BaseXPath("/foo/@id", nav);
613         log("Initial Context :: " + contextpath);
614         List JavaDoc list = contextpath.selectNodes(document);
615         Iterator JavaDoc iter = list.iterator();
616         while (iter.hasNext())
617         {
618             Object JavaDoc context = iter.next();
619             assertCountXPath(1, context, "parent::foo");
620         }
621     }
622
623     public void testid53992() throws JaxenException
624     {
625         Navigator nav = getNavigator();
626         String JavaDoc url = "xml/pi.xml";
627         log("Document [" + url + "]");
628         Object JavaDoc document = nav.getDocument(url);
629         XPath contextpath = new BaseXPath("/", nav);
630         log("Initial Context :: " + contextpath);
631         List JavaDoc list = contextpath.selectNodes(document);
632         Iterator JavaDoc iter = list.iterator();
633         while (iter.hasNext())
634         {
635             Object JavaDoc context = iter.next();
636             assertCountXPath(3, context, "//processing-instruction()");
637             assertCountXPath(2, context, "//processing-instruction('cheese')");
638             try
639             {
640                 Object JavaDoc result = assertCountXPath2(1, context, "//processing-instruction('toast')");
641                 assertValueOfXPath("is tasty", result, "string()");
642             }
643             catch (UnsupportedAxisException e)
644             {
645                 log(debug, " ## SKIPPED -- Unsupported Axis");
646             }
647         }
648     }
649
650     /* test evaluate() extension function
651     */

652     public void testid54032() throws JaxenException
653     {
654         Navigator nav = getNavigator();
655         String JavaDoc url = "xml/evaluate.xml";
656         log("Document [" + url + "]");
657         Object JavaDoc document = nav.getDocument(url);
658         XPath contextpath = new BaseXPath("/", nav);
659         log("Initial Context :: " + contextpath);
660         List JavaDoc list = contextpath.selectNodes(document);
661         Iterator JavaDoc iter = list.iterator();
662         while (iter.hasNext())
663         {
664             Object JavaDoc context = iter.next();
665             assertCountXPath(3, context, "evaluate('//jumps/*')");
666             assertCountXPath(1, context, "evaluate('//jumps/object/dog')");
667             assertCountXPath(0, context, "evaluate('//jumps/object')/evaluate");
668             assertCountXPath(1, context, "evaluate('//jumps/object')/dog");
669             assertCountXPath(1, context, "evaluate('//jumps/*')/dog");
670             assertCountXPath(1, context, "//metatest[ evaluate(@select) = . ]");
671         }
672     }
673
674     public void testid54082() throws JaxenException
675     {
676         Navigator nav = getNavigator();
677         String JavaDoc url = "xml/numbers.xml";
678         log("Document [" + url + "]");
679         Object JavaDoc document = nav.getDocument(url);
680         XPath contextpath = new BaseXPath("/numbers/set[1]", nav);
681         log("Initial Context :: " + contextpath);
682         List JavaDoc list = contextpath.selectNodes(document);
683         Iterator JavaDoc iter = list.iterator();
684         while (iter.hasNext())
685         {
686             Object JavaDoc context = iter.next();
687             assertCountXPath(1, context, "*[-3 = .]");
688             assertValueOfXPath("true", context, "54 < *");
689             assertValueOfXPath("true", context, "55 <= *");
690             assertValueOfXPath("false", context, "69 < *");
691             assertValueOfXPath("true", context, "-2 > *");
692             assertValueOfXPath("true", context, "-3 >= *");
693             assertValueOfXPath("false", context, "-4 >= *");
694         }
695     }
696
697     /* TODO
698     This context should work, but needs a fixed version of saxpath to parse the right-hand side
699     of the greater-than expression.
700     <context select="/numbers/set[2]">
701       <valueOf select="1 &gt; nr/@value">false</valueOf>
702       <valueOf select="55 &gt; nr/@value">false</valueOf>
703       <valueOf select="55 &gt;= nr/@value">true</valueOf>
704       <valueOf select="1000000 &gt; nr/@value">true</valueOf>
705     </context>
706     
707     */

708     /* test sibling axes
709     */

710     public void testid54145() throws JaxenException
711     {
712         Navigator nav = getNavigator();
713         String JavaDoc url = "xml/axis.xml";
714         log("Document [" + url + "]");
715         Object JavaDoc document = nav.getDocument(url);
716         XPath contextpath = new BaseXPath("/root", nav);
717         log("Initial Context :: " + contextpath);
718         List JavaDoc list = contextpath.selectNodes(document);
719         Iterator JavaDoc iter = list.iterator();
720         while (iter.hasNext())
721         {
722             Object JavaDoc context = iter.next();
723             assertCountXPath(0, context, "preceding-sibling::*");
724         }
725     }
726
727     public void testid54156() throws JaxenException
728     {
729         Navigator nav = getNavigator();
730         String JavaDoc url = "xml/axis.xml";
731         log("Document [" + url + "]");
732         Object JavaDoc document = nav.getDocument(url);
733         XPath contextpath = new BaseXPath("/root/a/a.3", nav);
734         log("Initial Context :: " + contextpath);
735         List JavaDoc list = contextpath.selectNodes(document);
736         Iterator JavaDoc iter = list.iterator();
737         while (iter.hasNext())
738         {
739             Object JavaDoc context = iter.next();
740             assertCountXPath(2, context, "preceding::*");
741         }
742     }
743
744     public void testid54168() throws JaxenException
745     {
746         Navigator nav = getNavigator();
747         String JavaDoc url = "xml/axis.xml";
748         log("Document [" + url + "]");
749         Object JavaDoc document = nav.getDocument(url);
750         XPath contextpath = new BaseXPath("/root/a/a.3", nav);
751         log("Initial Context :: " + contextpath);
752         List JavaDoc list = contextpath.selectNodes(document);
753         Iterator JavaDoc iter = list.iterator();
754         while (iter.hasNext())
755         {
756             Object JavaDoc context = iter.next();
757             assertCountXPath(2, context, "preceding-sibling::*");
758         }
759     }
760
761     public void testid54180() throws JaxenException
762     {
763         Navigator nav = getNavigator();
764         String JavaDoc url = "xml/axis.xml";
765         log("Document [" + url + "]");
766         Object JavaDoc document = nav.getDocument(url);
767         XPath contextpath = new BaseXPath("/", nav);
768         log("Initial Context :: " + contextpath);
769         List JavaDoc list = contextpath.selectNodes(document);
770         Iterator JavaDoc iter = list.iterator();
771         while (iter.hasNext())
772         {
773             Object JavaDoc context = iter.next();
774             assertValueOfXPath("a.2", context, "name(/root/a/a.3/preceding-sibling::*[1])");
775             assertValueOfXPath("a.1", context, "name(/root/a/a.3/preceding-sibling::*[2])");
776         }
777     }
778
779     public void testid54197() throws JaxenException
780     {
781         Navigator nav = getNavigator();
782         String JavaDoc url = "xml/axis.xml";
783         log("Document [" + url + "]");
784         Object JavaDoc document = nav.getDocument(url);
785         XPath contextpath = new BaseXPath("/", nav);
786         log("Initial Context :: " + contextpath);
787         List JavaDoc list = contextpath.selectNodes(document);
788         Iterator JavaDoc iter = list.iterator();
789         while (iter.hasNext())
790         {
791             Object JavaDoc context = iter.next();
792             assertValueOfXPath("a.4", context, "name(/root/a/a.3/following-sibling::*[1])");
793             assertValueOfXPath("a.5", context, "name(/root/a/a.3/following-sibling::*[2])");
794         }
795     }
796
797     public void testid54219() throws JaxenException
798     {
799         Navigator nav = getNavigator();
800         String JavaDoc url = "xml/web.xml";
801         log("Document [" + url + "]");
802         Object JavaDoc document = nav.getDocument(url);
803         XPath contextpath = new BaseXPath("/", nav);
804         log("Initial Context :: " + contextpath);
805         List JavaDoc list = contextpath.selectNodes(document);
806         Iterator JavaDoc iter = list.iterator();
807         while (iter.hasNext())
808         {
809             Object JavaDoc context = iter.next();
810             assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name");
811             assertValueOfXPath("snoop", context, "/web-app/servlet[1]/servlet-name/text()");
812             assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name");
813             assertValueOfXPath("file", context, "/web-app/servlet[2]/servlet-name/text()");
814         }
815     }
816
817     public void testid54249() throws JaxenException
818     {
819         Navigator nav = getNavigator();
820         String JavaDoc url = "xml/web.xml";
821         log("Document [" + url + "]");
822         Object JavaDoc document = nav.getDocument(url);
823         XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav);
824         log("Initial Context :: " + contextpath);
825         List JavaDoc list = contextpath.selectNodes(document);
826         Iterator JavaDoc iter = list.iterator();
827         while (iter.hasNext())
828         {
829             Object JavaDoc context = iter.next();
830             assertValueOfXPath("snoop", context, "servlet-name");
831             assertValueOfXPath("snoop", context, "servlet-name/text()");
832         }
833     }
834
835     public void testid54266() throws JaxenException
836     {
837         Navigator nav = getNavigator();
838         String JavaDoc url = "xml/web.xml";
839         log("Document [" + url + "]");
840         Object JavaDoc document = nav.getDocument(url);
841         XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav);
842         log("Initial Context :: " + contextpath);
843         List JavaDoc list = contextpath.selectNodes(document);
844         Iterator JavaDoc iter = list.iterator();
845         while (iter.hasNext())
846         {
847             Object JavaDoc context = iter.next();
848             assertCountXPath(3, context, "preceding::*");
849         }
850     }
851
852     public void testid54278() throws JaxenException
853     {
854         Navigator nav = getNavigator();
855         String JavaDoc url = "xml/web.xml";
856         log("Document [" + url + "]");
857         Object JavaDoc document = nav.getDocument(url);
858         XPath contextpath = new BaseXPath("/web-app/servlet[2]/servlet-name", nav);
859         log("Initial Context :: " + contextpath);
860         List JavaDoc list = contextpath.selectNodes(document);
861         Iterator JavaDoc iter = list.iterator();
862         while (iter.hasNext())
863         {
864             Object JavaDoc context = iter.next();
865             assertCountXPath(13, context, "following::*");
866         }
867     }
868
869     /* test name
870     */

871     public void testid54298() throws JaxenException
872     {
873         Navigator nav = getNavigator();
874         String JavaDoc url = "xml/web.xml";
875         log("Document [" + url + "]");
876         Object JavaDoc document = nav.getDocument(url);
877         XPath contextpath = new BaseXPath("/", nav);
878         log("Initial Context :: " + contextpath);
879         List JavaDoc list = contextpath.selectNodes(document);
880         Iterator JavaDoc iter = list.iterator();
881         while (iter.hasNext())
882         {
883             Object JavaDoc context = iter.next();
884             try
885             {
886                 Object JavaDoc result = assertCountXPath2(1, context, "*");
887                 assertValueOfXPath("web-app", result, "name()");
888             }
889             catch (UnsupportedAxisException e)
890             {
891                 log(debug, " ## SKIPPED -- Unsupported Axis");
892             }
893             /* NOTE that the child::node() tests only work if the
894               XML document does not comments or PIs
895
896             */

897             try
898             {
899                 Object JavaDoc result = assertCountXPath2(1, context, "./*");
900                 assertValueOfXPath("web-app", result, "name()");
901             }
902             catch (UnsupportedAxisException e)
903             {
904                 log(debug, " ## SKIPPED -- Unsupported Axis");
905             }
906             try
907             {
908                 Object JavaDoc result = assertCountXPath2(1, context, "child::*");
909                 assertValueOfXPath("web-app", result, "name()");
910             }
911             catch (UnsupportedAxisException e)
912             {
913                 log(debug, " ## SKIPPED -- Unsupported Axis");
914             }
915             try
916             {
917                 Object JavaDoc result = assertCountXPath2(1, context, "/*");
918                 assertValueOfXPath("web-app", result, "name()");
919             }
920             catch (UnsupportedAxisException e)
921             {
922                 log(debug, " ## SKIPPED -- Unsupported Axis");
923             }
924             try
925             {
926                 Object JavaDoc result = assertCountXPath2(1, context, "/child::node()");
927                 assertValueOfXPath("web-app", result, "name(.)");
928             }
929             catch (UnsupportedAxisException e)
930             {
931                 log(debug, " ## SKIPPED -- Unsupported Axis");
932             }
933             try
934             {
935                 Object JavaDoc result = assertCountXPath2(1, context, "child::node()");
936                 assertValueOfXPath("web-app", result, "name(.)");
937             }
938             catch (UnsupportedAxisException e)
939             {
940                 log(debug, " ## SKIPPED -- Unsupported Axis");
941             }
942             /* empty names
943             */

944             assertValueOfXPath("", context, "name()");
945             assertValueOfXPath("", context, "name(.)");
946             assertValueOfXPath("", context, "name(parent::*)");
947             assertValueOfXPath("", context, "name(/)");
948             assertValueOfXPath("", context, "name(/.)");
949             assertValueOfXPath("", context, "name(/self::node())");
950             /* name of root elemet
951             */

952             assertValueOfXPath("web-app", context, "name(node())");
953             assertValueOfXPath("web-app", context, "name(/node())");
954             assertValueOfXPath("web-app", context, "name(/*)");
955             assertValueOfXPath("web-app", context, "name(/child::*)");
956             assertValueOfXPath("web-app", context, "name(/child::node())");
957             assertValueOfXPath("web-app", context, "name(/child::node())");
958             assertValueOfXPath("web-app", context, "name(child::node())");
959             assertValueOfXPath("web-app", context, "name(./*)");
960             assertValueOfXPath("web-app", context, "name(*)");
961         }
962     }
963
964     public void testid54467() throws JaxenException
965     {
966         Navigator nav = getNavigator();
967         String JavaDoc url = "xml/web.xml";
968         log("Document [" + url + "]");
969         Object JavaDoc document = nav.getDocument(url);
970         XPath contextpath = new BaseXPath("/*", nav);
971         log("Initial Context :: " + contextpath);
972         List JavaDoc list = contextpath.selectNodes(document);
973         Iterator JavaDoc iter = list.iterator();
974         while (iter.hasNext())
975         {
976             Object JavaDoc context = iter.next();
977             /* empty names
978             */

979             assertValueOfXPath("", context, "name(..)");
980             assertValueOfXPath("", context, "name(parent::node())");
981             assertValueOfXPath("", context, "name(parent::*)");
982             /* name of root elemet
983             */

984             assertValueOfXPath("web-app", context, "name()");
985             assertValueOfXPath("web-app", context, "name(.)");
986             assertValueOfXPath("web-app", context, "name(../*)");
987             assertValueOfXPath("web-app", context, "name(../child::node())");
988         }
989     }
990
991     /* test predicates
992     */

993     public void testid54522() throws JaxenException
994     {
995         Navigator nav = getNavigator();
996         String JavaDoc url = "xml/nitf.xml";
997         log("Document [" + url + "]");
998         Object JavaDoc document = nav.getDocument(url);
999         XPath contextpath = new BaseXPath("/nitf/head/docdata", nav);
1000        log("Initial Context :: " + contextpath);
1001        List JavaDoc list = contextpath.selectNodes(document);
1002        Iterator JavaDoc iter = list.iterator();
1003        while (iter.hasNext())
1004        {
1005            Object JavaDoc context = iter.next();
1006            assertCountXPath(1, context, "doc-id[@regsrc='AP' and @id-string='D76UIMO80']");
1007        }
1008    }
1009
1010    public void testid54534() throws JaxenException
1011    {
1012        Navigator nav = getNavigator();
1013        String JavaDoc url = "xml/nitf.xml";
1014        log("Document [" + url + "]");
1015        Object JavaDoc document = nav.getDocument(url);
1016        XPath contextpath = new BaseXPath("/nitf/head", nav);
1017        log("Initial Context :: " + contextpath);
1018        List JavaDoc list = contextpath.selectNodes(document);
1019        Iterator JavaDoc iter = list.iterator();
1020        while (iter.hasNext())
1021        {
1022            Object JavaDoc context = iter.next();
1023            assertCountXPath(1, context, "meta[@name='ap-cycle']");
1024            assertCountXPath(1, context, "meta[@content='AP']");
1025            assertCountXPath(8, context, "meta[@name and @content]");
1026            assertCountXPath(1, context, "meta[@name='ap-cycle' and @content='AP']");
1027            assertCountXPath(7, context, "meta[@name != 'ap-cycle']");
1028        }
1029    }
1030
1031    public void testid54570() throws JaxenException
1032    {
1033        Navigator nav = getNavigator();
1034        String JavaDoc url = "xml/nitf.xml";
1035        log("Document [" + url + "]");
1036        Object JavaDoc document = nav.getDocument(url);
1037        XPath contextpath = new BaseXPath("/", nav);
1038        log("Initial Context :: " + contextpath);
1039        List JavaDoc list = contextpath.selectNodes(document);
1040        Iterator JavaDoc iter = list.iterator();
1041        while (iter.hasNext())
1042        {
1043            Object JavaDoc context = iter.next();
1044            assertCountXPath(1, context, "/nitf/head/meta[@name='ap-cycle']");
1045            assertCountXPath(1, context, "/nitf/head/meta[@content='AP']");
1046            assertCountXPath(8, context, "/nitf/head/meta[@name and @content]");
1047            assertCountXPath(1, context, "/nitf/head/meta[@name='ap-cycle' and @content='AP']");
1048            assertCountXPath(7, context, "/nitf/head/meta[@name != 'ap-cycle']");
1049        }
1050    }
1051
1052    public void testid54614() throws JaxenException
1053    {
1054        Navigator nav = getNavigator();
1055        String JavaDoc url = "xml/moreover.xml";
1056        log("Document [" + url + "]");
1057        Object JavaDoc document = nav.getDocument(url);
1058        XPath contextpath = new BaseXPath("/", nav);
1059        log("Initial Context :: " + contextpath);
1060        List JavaDoc list = contextpath.selectNodes(document);
1061        Iterator JavaDoc iter = list.iterator();
1062        while (iter.hasNext())
1063        {
1064            Object JavaDoc context = iter.next();
1065            assertCountXPath(1, context, "/child::node()");
1066            assertCountXPath(1, context, "/*");
1067            assertCountXPath(20, context, "/*/article");
1068            assertCountXPath(221, context, "//*");
1069            assertCountXPath(20, context, "//*[local-name()='article']");
1070            assertCountXPath(20, context, "//article");
1071            assertCountXPath(20, context, "/*/*[@code]");
1072            assertCountXPath(1, context, "/moreovernews/article[@code='13563275']");
1073            try
1074            {
1075                BaseXPath xpath = new BaseXPath("/moreovernews/article[@code='13563275']");
1076                List JavaDoc results = xpath.selectNodes(getContext(context));
1077                Object JavaDoc result = results.get(0);
1078                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1079            }
1080            catch (UnsupportedAxisException e)
1081            {
1082                log(debug, " ## SKIPPED -- Unsupported Axis");
1083            }
1084            try
1085            {
1086                BaseXPath xpath = new BaseXPath("/*/article[@code='13563275']");
1087                List JavaDoc results = xpath.selectNodes(getContext(context));
1088                Object JavaDoc result = results.get(0);
1089                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1090            }
1091            catch (UnsupportedAxisException e)
1092            {
1093                log(debug, " ## SKIPPED -- Unsupported Axis");
1094            }
1095            try
1096            {
1097                BaseXPath xpath = new BaseXPath("//article[@code='13563275']");
1098                List JavaDoc results = xpath.selectNodes(getContext(context));
1099                Object JavaDoc result = results.get(0);
1100                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1101            }
1102            catch (UnsupportedAxisException e)
1103            {
1104                log(debug, " ## SKIPPED -- Unsupported Axis");
1105            }
1106            try
1107            {
1108                BaseXPath xpath = new BaseXPath("//*[@code='13563275']");
1109                List JavaDoc results = xpath.selectNodes(getContext(context));
1110                Object JavaDoc result = results.get(0);
1111                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1112            }
1113            catch (UnsupportedAxisException e)
1114            {
1115                log(debug, " ## SKIPPED -- Unsupported Axis");
1116            }
1117            try
1118            {
1119                BaseXPath xpath = new BaseXPath("/child::node()/child::node()[@code='13563275']");
1120                List JavaDoc results = xpath.selectNodes(getContext(context));
1121                Object JavaDoc result = results.get(0);
1122                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1123            }
1124            catch (UnsupportedAxisException e)
1125            {
1126                log(debug, " ## SKIPPED -- Unsupported Axis");
1127            }
1128            try
1129            {
1130                BaseXPath xpath = new BaseXPath("/*/*[@code='13563275']");
1131                List JavaDoc results = xpath.selectNodes(getContext(context));
1132                Object JavaDoc result = results.get(0);
1133                assertValueOfXPath("http://c.moreover.com/click/here.pl?x13563273", result, "url");
1134            }
1135            catch (UnsupportedAxisException e)
1136            {
1137                log(debug, " ## SKIPPED -- Unsupported Axis");
1138            }
1139        }
1140    }
1141
1142    /* test other node types
1143    */

1144    public void testid54747() throws JaxenException
1145    {
1146        Navigator nav = getNavigator();
1147        String JavaDoc url = "xml/contents.xml";
1148        log("Document [" + url + "]");
1149        Object JavaDoc document = nav.getDocument(url);
1150        XPath contextpath = new BaseXPath("/", nav);
1151        log("Initial Context :: " + contextpath);
1152        List JavaDoc list = contextpath.selectNodes(document);
1153        Iterator JavaDoc iter = list.iterator();
1154        while (iter.hasNext())
1155        {
1156            Object JavaDoc context = iter.next();
1157            assertCountXPath(3, context, "processing-instruction()");
1158            assertCountXPath(3, context, "/processing-instruction()");
1159            assertCountXPath(1, context, "/comment()");
1160            assertCountXPath(1, context, "comment()");
1161            assertCountXPath(2, context, "/child::node()/comment()");
1162            assertCountXPath(2, context, "/*/comment()");
1163            assertCountXPath(3, context, "//comment()");
1164        }
1165    }
1166
1167    /* test positioning
1168    */

1169    public void testid54802() throws JaxenException
1170    {
1171        Navigator nav = getNavigator();
1172        String JavaDoc url = "xml/fibo.xml";
1173        log("Document [" + url + "]");
1174        Object JavaDoc document = nav.getDocument(url);
1175        XPath contextpath = new BaseXPath("/", nav);
1176        log("Initial Context :: " + contextpath);
1177        List JavaDoc list = contextpath.selectNodes(document);
1178        Iterator JavaDoc iter = list.iterator();
1179        while (iter.hasNext())
1180        {
1181            Object JavaDoc context = iter.next();
1182            assertCountXPath(9, context, "/*/fibonacci[position() < 10]");
1183            assertValueOfXPath("196417", context, "sum(//fibonacci)");
1184            assertValueOfXPath("325", context, "sum(//fibonacci/@index)");
1185            assertValueOfXPath("1", context, "/*/fibonacci[2]");
1186            assertValueOfXPath("75025", context, "/*/fibonacci[ count(/*/fibonacci) ]");
1187            assertValueOfXPath("46368", context, "/*/fibonacci[ count(/*/fibonacci) - 1 ]");
1188        }
1189    }
1190
1191    /* test number functions
1192    */

1193    /* test Axes
1194    */

1195    public void testid54853() throws JaxenException
1196    {
1197        Navigator nav = getNavigator();
1198        String JavaDoc url = "xml/web.xml";
1199        log("Document [" + url + "]");
1200        Object JavaDoc document = nav.getDocument(url);
1201        XPath contextpath = new BaseXPath("/", nav);
1202        log("Initial Context :: " + contextpath);
1203        List JavaDoc list = contextpath.selectNodes(document);
1204        Iterator JavaDoc iter = list.iterator();
1205        while (iter.hasNext())
1206        {
1207            Object JavaDoc context = iter.next();
1208            assertCountXPath(19, context, "descendant-or-self::*");
1209            assertCountXPath(19, context, "descendant::*");
1210            assertCountXPath(19, context, "/descendant::*");
1211            assertCountXPath(19, context, "/descendant-or-self::*");
1212            assertCountXPath(2, context, "/descendant::servlet");
1213            assertCountXPath(2, context, "/descendant-or-self::servlet");
1214            assertCountXPath(2, context, "descendant-or-self::servlet");
1215            assertCountXPath(2, context, "descendant::servlet");
1216            assertCountXPath(2, context, "/*/servlet");
1217            assertValueOfXPath("2", context, "count(/*/servlet)");
1218            assertCountXPath(2, context, "//servlet");
1219            assertValueOfXPath("2", context, "count(//servlet)");
1220        }
1221    }
1222
1223    public void testid54932() throws JaxenException
1224    {
1225        Navigator nav = getNavigator();
1226        String JavaDoc url = "xml/web.xml";
1227        log("Document [" + url + "]");
1228        Object JavaDoc document = nav.getDocument(url);
1229        XPath contextpath = new BaseXPath("/web-app", nav);
1230        log("Initial Context :: " + contextpath);
1231        List JavaDoc list = contextpath.selectNodes(document);
1232        Iterator JavaDoc iter = list.iterator();
1233        while (iter.hasNext())
1234        {
1235            Object JavaDoc context = iter.next();
1236            assertCountXPath(2, context, "/descendant::servlet");
1237            assertCountXPath(2, context, "/descendant-or-self::servlet");
1238            assertCountXPath(2, context, "descendant-or-self::servlet");
1239            assertCountXPath(2, context, "descendant::servlet");
1240        }
1241    }
1242
1243    public void testid54968() throws JaxenException
1244    {
1245        Navigator nav = getNavigator();
1246        String JavaDoc url = "xml/much_ado.xml";
1247        log("Document [" + url + "]");
1248        Object JavaDoc document = nav.getDocument(url);
1249        XPath contextpath = new BaseXPath("/", nav);
1250        log("Initial Context :: " + contextpath);
1251        List JavaDoc list = contextpath.selectNodes(document);
1252        Iterator JavaDoc iter = list.iterator();
1253        while (iter.hasNext())
1254        {
1255            Object JavaDoc context = iter.next();
1256            assertCountXPath(5, context, "/descendant::ACT");
1257            assertCountXPath(5, context, "descendant::ACT");
1258            assertValueOfXPath("Much Ado about Nothing", context, "/PLAY/TITLE");
1259            assertValueOfXPath("4", context, "2+2");
1260            assertValueOfXPath("21", context, "5 * 4 + 1");
1261            assertValueOfXPath("5", context, "count(descendant::ACT)");
1262            assertValueOfXPath("35", context, "10 + count(descendant::ACT) * 5");
1263            assertValueOfXPath("75", context, "(10 + count(descendant::ACT)) * 5");
1264        }
1265    }
1266
1267    public void testid55020() throws JaxenException
1268    {
1269        Navigator nav = getNavigator();
1270        String JavaDoc url = "xml/much_ado.xml";
1271        log("Document [" + url + "]");
1272        Object JavaDoc document = nav.getDocument(url);
1273        XPath contextpath = new BaseXPath("/PLAY/ACT[2]/SCENE[1]", nav);
1274        log("Initial Context :: " + contextpath);
1275        List JavaDoc list = contextpath.selectNodes(document);
1276        Iterator JavaDoc iter = list.iterator();
1277        while (iter.hasNext())
1278        {
1279            Object JavaDoc context = iter.next();
1280            assertCountXPath(5, context, "/descendant::ACT");
1281            assertCountXPath(5, context, "../../descendant::ACT");
1282            assertCountXPath(141, context, "/PLAY/ACT[2]/SCENE[1]/descendant::SPEAKER");
1283            assertCountXPath(141, context, "descendant::SPEAKER");
1284            assertValueOfXPath("646", context, "count(descendant::*)+1");
1285            assertValueOfXPath("142", context, "count(descendant::SPEAKER)+1");
1286            assertValueOfXPath("2", context, "count(ancestor::*)");
1287            assertValueOfXPath("1", context, "count(ancestor::PLAY)");
1288            assertValueOfXPath("3", context, "count(ancestor-or-self::*)");
1289            assertValueOfXPath("1", context, "count(ancestor-or-self::PLAY)");
1290            assertValueOfXPath("6", context, "5+count(ancestor::*)-1");
1291        }
1292    }
1293
1294    public void testid55090() throws JaxenException
1295    {
1296        Navigator nav = getNavigator();
1297        String JavaDoc url = "xml/much_ado.xml";
1298        log("Document [" + url + "]");
1299        Object JavaDoc document = nav.getDocument(url);
1300        XPath contextpath = new BaseXPath("/", nav);
1301        log("Initial Context :: " + contextpath);
1302        List JavaDoc list = contextpath.selectNodes(document);
1303        Iterator JavaDoc iter = list.iterator();
1304        while (iter.hasNext())
1305        {
1306            Object JavaDoc context = iter.next();
1307            /* Test correct predicate application
1308            */

1309            assertValueOfXPath("5", context, "count(/PLAY/ACT/SCENE[1])");
1310        }
1311    }
1312
1313    /* test axis node ordering
1314    */

1315    public void testid55112() throws JaxenException
1316    {
1317        Navigator nav = getNavigator();
1318        String JavaDoc url = "xml/web.xml";
1319        log("Document [" + url + "]");
1320        Object JavaDoc document = nav.getDocument(url);
1321        XPath contextpath = new BaseXPath("/", nav);
1322        log("Initial Context :: " + contextpath);
1323        List JavaDoc list = contextpath.selectNodes(document);
1324        Iterator JavaDoc iter = list.iterator();
1325        while (iter.hasNext())
1326        {
1327            Object JavaDoc context = iter.next();
1328            /* Reported as Jira issue JAXEN-24
1329            */

1330            assertCountXPath(1, context, "//servlet-mapping/preceding::*[1][name()='description']");
1331            assertCountXPath(1, context, "/web-app/servlet//description/following::*[1][name()='servlet-mapping']");
1332            assertCountXPath(1, context, "/web-app/servlet//description/following::*[2][name()='servlet-name']");
1333        }
1334    }
1335
1336    /* test document function
1337    */

1338    public void testid55150() throws JaxenException
1339    {
1340        Navigator nav = getNavigator();
1341        String JavaDoc url = "xml/text.xml";
1342        log("Document [" + url + "]");
1343        Object JavaDoc document = nav.getDocument(url);
1344        XPath contextpath = new BaseXPath("/", nav);
1345        log("Initial Context :: " + contextpath);
1346        List JavaDoc list = contextpath.selectNodes(document);
1347        Iterator JavaDoc iter = list.iterator();
1348        while (iter.hasNext())
1349        {
1350            Object JavaDoc context = iter.next();
1351            try
1352            {
1353                Object JavaDoc result = assertCountXPath2(1, context, "document('xml/web.xml')");
1354                assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name");
1355                assertValueOfXPath("snoop", result, "/web-app/servlet[1]/servlet-name/text()");
1356            }
1357            catch (UnsupportedAxisException e)
1358            {
1359                log(debug, " ## SKIPPED -- Unsupported Axis");
1360            }
1361            assertValueOfXPath("snoop", context, "document('xml/web.xml')/web-app/servlet[1]/servlet-name");
1362        }
1363    }
1364
1365    /* Test to check if the context changes when an extension function is used.
1366    First test is an example, second is the actual test.
1367    
1368    */

1369    public void testid55189() throws JaxenException
1370    {
1371        Navigator nav = getNavigator();
1372        String JavaDoc url = "xml/text.xml";
1373        log("Document [" + url + "]");
1374        Object JavaDoc document = nav.getDocument(url);
1375        XPath contextpath = new BaseXPath("/foo/bar/cheese[1]", nav);
1376        log("Initial Context :: " + contextpath);
1377        List JavaDoc list = contextpath.selectNodes(document);
1378        Iterator JavaDoc iter = list.iterator();
1379        while (iter.hasNext())
1380        {
1381            Object JavaDoc context = iter.next();
1382            assertValueOfXPath("3foo3", context, "concat(./@id,'foo',@id)");
1383            assertValueOfXPath("3snoop3", context, "concat(./@id,document('xml/web.xml')/web-app/servlet[1]/servlet-name,./@id)");
1384        }
1385    }
1386
1387    public void testid55211() throws JaxenException
1388    {
1389        Navigator nav = getNavigator();
1390        String JavaDoc url = "xml/message.xml";
1391        log("Document [" + url + "]");
1392        Object JavaDoc document = nav.getDocument(url);
1393        XPath contextpath = new BaseXPath("/", nav);
1394        log("Initial Context :: " + contextpath);
1395        List JavaDoc list = contextpath.selectNodes(document);
1396        Iterator JavaDoc iter = list.iterator();
1397        while (iter.hasNext())
1398        {
1399            Object JavaDoc context = iter.next();
1400            assertValueOfXPath("Pruefgebiete", context, "/message/body/data/items/item[name/text()='parentinfo']/value");
1401            assertValueOfXPath("Pruefgebiete", context, "document('xml/message.xml')/message/body/data/items/item[name/text()='parentinfo']/value");
1402        }
1403    }
1404
1405    /* test behaviour of AbsoluteLocationPath
1406    */

1407    public void testid55183() throws JaxenException
1408    {
1409        Navigator nav = getNavigator();
1410        String JavaDoc url = "xml/simple.xml";
1411        log("Document [" + url + "]");
1412        Object JavaDoc document = nav.getDocument(url);
1413        XPath contextpath = new BaseXPath("/root/a", nav);
1414        log("Initial Context :: " + contextpath);
1415        List JavaDoc list = contextpath.selectNodes(document);
1416        Iterator JavaDoc iter = list.iterator();
1417        while (iter.hasNext())
1418        {
1419            Object JavaDoc context = iter.next();
1420            assertValueOfXPath("ab", context, "concat( ., /root/b )");
1421            assertValueOfXPath("ba", context, "concat( ../b, . )");
1422            assertValueOfXPath("ba", context, "concat( /root/b, . )");
1423            assertValueOfXPath("db", context, "concat( /root/c/d, ../b )");
1424        }
1425    }
1426
1427    /* test the translate() function
1428    */

1429    public void testid55268() throws JaxenException
1430    {
1431        Navigator nav = getNavigator();
1432        String JavaDoc url = "xml/simple.xml";
1433        log("Document [" + url + "]");
1434        Object JavaDoc document = nav.getDocument(url);
1435        XPath contextpath = new BaseXPath("/", nav);
1436        log("Initial Context :: " + contextpath);
1437        List JavaDoc list = contextpath.selectNodes(document);
1438        Iterator JavaDoc iter = list.iterator();
1439        while (iter.hasNext())
1440        {
1441            Object JavaDoc context = iter.next();
1442            assertValueOfXPath("", context, "translate( '', '', '' )");
1443            assertValueOfXPath("abcd", context, "translate( 'abcd', '', '' )");
1444            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcd' )");
1445            assertValueOfXPath("abcd", context, "translate( 'abcd', 'dcba', 'dcba' )");
1446            assertValueOfXPath("dcba", context, "translate( 'abcd', 'abcd', 'dcba' )");
1447            assertValueOfXPath("ab", context, "translate( 'abcd', 'abcd', 'ab' )");
1448            assertValueOfXPath("cd", context, "translate( 'abcd', 'cdab', 'cd' )");
1449            assertValueOfXPath("xy", context, "translate( 'abcd', 'acbd', 'xy' )");
1450            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcdb', 'abcdb' )");
1451            assertValueOfXPath("abcd", context, "translate( 'abcd', 'abcd', 'abcdb' )");
1452        }
1453    }
1454
1455    public void testid55331() throws JaxenException
1456    {
1457        Navigator nav = getNavigator();
1458        String JavaDoc url = "xml/simple.xml";
1459        log("Document [" + url + "]");
1460        Object JavaDoc document = nav.getDocument(url);
1461        XPath contextpath = new BaseXPath("/", nav);
1462        log("Initial Context :: " + contextpath);
1463        List JavaDoc list = contextpath.selectNodes(document);
1464        Iterator JavaDoc iter = list.iterator();
1465        while (iter.hasNext())
1466        {
1467            Object JavaDoc context = iter.next();
1468            assertValueOfXPath("234", context, "substring('12345', 1.5, 2.6)");
1469            assertValueOfXPath("12", context, "substring('12345', 0, 3)");
1470            assertValueOfXPath("", context, "substring('12345', 0 div 0, 3)");
1471            assertValueOfXPath("", context, "substring('12345', 1, 0 div 0)");
1472            assertValueOfXPath("12345", context, "substring('12345', -42, 1 div 0)");
1473            assertValueOfXPath("", context, "substring('12345', -1 div 0, 1 div 0)");
1474            assertValueOfXPath("345", context, "substring('12345', 3)");
1475            assertValueOfXPath("12345", context, "substring('12345',1,15)");
1476        }
1477    }
1478
1479    /* Some tests for the normalize-space() function
1480    */

1481    public void testid55382() throws JaxenException
1482    {
1483        Navigator nav = getNavigator();
1484        String JavaDoc url = "xml/simple.xml";
1485        log("Document [" + url + "]");
1486        Object JavaDoc document = nav.getDocument(url);
1487        XPath contextpath = new BaseXPath("/", nav);
1488        log("Initial Context :: " + contextpath);
1489        List JavaDoc list = contextpath.selectNodes(document);
1490        Iterator JavaDoc iter = list.iterator();
1491        while (iter.hasNext())
1492        {
1493            Object JavaDoc context = iter.next();
1494            assertValueOfXPath("abc", context, "normalize-space(' abc ')");
1495            assertValueOfXPath("a b c", context, "normalize-space(' a b c ')");
1496            assertValueOfXPath("a b c", context, "normalize-space(' a \n b \n c')");
1497            /* Next test case addresses issue JAXEN-22
1498            */

1499            assertValueOfXPath("", context, "normalize-space(' ')");
1500            /* Next test case addresses issue JAXEN-29
1501            */

1502            assertValueOfXPath("", context, "normalize-space('')");
1503        }
1504    }
1505
1506    /* test cases for String extension functions
1507    */

1508    public void testid55429() throws JaxenException
1509    {
1510        Navigator nav = getNavigator();
1511        String JavaDoc url = "xml/web.xml";
1512        log("Document [" + url + "]");
1513        Object JavaDoc document = nav.getDocument(url);
1514        XPath contextpath = new BaseXPath("/web-app/servlet[1]", nav);
1515        log("Initial Context :: " + contextpath);
1516        List JavaDoc list = contextpath.selectNodes(document);
1517        Iterator JavaDoc iter = list.iterator();
1518        while (iter.hasNext())
1519        {
1520            Object JavaDoc context = iter.next();
1521            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class )");
1522            assertValueOfXPath("snoopservlet", context, "lower-case( servlet-class )");
1523            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr' )");
1524            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'fr-CA' )");
1525            assertValueOfXPath("SNOOPSERVLET", context, "upper-case( servlet-class, 'es-ES-Traditional_WIN' )");
1526            assertValueOfXPath("true", context, "ends-with( servlet-class, 'Servlet' )");
1527            assertValueOfXPath("false", context, "ends-with( servlet-class, 'S' )");
1528        }
1529    }
1530
1531    /* test cases for the lang() function
1532    */

1533    public void testid55485() throws JaxenException
1534    {
1535        Navigator nav = getNavigator();
1536        String JavaDoc url = "xml/lang.xml";
1537        log("Document [" + url + "]");
1538        Object JavaDoc document = nav.getDocument(url);
1539        XPath contextpath = new BaseXPath("/", nav);
1540        log("Initial Context :: " + contextpath);
1541        List JavaDoc list = contextpath.selectNodes(document);
1542        Iterator JavaDoc iter = list.iterator();
1543        while (iter.hasNext())
1544        {
1545            Object JavaDoc context = iter.next();
1546            assertCountXPath(0, context, "/e1/e2[lang('hr')]");
1547            assertCountXPath(1, context, "/e1/e2/e3[lang('en')]");
1548            assertCountXPath(1, context, "/e1/e2/e3[lang('en-US')]");
1549            assertCountXPath(0, context, "/e1/e2/e3[lang('en-GB')]");
1550            assertCountXPath(2, context, "/e1/e2/e3[lang('hu')]");
1551            assertCountXPath(0, context, "/e1/e2/e3[lang('hu-HU')]");
1552            assertCountXPath(1, context, "/e1/e2/e3[lang('es')]");
1553            assertCountXPath(0, context, "/e1/e2/e3[lang('es-BR')]");
1554        }
1555    }
1556
1557    /* test namespace
1558    */

1559    public void testid55235() throws JaxenException
1560    {
1561        Navigator nav = getNavigator();
1562        String JavaDoc url = "xml/namespaces.xml";
1563        log("Document [" + url + "]");
1564        Object JavaDoc document = nav.getDocument(url);
1565        XPath contextpath = new BaseXPath("/", nav);
1566        log("Initial Context :: " + contextpath);
1567        List JavaDoc list = contextpath.selectNodes(document);
1568        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
1569        nsContext.addNamespace("alias", "http://fooNamespace/");
1570        nsContext.addNamespace("bar", "http://barNamespace/");
1571        nsContext.addNamespace("voo", "http://fooNamespace/");
1572        nsContext.addNamespace("foo", "http://fooNamespace/");
1573        getContextSupport().setNamespaceContext(nsContext);
1574        Iterator JavaDoc iter = list.iterator();
1575        while (iter.hasNext())
1576        {
1577            Object JavaDoc context = iter.next();
1578            assertCountXPath(1, context, "/*");
1579            assertCountXPath(1, context, "/foo:a");
1580            assertCountXPath(1, context, "/foo:a/b");
1581            assertCountXPath(1, context, "/voo:a/b/c");
1582            assertCountXPath(1, context, "/voo:a/bar:f");
1583            assertCountXPath(1, context, "/*[namespace-uri()='http://fooNamespace/' and local-name()='a']");
1584            assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']");
1585            assertCountXPath(1, context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']");
1586        }
1587    }
1588
1589    /* the prefix here and in the document have no relation; it's their
1590    namespace-uri binding that counts
1591    */

1592    public void testid55615() throws JaxenException
1593    {
1594        Navigator nav = getNavigator();
1595        String JavaDoc url = "xml/namespaces.xml";
1596        log("Document [" + url + "]");
1597        Object JavaDoc document = nav.getDocument(url);
1598        XPath contextpath = new BaseXPath("/", nav);
1599        log("Initial Context :: " + contextpath);
1600        List JavaDoc list = contextpath.selectNodes(document);
1601        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
1602        nsContext.addNamespace("foo", "http://somethingElse/");
1603        getContextSupport().setNamespaceContext(nsContext);
1604        Iterator JavaDoc iter = list.iterator();
1605        while (iter.hasNext())
1606        {
1607            Object JavaDoc context = iter.next();
1608            assertCountXPath(0, context, "/foo:a/b/c");
1609        }
1610    }
1611
1612    public void testid55632() throws JaxenException
1613    {
1614        Navigator nav = getNavigator();
1615        String JavaDoc url = "xml/namespaces.xml";
1616        log("Document [" + url + "]");
1617        Object JavaDoc document = nav.getDocument(url);
1618        XPath contextpath = new BaseXPath("/", nav);
1619        log("Initial Context :: " + contextpath);
1620        List JavaDoc list = contextpath.selectNodes(document);
1621        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
1622        nsContext.addNamespace("alias", "http://fooNamespace/");
1623        nsContext.addNamespace("bar", "http://barNamespace/");
1624        nsContext.addNamespace("foo", "http://fooNamespace/");
1625        getContextSupport().setNamespaceContext(nsContext);
1626        Iterator JavaDoc iter = list.iterator();
1627        while (iter.hasNext())
1628        {
1629            Object JavaDoc context = iter.next();
1630            assertValueOfXPath("Hello", context, "/foo:a/b/c");
1631            assertValueOfXPath("Hey", context, "/foo:a/foo:d/foo:e");
1632            assertValueOfXPath("Hey3", context, "/foo:a/alias:x/alias:y");
1633            assertValueOfXPath("Hey3", context, "/foo:a/foo:x/foo:y");
1634            assertValueOfXPath("Hey3", context, "/*[local-name()='a' and namespace-uri()='http://fooNamespace/']/*[local-name()='x' and namespace-uri()='http://fooNamespace/']/*[local-name()='y' and namespace-uri()='http://fooNamespace/']");
1635        }
1636    }
1637
1638    public void testid55676() throws JaxenException
1639    {
1640        Navigator nav = getNavigator();
1641        String JavaDoc url = "xml/defaultNamespace.xml";
1642        log("Document [" + url + "]");
1643        Object JavaDoc document = nav.getDocument(url);
1644        XPath contextpath = new BaseXPath("/", nav);
1645        log("Initial Context :: " + contextpath);
1646        List JavaDoc list = contextpath.selectNodes(document);
1647        Iterator JavaDoc iter = list.iterator();
1648        while (iter.hasNext())
1649        {
1650            Object JavaDoc context = iter.next();
1651            /* NOTE: /a/b/c selects elements in no namespace only!
1652            */

1653            assertCountXPath(0, context, "/a/b/c");
1654            /*
1655                The following test uses an unbound prefix 'x' and should throw an exception.
1656                Addresses issue JAXEN-18.
1657                Turns out this isn't really tested as the test didn't fail when the exception wasn't thrown.
1658              <test select="/x:a/x:b/x:c" count="0" exception="true"/>
1659
1660            */

1661        }
1662    }
1663
1664    public void testid55692() throws JaxenException
1665    {
1666        Navigator nav = getNavigator();
1667        String JavaDoc url = "xml/defaultNamespace.xml";
1668        log("Document [" + url + "]");
1669        Object JavaDoc document = nav.getDocument(url);
1670        XPath contextpath = new BaseXPath("/", nav);
1671        log("Initial Context :: " + contextpath);
1672        List JavaDoc list = contextpath.selectNodes(document);
1673        SimpleNamespaceContext nsContext = new SimpleNamespaceContext();
1674        nsContext.addNamespace("dummy", "http://dummyNamespace/");
1675        getContextSupport().setNamespaceContext(nsContext);
1676        Iterator JavaDoc iter = list.iterator();
1677        while (iter.hasNext())
1678        {
1679            Object JavaDoc context = iter.next();
1680            assertCountXPath(1, context, "/dummy:a/dummy:b/dummy:c");
1681        }
1682    }
1683
1684    public void testid55716() throws JaxenException
1685    {
1686        Navigator nav = getNavigator();
1687        String JavaDoc url = "xml/text.xml";
1688        log("Document [" + url + "]");
1689        Object JavaDoc document = nav.getDocument(url);
1690        XPath contextpath = new BaseXPath("/", nav);
1691        log("Initial Context :: " + contextpath);
1692        List JavaDoc list = contextpath.selectNodes(document);
1693        Iterator JavaDoc iter = list.iterator();
1694        while (iter.hasNext())
1695        {
1696            Object JavaDoc context = iter.next();
1697            assertCountXPath(3, context, "/foo/bar/text()");
1698            assertValueOfXPath("baz", context, "normalize-space(/foo/bar/text())");
1699        }
1700    }
1701
1702    public void testid55739() throws JaxenException
1703    {
1704        Navigator nav = getNavigator();
1705        String JavaDoc url = "xml/testNamespaces.xml";
1706        log("Document [" + url + "]");
1707        Object JavaDoc document = nav.getDocument(url);
1708        XPath contextpath = new BaseXPath("/", nav);
1709        log("Initial Context :: " + contextpath);
1710        List JavaDoc list = contextpath.selectNodes(document);
1711        Iterator JavaDoc iter = list.iterator();
1712        while (iter.hasNext())
1713        {
1714            Object JavaDoc context = iter.next();
1715            /* the root is not an element, so no namespaces
1716            */

1717            assertCountXPath(0, context, "namespace::*");
1718            assertCountXPath(0, context, "/namespace::*");
1719            /* must count the default xml: prefix as well
1720            */

1721            assertCountXPath(3, context, "/Template/Application1/namespace::*");
1722            assertCountXPath(3, context, "/Template/Application2/namespace::*");
1723            /* every element has separate copies
1724            */

1725            assertCountXPath(25, context, "//namespace::*");
1726        }
1727    }
1728
1729    public void testid55797() throws JaxenException
1730    {
1731        Navigator nav = getNavigator();
1732        String JavaDoc url = "xml/testNamespaces.xml";
1733        log("Document [" + url + "]");
1734        Object JavaDoc document = nav.getDocument(url);
1735        XPath contextpath = new BaseXPath("/Template/Application1", nav);
1736        log("Initial Context :: " + contextpath);
1737        List JavaDoc list = contextpath.selectNodes(document);
1738        Iterator JavaDoc iter = list.iterator();
1739        while (iter.hasNext())
1740        {
1741            Object JavaDoc context = iter.next();
1742            /* must count the default xml: prefix as well
1743            */

1744            assertCountXPath(3, context, "namespace::*");
1745            assertCountXPath(0, context, "/namespace::*");
1746            assertCountXPath(3, context, "/Template/Application1/namespace::*");
1747            assertCountXPath(3, context, "/Template/Application2/namespace::*");
1748            assertCountXPath(25, context, "//namespace::*");
1749            assertCountXPath(8, context, "//namespace::xplt");
1750            /* the name test literally matches the prefix as given in the
1751              document, and does not use the uri
1752            */

1753            assertCountXPath(0, context, "//namespace::somethingelse");
1754        }
1755    }
1756
1757    public void testid55873() throws JaxenException
1758    {
1759        Navigator nav = getNavigator();
1760        String JavaDoc url = "xml/testNamespaces.xml";
1761        log("Document [" + url + "]");
1762        Object JavaDoc document = nav.getDocument(url);
1763        XPath contextpath = new BaseXPath("/", nav);
1764        log("Initial Context :: " + contextpath);
1765        List JavaDoc list = contextpath.selectNodes(document);
1766        Iterator JavaDoc iter = list.iterator();
1767        while (iter.hasNext())
1768        {
1769            Object JavaDoc context = iter.next();
1770            /* namespace nodes have their element as their parent
1771            */

1772            assertCountXPath(1, context, "/Template/namespace::xml/parent::Template");
1773        }
1774    }
1775
1776    /* namespace nodes can also be used as context nodes
1777    */

1778    public void testid55893() throws JaxenException
1779    {
1780        Navigator nav = getNavigator();
1781        String JavaDoc url = "xml/testNamespaces.xml";
1782        log("Document [" + url + "]");
1783        Object JavaDoc document = nav.getDocument(url);
1784        XPath contextpath = new BaseXPath("/Template/namespace::xml", nav);
1785        log("Initial Context :: " + contextpath);
1786        List JavaDoc list = contextpath.selectNodes(document);
1787        Iterator JavaDoc iter = list.iterator();
1788        while (iter.hasNext())
1789        {
1790            Object JavaDoc context = iter.next();
1791            assertCountXPath(1, context, "parent::Template");
1792        }
1793    }
1794}
1795        
Popular Tags