org.rhq.bindings.util
Class ScriptAssert

java.lang.Object
  extended by org.rhq.bindings.util.ScriptAssert

public class ScriptAssert
extends Object

This class provides the assertion functions to the scripts. It is heavily inspired by and in part copied from org.testng.Assert class.

We specifically do not use the TestNG class here so that we avoid a runtime dependency on TestNG.


Constructor Summary
ScriptAssert()
           
ScriptAssert(ScriptEngine scriptEngine)
           
 
Method Summary
 void assertEquals(Collection<?> actual, Collection<?> expected)
           
 void assertEquals(Collection<?> actual, Collection<?> expected, String msg)
           
 void assertEquals(Object[] actual, Object[] expected)
           
 void assertEquals(Object[] actual, Object[] expected, String msg)
           
 void assertEquals(Object actual, Object expected)
           
 void assertEquals(Object actual, Object expected, String msg)
           
 void assertEqualsNoOrder(Object[] actual, Object[] expected)
           
 void assertEqualsNoOrder(Object[] actual, Object[] expected, String msg)
           
 void assertExists(String identifier)
           
 void assertFalse(boolean condition)
           
 void assertFalse(boolean condition, String msg)
           
 void assertNotNull(Object object)
           
 void assertNotNull(Object object, String msg)
           
 void assertNotSame(Object actual, Object expected)
           
 void assertNotSame(Object actual, Object expected, String msg)
           
 void assertNull(Object object)
           
 void assertNull(Object object, String msg)
           
 void assertNumberEqualsJS(double actual, double expected, String msg)
          Deprecated. - it is now possible to use assertEquals() with numbers from within javascript because we now only provide assertEquals(Object, Object) to which the numbers convert to correctly.
 void assertSame(Object actual, Object expected)
           
 void assertSame(Object actual, Object expected, String msg)
           
 void assertTrue(boolean condition)
           
 void assertTrue(boolean condition, String msg)
           
 void fail()
           
 void fail(String msg)
           
 void fail(String msg, Throwable throwable)
           
 void init(ScriptEngine engine)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ScriptAssert

public ScriptAssert()

ScriptAssert

public ScriptAssert(ScriptEngine scriptEngine)
Method Detail

init

public void init(ScriptEngine engine)

assertTrue

public void assertTrue(boolean condition,
                       String msg)

assertTrue

public void assertTrue(boolean condition)

assertFalse

public void assertFalse(boolean condition,
                        String msg)

assertFalse

public void assertFalse(boolean condition)

fail

public void fail(String msg,
                 Throwable throwable)

fail

public void fail(String msg)

fail

public void fail()

assertEquals

public void assertEquals(Object actual,
                         Object expected,
                         String msg)

assertEquals

public void assertEquals(Object actual,
                         Object expected)

assertNotNull

public void assertNotNull(Object object)

assertNotNull

public void assertNotNull(Object object,
                          String msg)

assertNull

public void assertNull(Object object)

assertNull

public void assertNull(Object object,
                       String msg)

assertSame

public void assertSame(Object actual,
                       Object expected,
                       String msg)

assertSame

public void assertSame(Object actual,
                       Object expected)

assertNotSame

public void assertNotSame(Object actual,
                          Object expected,
                          String msg)

assertNotSame

public void assertNotSame(Object actual,
                          Object expected)

assertEquals

public void assertEquals(Collection<?> actual,
                         Collection<?> expected)

assertEquals

public void assertEquals(Collection<?> actual,
                         Collection<?> expected,
                         String msg)

assertEquals

public void assertEquals(Object[] actual,
                         Object[] expected,
                         String msg)

assertEqualsNoOrder

public void assertEqualsNoOrder(Object[] actual,
                                Object[] expected,
                                String msg)

assertEquals

public void assertEquals(Object[] actual,
                         Object[] expected)

assertEqualsNoOrder

public void assertEqualsNoOrder(Object[] actual,
                                Object[] expected)

assertExists

public void assertExists(String identifier)

assertNumberEqualsJS

@Deprecated
public void assertNumberEqualsJS(double actual,
                                            double expected,
                                            String msg)
Deprecated. - it is now possible to use assertEquals() with numbers from within javascript because we now only provide assertEquals(Object, Object) to which the numbers convert to correctly.

JavaScript has only a single numeric type such that x = 1 and y = 1.0 are considered to be of the same type. From within a (JavaScript) script if you were to call assertEquals(x, y), you would get an exception that looks something like,
 Caused by: javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: The choice of
 Java constructor assertEquals matching JavaScript argument types (number,number,string) is ambiguous;
 candidate constructors are:
 void assertEquals(java.lang.String,java.lang.String,java.lang.String)
 void assertEquals(double,double,double)
 void assertEquals(float,float,float)
 void assertEquals(long,long,java.lang.String)
 void assertEquals(byte,byte,java.lang.String)
 void assertEquals(char,char,java.lang.String)
 void assertEquals(short,short,java.lang.String)
 void assertEquals(int,int,java.lang.String) (#1) in  at line number 1
     
To avoid the ambiguity when comparing numbers in JavaScript scripts, it is recommended to use this method.

Parameters:
actual - The actual value
expected - The expected value
msg - A useful, meaningful error message


Copyright © 2008-2012 Red Hat, Inc.. All Rights Reserved.