Extended Test Script Services Reference |
This class lets a method in a stub access a lookup table.
A lookup table lets you test a component whose operation depends upon an associated component that is still in the development stages. To test the component, you first provide a stub of the unfinished component that contains that component's methods. When the component-under-test calls a method in the stub, the method simulates operation by retrieving information from the lookup table -- information that would otherwise be generated during normal execution in the completed component. The method then presents the retrieved information to the calling component-under-test.
The information that a stub's method retrieves from the lookup table depends upon the values that the component-under-test passes to the method. In other words, a method finds the lookup-table row that contains the parameter values that the component-under-test passed to it, and then retrieves the appropriate value (return value or exception) from that same lookup-table row.
A lookup table typically has multiple rows, with each row representing a different set of inputs and outputs. This allows a method in the component-under-test to be executed multiple times against the stub, supplying different input values and retrieving different output values each time.
In the following example of a lookup table for a mortgage calculation method, amount
, interest
, and months
are input values, while expectedReturn
and expectedException
are the corresponding output values:
Typically, you create a lookup table for each stub method that is called during testing of the component-under-test.
The underlying files used for both lookup tables and datapools are the same. As a result, when it is time to replace the stub with the completed component, you can use the lookup table as a datapool when you test the associated component-under-test.
Note: A stub is not a test script. Consequently, it does not require a testMain()
method.
public class LookUpTable extends java.lang.Object java.lang.Object | +--com.rational.test.ct.LookUpTable
Commonly used with QualityArchitect.
This class requires QualityArchitect.
The following sample code opens and retrieves values from the lookup table ManageAccountsBean_getSavingsBalance_L
. The code contains examples of both LookUpTable
methods and TestLog
methods. TestLog
methods are described in TestLog Class.
public double getSavingsBalance(long accountID) throws java.rmi.RemoteException,javax.naming.NamingException, javax.ejb.EJBException { String[] ParamNames = new String[1]; ParamNames[0] = "accountID"; return getSavingsBalance_lookup(ParamNames, accountID); } private double getSavingsBalance_lookup(String[] ParamNames, long accountID) throws java.rmi.RemoteException, javax.naming.NamingException,javax.ejb.EJBException{ boolean bThrow = false; double retval = 0; TestLog log = new TestLog(); LookUpTable lookup = new LookUpTable(); String sRetval = null; try { lookup.open("ManageAccountsBean_getSavingsBalance_L"); String[] values = new String[1]; values[0] = Long.toString(accountID); log.writeStubMessage( "ManageAccounts stub,getSavingsBalance method. ", "Entered with following values: " + values[0] + " " + " "); lookup.find(ParamNames, values); Throwable eExpected = lookup.getExpectedException(); if (eExpected != null) { log.writeStubMessage( "ManageAccounts, getSavingsBalance method. ", "Throwing exception: " + eExpected.getClass().getName()); bThrow = true; throw eExpected; } else { sRetval = lookup.getReturnValue(); if (sRetval != null) retval = Double.valueOf(sRetval).doubleValue(); } lookup.close(); } catch (LookUpTableException e) { log.writeStubException("Lookup table Error in ManageAccounts stub, getCheckingBalance method: ", e); lookup.close(); } catch (java.rmi.RemoteException e) { lookup.close(); throw e; } catch (javax.naming.NamingException e) { lookup.close(); throw e; } catch (javax.ejb.EJBException e) { lookup.close(); throw e; } catch (Throwable e) { lookup.close(); if (bThrow) { LookUpTableException ex = new LookUpTableException( "Lookup table returned an invalid exception, " + e.getClass().getName() +" for this method."); log.writeStubException("Lookup table Error in ManageAccounts stub, getSavingsBalance method: ", ex); } else { log.writeStubException("Lookup table Error in ManageAccounts stub, getSavingsBalance method: Unknown error. ", e); } } log.writeStubMessage("ManageAccounts stub, getSavingsBalance method. ","Returning " + sRetval); return retval; }
This class contains the following methods:
close()
Closes the current lookup table (that is, the lookup table associated with this instance of the
LookUpTable
class).
find()
Sets the cursor to the row in the current lookup table that contains the column value(s) passed to it.
getExpectedException()
Returns the contents of the expectedException column in the current lookup table row.
getReturnValue()
Returns the contents of the expectedReturn column in the current lookup table row.
getValue()
Returns the contents of the specified column in the current lookup table row.
open()
Opens the specified lookup table.
public LookUpTable
()
Closes the current lookup table (that is, the lookup table associated with this instance of the LookUpTable class).
public void close
()
For an example of this method, see LookUpTable Example.
Sets the cursor to the row in the current lookup table that contains the column value(s) passed to it.
public booleanfind
(java.lang.String[]names
, java.lang.String[]values
)
names
An array containing one or more lookup-table column names.
values
An array containing a value for each corresponding column name passed to the method.
If true
, the cursor was successfully set to the row that matched the specified criteria. If false
, a row could not be found that matched the specified criteria.
This method throws the following exception:
com.rational.test.ct.LookUpTableException
. Reports problems attempting to set the cursor to a row in the lookup table.
If you handle this exception and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass Result for the script.
Subsequent value-retrieval methods act upon the row with the cursor.
If multiple rows contain the passed value(s), this method throws an exception.
For an example of this method, see LookUpTable Example.
Returns the contents of the expectedException column in the current lookup table row.
public java.lang.Throwable getExpectedException
()
The contents of the Exception column in the current lookup table row.
This method throws the following exception:
com.rational.test.ct.LookUpTableException
. Reports problems attempting to retrieve the contents of the Exception column.
If you handle this exception and do not log it, TestManager is not aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass Result for the script.
For an example of this method, see LookUpTable Example.
Returns the contents of the expectedReturn column in the current lookup table row.
public java.lang.String getReturnValue
()
The contents of the Return Value column in the current lookup table row.
This method throws the following exception:
com.rational.test.ct.LookUpTableException
. Reports problems attempting to retrieve the contents of the Return Value column.
If you handle this exception and do not log it, TestManager is not be aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass Result for the script.
For an example of this method, see LookUpTable Example.
Returns the contents of the specified column in the current lookup table row.
public java.lang.StringgetValue
(java.lang.StringcolName
)
colName
The name of the column containing the value to retrieve.
The contents of the specified column in the current lookup table row.
An auto-generated lookup table contains an input column for each parameter and two output columns -- expectedReturn and expectedException. If you use additional output columns in a lookup table, you can use getValue()
to retrieve values from those additional output columns.
This method throws the following exception:
com.rational.test.ct.LookUpTableException
. Reports problems attempting to retrieve the contents of the specified column.
If you handle this exception and do not log it, TestManager is not be aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass Result for the script.
Opens the specified lookup table.
public voidopen
(java.lang.Stringtablename
)
tablename
The name of the lookup table to open.
This method throws the following exception:
com.rational.test.ct.LookUpTableException
. Reports problems attempting to open the specified lookup table.
If you handle this exception and do not log it, TestManager is not be aware of the exception and does not log a Fail result for it. The script continues to run, and TestManager could log a Pass Result for the script.
Only one lookup table can exist for a given instance of the LookUpTable
class.
For an example of this method, see LookUpTable Example.
Rational Test Script Services for Java | Rational Software Corporation |
Copyright (c) 2003, Rational Software Corporation | http://www.rational.com support@rational.com info@rational.com |