1 61 62 63 64 package org.jaxen; 65 66 import javax.xml.parsers.DocumentBuilderFactory ; 67 import javax.xml.parsers.ParserConfigurationException ; 68 69 import org.jaxen.dom.DOMXPath; 70 import org.w3c.dom.Document ; 71 import org.w3c.dom.Element ; 72 73 import junit.framework.TestCase; 74 75 84 public class FunctionContextTest extends TestCase 85 { 86 87 private Document doc; 88 89 public void setUp() throws ParserConfigurationException { 90 91 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 92 factory.setNamespaceAware(true); 93 doc = factory.newDocumentBuilder().newDocument(); 94 Element root = doc.createElementNS("http://www.example.org/", "root"); 95 doc.appendChild(root); 96 root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.example.org/"); 97 98 } 99 100 public void testJAXEN50() throws JaxenException { 101 102 DOMXPath xpath = new DOMXPath("true()"); 103 104 SimpleNamespaceContext nsContext = new SimpleNamespaceContext(); 105 nsContext.addElementNamespaces(xpath.getNavigator(), doc); 107 xpath.setNamespaceContext(nsContext); 108 109 boolean result = xpath.booleanValueOf(doc); 110 assertTrue(result); 111 112 } 113 114 public void testUnresolvableFunction() throws JaxenException { 115 116 DOMXPath xpath = new DOMXPath("nonesuch()"); 117 118 try { 119 xpath.evaluate(doc); 120 fail("Evaluated nonexistent function"); 121 } 122 catch (UnresolvableException ex) { 123 assertNotNull(ex.getMessage()); 124 } 125 126 } 127 128 public void testGetFunctionContext() throws JaxenException { 129 DOMXPath xpath = new DOMXPath("/root/child"); 130 assertNotNull(xpath.getFunctionContext()); 131 } 132 133 } 134 | Popular Tags |