org.apache.commons.jexl2.junit
Class Asserter

java.lang.Object
  extended by junit.framework.Assert
      extended by org.apache.commons.jexl2.junit.Asserter

public class Asserter
extends junit.framework.Assert

A utility class for performing JUnit based assertions using Jexl expressions. This class can make it easier to do unit tests using Jexl navigation expressions.

Since:
1.0

Constructor Summary
Asserter(JexlEngine jexl)
          Create an asserter.
 
Method Summary
 void assertExpression(String expression, Object expected)
          Performs an assertion that the value of the given Jexl expression evaluates to the given expected value.
 void failExpression(String expression, String matchException)
          Performs an assertion that the expression fails throwing an exception.
 JexlContext getContext()
          Retrieves the underlying JEXL context.
 JexlEngine getEngine()
          Retrieves the underlying JEXL engine.
 Object removeVariable(String name)
          Removes a variable of a certain name from the context.
 void setVariable(String name, Object value)
          Puts a variable of a certain name in the context so that it can be used from assertion expressions.
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, failNotEquals, failNotSame, failSame, format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Asserter

public Asserter(JexlEngine jexl)
Create an asserter.

Parameters:
jexl - the JEXL engine to use
Method Detail

getEngine

public JexlEngine getEngine()
Retrieves the underlying JEXL engine.

Returns:
the JEXL engine

getContext

public JexlContext getContext()
Retrieves the underlying JEXL context.

Returns:
the JEXL context

assertExpression

public void assertExpression(String expression,
                             Object expected)
                      throws Exception
Performs an assertion that the value of the given Jexl expression evaluates to the given expected value.

Parameters:
expression - is the Jexl expression to evaluate
expected - is the expected value of the expression
Throws:
Exception - if the expression could not be evaluationed or an assertion fails

failExpression

public void failExpression(String expression,
                           String matchException)
                    throws Exception
Performs an assertion that the expression fails throwing an exception. If matchException is not null, the exception message is expected to match it as a regexp. The engine is temporarily switched to strict * verbose to maximize error detection abilities.

Parameters:
expression - the expression that should fail
matchException - the exception message pattern
Throws:
Exception - if the expression did not fail or the exception did not match the expected pattern

setVariable

public void setVariable(String name,
                        Object value)
Puts a variable of a certain name in the context so that it can be used from assertion expressions.

Parameters:
name - variable name
value - variable value

removeVariable

public Object removeVariable(String name)
Removes a variable of a certain name from the context.

Parameters:
name - variable name
Returns:
variable value


Copyright © 2001-2011 The Apache Software Foundation. All Rights Reserved.