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 VariableContextTest 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 101 public void testUnresolvableVariable() throws JaxenException { 102 103 DOMXPath xpath = new DOMXPath("$a/root"); 104 105 try { 106 xpath.evaluate(doc); 107 fail("Evaluated nonexistent variable"); 108 } 109 catch (UnresolvableException ex) { 110 assertNotNull(ex.getMessage()); 111 } 112 113 } 114 115 public void testGetVariableContext() throws JaxenException { 116 DOMXPath xpath = new DOMXPath("/root/child"); 117 assertNotNull(xpath.getVariableContext()); 118 } 119 120 } 121 | Popular Tags |