1 16 package org.apache.commons.jelly.tags.junit; 17 18 import org.apache.commons.jelly.JellyTagException; 19 import org.apache.commons.jelly.XMLOutput; 20 import org.apache.commons.jelly.MissingAttributeException; 21 import org.apache.commons.jelly.expression.Expression; 22 23 import org.jaxen.JaxenException; 24 import org.jaxen.XPath; 25 26 33 public class AssertTag extends AssertTagSupport { 34 35 36 private Expression test; 37 38 39 private XPath xpath; 40 41 public AssertTag() { 42 } 43 44 public void doTag(XMLOutput output) throws JellyTagException { 47 if (test == null && xpath == null) { 48 throw new MissingAttributeException( "test" ); 49 } 50 if (test != null) { 51 if (! test.evaluateAsBoolean(context)) { 52 fail( getBodyText(), "evaluating test: "+ test.getExpressionText() ); 53 } 54 } 55 else { 56 try { 57 Object xpathContext = getXPathContext(); 58 if (! xpath.booleanValueOf(xpathContext)) { 59 fail( getBodyText(), "evaluating xpath: "+ xpath ); 60 } 61 } catch (JaxenException anException) { 62 throw new JellyTagException("Error evaluating xpath", anException); 63 } 64 65 } 66 67 } 68 69 72 77 public void setTest(Expression test) { 78 this.test = test; 79 } 80 81 86 public void setXpath(XPath xpath) { 87 this.xpath = xpath; 88 } 89 } 90 | Popular Tags |