1   /*
2    * $Header$
3    * $Revision$
4    * $Date$
5    *
6    * ====================================================================
7    *
8    * Copyright (C) 2005 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$
60   */
61  
62  
63  package org.jaxen;
64  
65  import java.io.IOException;
66  import java.util.Iterator;
67  import java.util.List;
68  
69  import javax.xml.parsers.DocumentBuilderFactory;
70  import javax.xml.parsers.ParserConfigurationException;
71  
72  import org.jaxen.dom.DOMXPath;
73  import org.jaxen.dom.NamespaceNode;
74  import org.w3c.dom.Attr;
75  
76  import junit.framework.TestCase;
77  
78  /***
79   * <p>
80   * Tests for org.jaxen.BaseXPath.
81   * </p>
82   * 
83   * @author Elliotte Rusty Harold
84   * @version 1.1b4
85   *
86   */
87  public class BaseXPathTest extends TestCase {
88  
89      private org.w3c.dom.Document doc;
90  
91      public BaseXPathTest(String name) {
92          super(name);
93      }
94      
95      protected void setUp() throws ParserConfigurationException {
96          
97          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
98          factory.setNamespaceAware(true);
99          doc = factory.newDocumentBuilder().newDocument();
100         
101     }
102     
103     public void testSelectSingleNodeForContext() throws JaxenException {
104         
105         BaseXPath xpath = new BaseXPath("1 + 2");
106         
107         String stringValue = xpath.stringValueOf(xpath);
108         assertEquals("3", stringValue);
109         
110         Number numberValue = xpath.numberValueOf(xpath);
111         assertEquals(3, numberValue.doubleValue(), 0.00001);
112         
113     }
114     
115     
116     public void testEvaluateString() throws JaxenException {
117         
118         BaseXPath xpath = new DOMXPath("string(/*)");
119         
120         doc.appendChild(doc.createElement("root"));
121         String stringValue = (String) xpath.evaluate(doc);
122         assertEquals("", stringValue);
123         
124     }
125     
126     
127     public void testNumberValueOfEmptyNodeSetIsNaN() throws JaxenException {
128         
129         BaseXPath xpath = new DOMXPath("/x");
130         
131         doc.appendChild(doc.createElement("root"));
132         Double numberValue = (Double) xpath.numberValueOf(doc);
133         assertTrue(numberValue.isNaN());
134         
135     }
136     
137     
138     public void testEvaluateWithMultiNodeAnswer() throws JaxenException {
139         
140         BaseXPath xpath = new DOMXPath("(/descendant-or-self::node())");
141         
142         doc.appendChild(doc.createElement("root"));
143         List result = (List) xpath.evaluate(doc);
144         assertEquals(2, result.size());
145         
146     }
147     
148     
149     public void testValueOfEmptyListIsEmptyString() throws JaxenException {
150         
151         BaseXPath xpath = new DOMXPath("/element");
152         doc.appendChild(doc.createElement("root"));
153         
154         String stringValue = xpath.stringValueOf(doc);
155         assertEquals("", stringValue);
156         
157     }
158 
159     public void testAllNodesQuery() throws JaxenException, ParserConfigurationException {
160         
161         BaseXPath xpath = new DOMXPath("//. | /");
162         org.w3c.dom.Element root = doc.createElementNS("http://www.example.org/", "root");
163         doc.appendChild(root);
164         
165         String stringValue = xpath.stringValueOf(doc);
166         assertEquals("", stringValue);
167         
168     }
169 
170     
171     public void testAncestorAxis() throws JaxenException {
172         
173         BaseXPath xpath = new DOMXPath("ancestor::*");
174         org.w3c.dom.Element root = doc.createElementNS("", "root");
175         org.w3c.dom.Element parent = doc.createElementNS("", "parent");
176         doc.appendChild(root);
177         org.w3c.dom.Element child = doc.createElementNS("", "child");
178         root.appendChild(parent);
179         parent.appendChild(child);
180         
181         List result = xpath.selectNodes(child);
182         assertEquals(2, result.size());
183         assertEquals(root, result.get(0));   
184         assertEquals(parent, result.get(1));
185         
186     }    
187     
188     
189     public void testPrecedingSiblingAxisIsInDocumentOrder() throws JaxenException {
190         
191         BaseXPath xpath = new DOMXPath("preceding-sibling::*");
192         org.w3c.dom.Element root = doc.createElementNS("", "root");
193         doc.appendChild(root);
194         org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
195         root.appendChild(child1);
196         org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
197         root.appendChild(child2);
198         org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
199         root.appendChild(child3);
200         
201         List result = xpath.selectNodes(child3);
202         assertEquals(2, result.size());
203         assertEquals(child1, result.get(0));   
204         assertEquals(child2, result.get(1));
205         
206     }    
207     
208     
209     public void testPrecedingAxisIsInDocumentOrder() throws JaxenException {
210         
211         BaseXPath xpath = new DOMXPath("preceding::*");
212         org.w3c.dom.Element root = doc.createElementNS("", "root");
213         doc.appendChild(root);
214         org.w3c.dom.Element parent1 = doc.createElementNS("", "parent1");
215         root.appendChild(parent1);
216         org.w3c.dom.Element parent2 = doc.createElementNS("", "parent2");
217         root.appendChild(parent2);
218         org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
219         parent2.appendChild(child1);
220         org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
221         parent2.appendChild(child2);
222         org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
223         parent2.appendChild(child3);
224         
225         List result = xpath.selectNodes(child3);
226         assertEquals(3, result.size());
227         assertEquals(parent1, result.get(0));   
228         assertEquals(child1, result.get(1));   
229         assertEquals(child2, result.get(2));
230         
231     }    
232     
233     
234     public void testPrecedingAxisWithPositionalPredicate() throws JaxenException {
235         
236         BaseXPath xpath = new DOMXPath("preceding::*[1]");
237         org.w3c.dom.Element root = doc.createElementNS("", "root");
238         doc.appendChild(root);
239         org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
240         root.appendChild(child1);
241         org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
242         root.appendChild(child2);
243         org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
244         root.appendChild(child3);
245         
246         List result = xpath.selectNodes(child3);
247         assertEquals(1, result.size());  
248         assertEquals(child2, result.get(0));
249         
250     }    
251     
252     
253     public void testAncestorAxisWithPositionalPredicate() throws JaxenException {
254         
255         BaseXPath xpath = new DOMXPath("ancestor::*[1]");
256         org.w3c.dom.Element root = doc.createElementNS("", "root");
257         doc.appendChild(root);
258         org.w3c.dom.Element child1 = doc.createElementNS("", "child1");
259         root.appendChild(child1);
260         org.w3c.dom.Element child2 = doc.createElementNS("", "child2");
261         child1.appendChild(child2);
262         org.w3c.dom.Element child3 = doc.createElementNS("", "child3");
263         child2.appendChild(child3);
264         
265         List result = xpath.selectNodes(child3);
266         assertEquals(1, result.size());  
267         assertEquals(child2, result.get(0));
268         
269     }    
270     
271     
272     public void testAncestorOrSelfAxis() throws JaxenException {
273         
274         BaseXPath xpath = new DOMXPath("ancestor-or-self::*");
275         org.w3c.dom.Element root = doc.createElementNS("", "root");
276         org.w3c.dom.Element parent = doc.createElementNS("", "parent");
277         doc.appendChild(root);
278         org.w3c.dom.Element child = doc.createElementNS("", "child");
279         root.appendChild(parent);
280         parent.appendChild(child);
281         
282         List result = xpath.selectNodes(child);
283         assertEquals(3, result.size());
284         assertEquals(root, result.get(0));   
285         assertEquals(parent, result.get(1));
286         assertEquals(child, result.get(2));
287         
288     }    
289     
290     
291     // test case for JAXEN-55
292     public void testAbbreviatedDoubleSlashAxis() throws JaxenException {
293         
294         BaseXPath xpath = new DOMXPath("//x");
295         org.w3c.dom.Element a = doc.createElementNS("", "a");
296         org.w3c.dom.Element b = doc.createElementNS("", "b");
297         doc.appendChild(a);
298         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
299         x1.appendChild(doc.createTextNode("1"));
300         a.appendChild(x1);
301         a.appendChild(b);
302         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
303         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
304         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
305         a.appendChild(x4);
306         b.appendChild(x2);
307         b.appendChild(x3);
308         x2.appendChild(doc.createTextNode("2"));
309         x3.appendChild(doc.createTextNode("3"));
310         x4.appendChild(doc.createTextNode("4"));
311         
312         List result = xpath.selectNodes(doc);
313         assertEquals(4, result.size());
314         assertEquals(x1, result.get(0));   
315         assertEquals(x2, result.get(1));   
316         assertEquals(x3, result.get(2));   
317         assertEquals(x4, result.get(3));
318         
319     }    
320     
321     
322     // test case for JAXEN-55
323     public void testAncestorFollowedByChildren() throws JaxenException {
324         
325         BaseXPath xpath = new DOMXPath("/a/b/x/ancestor::*/child::x");
326         org.w3c.dom.Element a = doc.createElementNS("", "a");
327         org.w3c.dom.Element b = doc.createElementNS("", "b");
328         doc.appendChild(a);
329         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
330         x1.appendChild(doc.createTextNode("1"));
331         a.appendChild(x1);
332         a.appendChild(b);
333         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
334         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
335         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
336         a.appendChild(x4);
337         b.appendChild(x2);
338         b.appendChild(x3);
339         x2.appendChild(doc.createTextNode("2"));
340         x3.appendChild(doc.createTextNode("3"));
341         x4.appendChild(doc.createTextNode("4"));
342         
343         List result = xpath.selectNodes(doc);
344         assertEquals(4, result.size());
345         assertEquals(x1, result.get(0));   
346         assertEquals(x2, result.get(1));   
347         assertEquals(x3, result.get(2));   
348         assertEquals(x4, result.get(3));
349         
350     }    
351     
352     
353     // test case for JAXEN-55
354     public void testDescendantAxis() throws JaxenException {
355         
356         BaseXPath xpath = new DOMXPath("/descendant::x");
357         org.w3c.dom.Element a = doc.createElementNS("", "a");
358         org.w3c.dom.Element b = doc.createElementNS("", "b");
359         doc.appendChild(a);
360         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
361         x1.appendChild(doc.createTextNode("1"));
362         a.appendChild(x1);
363         a.appendChild(b);
364         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
365         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
366         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
367         a.appendChild(x4);
368         b.appendChild(x2);
369         b.appendChild(x3);
370         x2.appendChild(doc.createTextNode("2"));
371         x3.appendChild(doc.createTextNode("3"));
372         x4.appendChild(doc.createTextNode("4"));
373         
374         List result = xpath.selectNodes(doc);
375         assertEquals(4, result.size());
376         assertEquals(x1, result.get(0));   
377         assertEquals(x2, result.get(1));   
378         assertEquals(x3, result.get(2));   
379         assertEquals(x4, result.get(3));
380         
381     }    
382     
383     public void testDescendantAxisWithAttributes() throws JaxenException {
384         
385         BaseXPath xpath = new DOMXPath("/descendant::x/@*");
386         org.w3c.dom.Element a = doc.createElementNS("", "a");
387         org.w3c.dom.Element b = doc.createElementNS("", "b");
388         doc.appendChild(a);
389         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
390         a.appendChild(x1);
391         a.appendChild(b);
392         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
393         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
394         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
395         a.appendChild(x4);
396         b.appendChild(x2);
397         b.appendChild(x3);
398         
399         Attr a1 = doc.createAttribute("name");
400         a1.setNodeValue("1");
401         x1.setAttributeNode(a1);
402         Attr a2 = doc.createAttribute("name");
403         a2.setNodeValue("2");
404         x2.setAttributeNode(a2);
405         Attr a3 = doc.createAttribute("name");
406         a3.setNodeValue("3");
407         x3.setAttributeNode(a3);
408         Attr a4 = doc.createAttribute("name");
409         a4.setNodeValue("4");
410         x4.setAttributeNode(a4);
411         
412         List result = xpath.selectNodes(doc);
413         assertEquals(4, result.size());
414         assertEquals(a1, result.get(0));   
415         assertEquals(a2, result.get(1));   
416         assertEquals(a3, result.get(2));   
417         assertEquals(a4, result.get(3));
418         
419     }    
420     
421     public void testDescendantAxisWithNamespaceNodes() throws JaxenException {
422         
423         BaseXPath xpath = new DOMXPath("/descendant::x/namespace::node()");
424         org.w3c.dom.Element a = doc.createElementNS("", "a");
425         org.w3c.dom.Element b = doc.createElementNS("", "b");
426         doc.appendChild(a);
427         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
428         a.appendChild(x1);
429         a.appendChild(b);
430         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
431         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
432         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
433         a.appendChild(x4);
434         b.appendChild(x2);
435         b.appendChild(x3);
436         
437         Attr a1 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:a");
438         a1.setNodeValue("http://www.example.org/");
439         x1.setAttributeNode(a1);
440         Attr a2 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:b");
441         a2.setNodeValue("http://www.example.org/");
442         x2.setAttributeNode(a2);
443         Attr a3 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:c");
444         a3.setNodeValue("http://www.example.org/");
445         x3.setAttributeNode(a3);
446         Attr a4 = doc.createAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:d");
447         a4.setNodeValue("http://www.example.org/");
448         x4.setAttributeNode(a4);
449         
450         List result = xpath.selectNodes(doc);
451         assertEquals(8, result.size());
452         Iterator iterator = result.iterator();
453         StringBuffer sb = new StringBuffer(4);
454         while (iterator.hasNext()) {
455             NamespaceNode ns = (NamespaceNode) iterator.next();
456             if (ns.getNodeValue().equals("http://www.example.org/")) {
457                 String name = ns.getNodeName();
458                 sb.append(name);
459             }
460         }
461         assertEquals("abcd", sb.toString());
462         
463     }    
464     
465     public void testMultipleAttributesOnElement() throws JaxenException {
466         
467         BaseXPath xpath = new DOMXPath("/descendant::x/@*");
468         org.w3c.dom.Element a = doc.createElementNS("", "a");
469         org.w3c.dom.Element b = doc.createElementNS("", "b");
470         doc.appendChild(a);
471         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
472         a.appendChild(x1);
473         a.appendChild(b);
474         
475         Attr a1 = doc.createAttribute("name1");
476         a1.setNodeValue("1");
477         x1.setAttributeNode(a1);
478         Attr a2 = doc.createAttribute("name2");
479         a2.setNodeValue("2");
480         x1.setAttributeNode(a2);
481         Attr a3 = doc.createAttribute("name3");
482         a3.setNodeValue("3");
483         x1.setAttributeNode(a3);
484         Attr a4 = doc.createAttribute("name4");
485         a4.setNodeValue("4");
486         x1.setAttributeNode(a4);
487         
488         List result = xpath.selectNodes(doc);
489         assertEquals(4, result.size());
490         assertTrue(result.contains(a1));
491         assertTrue(result.contains(a2));
492         assertTrue(result.contains(a3));
493         assertTrue(result.contains(a4));
494         
495     }   
496     
497     public void testXMLNamespaceAttributeOrderOnAncestorAxis() 
498       throws IOException, JaxenException {
499      
500         org.w3c.dom.Element superroot = doc.createElement("superroot");
501         doc.appendChild(superroot);
502         org.w3c.dom.Element root = doc.createElement("root");
503         superroot.appendChild(root);
504         
505         org.w3c.dom.Attr p0 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id");
506         p0.setValue("p0");
507         superroot.setAttributeNodeNS(p0);
508         org.w3c.dom.Attr p1 = doc.createAttributeNS("http://www.w3.org/XML/1998/namespace", "xml:id");
509         p1.setValue("p1");
510         root.setAttributeNodeNS(p1);
511         
512         org.w3c.dom.Element child = doc.createElement("child312");
513         root.appendChild(child);
514         
515         BaseXPath xpath = new DOMXPath("ancestor::*/@xml:*");
516         List result = xpath.selectNodes(child);
517         assertEquals(2, result.size());
518         assertEquals(p0, result.get(0));
519         assertEquals(p1, result.get(1));
520         
521     }
522     
523     public void testDescendantAxisWithAttributesAndChildren() throws JaxenException {
524         
525         BaseXPath xpath = new DOMXPath("/descendant::x/@* | /descendant::x");
526         org.w3c.dom.Element a = doc.createElementNS("", "a");
527         org.w3c.dom.Element b = doc.createElementNS("", "b");
528         doc.appendChild(a);
529         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
530         a.appendChild(x1);
531         a.appendChild(b);
532         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
533         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
534         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
535         a.appendChild(x4);
536         b.appendChild(x2);
537         b.appendChild(x3);
538         
539         Attr a1 = doc.createAttribute("name");
540         a1.setNodeValue("1");
541         x1.setAttributeNode(a1);
542         Attr a2 = doc.createAttribute("name");
543         a2.setNodeValue("2");
544         x2.setAttributeNode(a2);
545         Attr a3 = doc.createAttribute("name");
546         a3.setNodeValue("3");
547         x3.setAttributeNode(a3);
548         Attr a4 = doc.createAttribute("name");
549         a4.setNodeValue("4");
550         x4.setAttributeNode(a4);
551         
552         List result = xpath.selectNodes(doc);
553         assertEquals(8, result.size());
554         assertEquals(x1, result.get(0));   
555         assertEquals(a1, result.get(1));   
556         assertEquals(x2, result.get(2));   
557         assertEquals(a2, result.get(3));
558         assertEquals(x3, result.get(4));   
559         assertEquals(a3, result.get(5));   
560         assertEquals(x4, result.get(6));   
561         assertEquals(a4, result.get(7));
562         
563     }    
564     
565     public void testAncestorAxisWithAttributes() throws JaxenException {
566         
567         BaseXPath xpath = new DOMXPath("ancestor::*/@*");
568         org.w3c.dom.Element a = doc.createElementNS("", "a");
569         org.w3c.dom.Element b = doc.createElementNS("", "b");
570         doc.appendChild(a);
571         a.appendChild(b);
572         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
573         b.appendChild(x3);
574         
575         Attr a1 = doc.createAttribute("name");
576         a1.setNodeValue("1");
577         a.setAttributeNode(a1);
578         Attr a2 = doc.createAttribute("name");
579         a2.setNodeValue("2");
580         b.setAttributeNode(a2);
581         Attr a3 = doc.createAttribute("name");
582         x3.setNodeValue("3");
583         x3.setAttributeNode(a3);
584         
585         List result = xpath.selectNodes(x3);
586         assertEquals(2, result.size());
587         assertEquals(a1, result.get(0));   
588         assertEquals(a2, result.get(1)); 
589         
590     }    
591     
592     // test for Jaxen-83
593     public void testPrincipalNodeTypeOfSelfAxisIsElement() throws JaxenException {
594         
595         BaseXPath xpath = new DOMXPath("child/@*[self::test]");
596         org.w3c.dom.Element a = doc.createElementNS("", "child");
597         org.w3c.dom.Attr test = doc.createAttributeNS("", "test");
598         test.setValue("value");
599         a.setAttributeNode(test);
600         doc.appendChild(a);
601         
602         List result = xpath.selectNodes(doc);
603         assertEquals(0, result.size()); 
604         
605     }
606     
607     // test to make sure Jaxen-83 fix doesn't go too far
608     public void testSelfAxisWithNodeTestCanReturnNonPrincipalNodeType() throws JaxenException {
609         
610         BaseXPath xpath = new DOMXPath("child/@*[self::node()]");
611         org.w3c.dom.Element a = doc.createElementNS("", "child");
612         org.w3c.dom.Attr test = doc.createAttributeNS("", "test");
613         test.setValue("value");
614         a.setAttributeNode(test);
615         doc.appendChild(a);
616         
617         List result = xpath.selectNodes(doc);
618         assertEquals(1, result.size());   
619         
620     } 
621     
622     // another Jaxen-55 test to try to pin down exactly what does
623     // and doesn't work
624     public void testDescendantOrSelfAxis() throws JaxenException {
625         
626         BaseXPath xpath = new DOMXPath("/descendant-or-self::x");
627         org.w3c.dom.Element a = doc.createElementNS("", "a");
628         org.w3c.dom.Element b = doc.createElementNS("", "b");
629         doc.appendChild(a);
630         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
631         x1.appendChild(doc.createTextNode("1"));
632         a.appendChild(x1);
633         a.appendChild(b);
634         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
635         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
636         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
637         a.appendChild(x4);
638         b.appendChild(x2);
639         b.appendChild(x3);
640         x2.appendChild(doc.createTextNode("2"));
641         x3.appendChild(doc.createTextNode("3"));
642         x4.appendChild(doc.createTextNode("4"));
643         
644         List result = xpath.selectNodes(doc);
645         assertEquals(4, result.size());
646         assertEquals(x1, result.get(0));   
647         assertEquals(x2, result.get(1));   
648         assertEquals(x3, result.get(2));   
649         assertEquals(x4, result.get(3));
650         
651     }    
652     
653     
654     public void testDuplicateNodes() throws JaxenException {
655         
656         BaseXPath xpath = new DOMXPath("//x | //*");
657         org.w3c.dom.Element a = doc.createElementNS("", "a");
658         org.w3c.dom.Element b = doc.createElementNS("", "b");
659         doc.appendChild(a);
660         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
661         x1.appendChild(doc.createTextNode("1"));
662         a.appendChild(x1);
663         a.appendChild(b);
664         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
665         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
666         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
667         a.appendChild(x4);
668         b.appendChild(x2);
669         b.appendChild(x3);
670         x2.appendChild(doc.createTextNode("2"));
671         x3.appendChild(doc.createTextNode("3"));
672         x4.appendChild(doc.createTextNode("4"));
673         
674         List result = xpath.selectNodes(doc);
675         assertEquals(6, result.size());
676         
677     }    
678        
679     public void testUnionOfNodesWithNonNodes() throws JaxenException {
680         
681         BaseXPath xpath = new DOMXPath("count(//*) | //x ");
682         org.w3c.dom.Element a = doc.createElementNS("", "a");
683         org.w3c.dom.Element b = doc.createElementNS("", "b");
684         doc.appendChild(a);
685         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
686         x1.appendChild(doc.createTextNode("1"));
687         a.appendChild(x1);
688         a.appendChild(b);
689         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
690         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
691         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
692         a.appendChild(x4);
693         b.appendChild(x2);
694         b.appendChild(x3);
695         x2.appendChild(doc.createTextNode("2"));
696         x3.appendChild(doc.createTextNode("3"));
697         x4.appendChild(doc.createTextNode("4"));
698         
699         try {
700             xpath.selectNodes(doc);
701             fail("Allowed union with non-node-set");
702         }
703         catch (JaxenException ex) {
704             assertNotNull(ex.getMessage());
705         }
706         
707     }    
708     
709     public void testUnionOfEmptyNodeSetWithNonNodes() throws JaxenException {
710         
711         BaseXPath xpath = new DOMXPath("//y | count(//*)");
712         org.w3c.dom.Element a = doc.createElementNS("", "a");
713         org.w3c.dom.Element b = doc.createElementNS("", "b");
714         doc.appendChild(a);
715         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
716         x1.appendChild(doc.createTextNode("1"));
717         a.appendChild(x1);
718         a.appendChild(b);
719         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
720         b.appendChild(x2);
721         x2.appendChild(doc.createTextNode("2"));
722         
723         try {
724             xpath.selectNodes(doc);
725             fail("Allowed union with non-node-set");
726         }
727         catch (JaxenException ex) {
728             assertNotNull(ex.getMessage());
729         }
730         
731     } 
732     
733     public void testSelectSingleNodeSelectsNothing() 
734       throws JaxenException {
735         
736         BaseXPath xpath = new DOMXPath("id('p1')");
737         org.w3c.dom.Element a = doc.createElementNS("", "a");
738         doc.appendChild(a);
739         Object result = xpath.selectSingleNode(doc);
740         assertNull(result);
741         
742     } 
743     
744     
745     public void testBooleanValueOfEmptyNodeSetIsFalse() 
746       throws JaxenException {
747         
748         BaseXPath xpath = new DOMXPath("/b/c");
749         org.w3c.dom.Element a = doc.createElementNS("", "a");
750         doc.appendChild(a);
751         List result = xpath.selectNodes(doc);
752         assertTrue(! xpath.booleanValueOf(result));
753         
754     } 
755     
756     public void testUnionUsesDocumentOrder() throws JaxenException {
757         
758         BaseXPath xpath = new DOMXPath("/descendant::x | /a | /a/b");
759         org.w3c.dom.Element a = doc.createElementNS("", "a");
760         org.w3c.dom.Element b = doc.createElementNS("", "b");
761         doc.appendChild(a);
762         org.w3c.dom.Element x1 = doc.createElementNS("", "x");
763         x1.appendChild(doc.createTextNode("1"));
764         a.appendChild(x1);
765         a.appendChild(b);
766         org.w3c.dom.Element x2 = doc.createElementNS("", "x");
767         org.w3c.dom.Element x3 = doc.createElementNS("", "x");
768         org.w3c.dom.Element x4 = doc.createElementNS("", "x");
769         a.appendChild(x4);
770         b.appendChild(x2);
771         b.appendChild(x3);
772         x2.appendChild(doc.createTextNode("2"));
773         x3.appendChild(doc.createTextNode("3"));
774         x4.appendChild(doc.createTextNode("4"));
775         
776         List result = xpath.selectNodes(doc);
777         assertEquals(6, result.size());
778         assertEquals(a, result.get(0));   
779         assertEquals(x1, result.get(1));   
780         assertEquals(b, result.get(2));   
781         assertEquals(x2, result.get(3));   
782         assertEquals(x3, result.get(4));   
783         assertEquals(x4, result.get(5));
784         
785     }   
786     
787     
788 }