Extended Test Script Services Reference

prevnext

LookUpTable Class


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:

amount
interest
months
expectedReturn
expectedException
100000
0.0700
240
775.30
125000
00725
300
bank.BadRateException
150000
0.0750
360
1048.83

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.


Overview

public class LookUpTable extends java.lang.Object
java.lang.Object
  |
  +--com.rational.test.ct.LookUpTable

Applicability

Commonly used with QualityArchitect.

This class requires QualityArchitect.


LookUpTable Example

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;
}

Summary

This class contains the following methods:

Method Description
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.


Constructor


Syntax

public LookUpTable()

LookUpTable.close()

Closes the current lookup table (that is, the lookup table associated with this instance of the LookUpTable class).


Syntax

public void close()

Example

For an example of this method, see LookUpTable Example.


LookUpTable.find()

Sets the cursor to the row in the current lookup table that contains the column value(s) passed to it.


Syntax

public boolean find(java.lang.String[] names, 
java.lang.String[] values)

Element Description
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.


Return Value

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.


Exceptions

This method throws the following exception:

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.


Comments

Subsequent value-retrieval methods act upon the row with the cursor.

If multiple rows contain the passed value(s), this method throws an exception.


Example

For an example of this method, see LookUpTable Example.


LookUpTable.getExpectedException()

Returns the contents of the expectedException column in the current lookup table row.


Syntax

public java.lang.Throwable getExpectedException()

Return Value

The contents of the Exception column in the current lookup table row.


Exceptions

This method throws the following exception:

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.


Example

For an example of this method, see LookUpTable Example.


LookUpTable.getReturnValue()

Returns the contents of the expectedReturn column in the current lookup table row.


Syntax

public java.lang.String getReturnValue()

Return Value

The contents of the Return Value column in the current lookup table row.


Exceptions

This method throws the following exception:

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.


Example

For an example of this method, see LookUpTable Example.


LookUpTable.getValue()

Returns the contents of the specified column in the current lookup table row.


Syntax

public java.lang.String getValue(java.lang.String colName)

Element Description
colName The name of the column containing the value to retrieve.


Return Value

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.


Exceptions

This method throws the following exception:

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.


LookUpTable.open()

Opens the specified lookup table.


Syntax

public void open(java.lang.String tablename)

Element Description
tablename The name of the lookup table to open.


Exceptions

This method throws the following exception:

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.


Comments

Only one lookup table can exist for a given instance of the LookUpTable class.


Example

For an example of this method, see LookUpTable Example.

prevnext


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