1 61 62 package org.jaxen.function; 63 64 import javax.xml.parsers.DocumentBuilder ; 65 import javax.xml.parsers.DocumentBuilderFactory ; 66 import javax.xml.parsers.ParserConfigurationException ; 67 68 import junit.framework.TestCase; 69 70 import org.jaxen.FunctionCallException; 71 import org.jaxen.JaxenException; 72 import org.jaxen.XPath; 73 import org.jaxen.dom.DOMXPath; 74 import org.w3c.dom.Document ; 75 76 80 public class SumTest extends TestCase { 81 82 private Document doc; 83 84 public void setUp() throws ParserConfigurationException 85 { 86 DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); 87 factory.setNamespaceAware(true); 88 DocumentBuilder builder = factory.newDocumentBuilder(); 89 doc = builder.newDocument(); 90 doc.appendChild(doc.createElement("root")); 91 } 92 93 94 public SumTest(String name) { 95 super(name); 96 } 97 98 public void testSumOfNumber() throws JaxenException 99 { 100 try 101 { 102 XPath xpath = new DOMXPath( "sum(3)" ); 103 xpath.selectNodes( doc ); 104 fail("sum of non-node-set"); 105 } 106 catch (FunctionCallException e) 107 { 108 assertEquals("The argument to the sum function must be a node-set", e.getMessage()); 109 } 110 } 111 112 public void testSumNoArguments() throws JaxenException 113 { 114 try 115 { 116 XPath xpath = new DOMXPath( "sum()" ); 117 xpath.selectNodes( doc ); 118 fail("sum of nothing"); 119 } 120 catch (FunctionCallException e) 121 { 122 assertEquals("sum() requires one argument.", e.getMessage()); 123 } 124 } 125 126 } 127 | Popular Tags |