opencard.tests.terminal
Class TestBean
java.lang.Object
|
+--opencard.core.service.CardService
|
+--opencard.tests.terminal.TestBean
- Direct Known Subclasses:
- CardEvent, CloseTerminal, CommandBean, GetATR, OpenTerminal, TerminalInfo, ThreadStarter, WaitForCard
- public abstract class TestBean
- extends CardService
The TestBean is the superclass of all Beans used for the OCF
compliance test.
This superclass implements the largest part of the required functionality:
- Check if the Result is expected or not (Low-level evaluation)
- Friendly look Log-Outputs/Traces.
In order to check the result a hashtable is maintained where all likely
possible results of this bean are listed and marked as Expected
or unexpected.
In the Hashtables only objects can be stored (e.g. exception classes,
ByteArray-objects). int and byte[] will be wrapped into ByteArray-objects!
Note: Under certain circumstances even an error return code could
be an expected result (e.g. if your test case tries to check
error handling by sending invalid commands)
Note: results are Exceptions, Return Codes of Commands ...
Returned Data of Commands has to be evaluated by the test case itself.
If an unexepected result occurs an TestFailedException is thrown.
This Exception can be caught and interpreted by the TestCase.
When using a TestBean in a test case just do the following things
- Instantiate the Bean
e.g.: SelectBean select = new SelectBean();
- Select the Card type this test should be performed with (only for CommandBeans)
e.g.: setCardType(CommandCodeFactory.IBM_MFC_4F_COS);
- Optional: Initialize it (depends on the type of test beans)
e.g.: select.initialize(sc);
- Set the specific parameters.
e.g.: select.setPath(new byte[]{(byte)0x2F,(byte)0x01});
- define the likely possible results as expected or unexpected
e.g.: select.addExpectedReturnCode(0x9000);
e.g.: select.addUnxpectedReturnCode(0x9A00);
e.g.: select.addUnxpectedReturnCode(CardTerminalException.class);
- execute the beans
e.g.: boolean result = select.execute()
The beans throws a TestFailedException if the execution fails
(it fails, when an unexpected result occurs).
The beans throws a TestInitException when parameters haven't been
configured correctly.
- Optional: Evaluate the responseData (e.g. of a command)
e.g.: if (responseData().equals ("XY") singHallejullah();
- Version:
- $Id: TestBean.java,v 1.1 1999/12/03 09:31:37 damke Exp $
- See Also:
CommandBean,
opencard.tests.terminal.SelectBean,
opencard.tests.terminal.ByteArray
|
Field Summary |
protected java.util.Hashtable |
resultLookup
Response Code mapping table |
|
Method Summary |
void |
addExpectedResult(int result)
Append a expected Result to the result lookup hashtable. |
void |
addExpectedResult(java.lang.Object result)
Append a expected result Object to the result lookup hashtable. |
void |
addUnexpectedResult(int result)
Append an unexpected Result to the result lookup hashtable. |
void |
addUnexpectedResult(java.lang.Object result)
Append an unexpected result object to the result lookup hashtable. |
protected void |
checkResult()
Check if the currently stored result object is listed as an
expected result in the hashtable.
|
void |
clearResultLookup()
Clear the result lookup hashtable (Delete all entries). |
abstract void |
execute()
Execute the Test Bean using a previously CardService.
|
java.lang.String |
getId()
|
protected java.lang.String |
getLabel()
|
java.lang.Object |
getResult()
|
java.lang.String |
getResultString()
|
java.lang.String |
getTitle()
|
boolean |
isDetails()
|
boolean |
lookupResult(int result)
Lookup in the hashtable if a result is expected
or is not expected |
boolean |
lookupResult(java.lang.Object result)
Lookup in the hashtable if a returned result object is expected
or is not expected |
void |
setDetails(boolean details)
|
void |
setId(java.lang.String id)
|
protected void |
setLabel(java.lang.String label)
|
protected void |
setResult(byte[] resultByteArray)
|
protected void |
setResult(int resultValue)
|
protected void |
setResult(java.lang.Object result)
|
java.lang.String |
toString()
|
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
resultLookup
protected java.util.Hashtable resultLookup
- Response Code mapping table
TestBean
public TestBean()
getLabel
protected java.lang.String getLabel()
setLabel
protected void setLabel(java.lang.String label)
getId
public java.lang.String getId()
setId
public void setId(java.lang.String id)
setDetails
public void setDetails(boolean details)
isDetails
public boolean isDetails()
execute
public abstract void execute()
throws TestFailedException,
TestInitException
- Execute the Test Bean using a previously CardService.
Check the result by looking for the result in the lookup hashtable.
Throw an exception whenever ths execution fails.
- Returns:
- true, if the result returned is defines as expected
- Throws:
- throws - a TestFailedException, if the test fails
(== the result of this exceution is unexpected
or not listed in the result lookup table
setResult
protected void setResult(int resultValue)
setResult
protected void setResult(byte[] resultByteArray)
setResult
protected void setResult(java.lang.Object result)
getResult
public java.lang.Object getResult()
getResultString
public java.lang.String getResultString()
checkResult
protected void checkResult()
throws TestFailedException
- Check if the currently stored result object is listed as an
expected result in the hashtable.
If not listed or listed as unexpected throw an TestFailedException
addExpectedResult
public void addExpectedResult(int result)
- Append a expected Result to the result lookup hashtable.
- Parameters:
Expected - result to be added to the lookup-hashtable
addUnexpectedResult
public void addUnexpectedResult(int result)
- Append an unexpected Result to the result lookup hashtable.
- Parameters:
Unexpected - result to be added to the lookup-hashtable
addExpectedResult
public void addExpectedResult(java.lang.Object result)
- Append a expected result Object to the result lookup hashtable.
- Parameters:
Expected - result object to be added to the lookup-hashtable
addUnexpectedResult
public void addUnexpectedResult(java.lang.Object result)
- Append an unexpected result object to the result lookup hashtable.
- Parameters:
Unexpected - result object to be added to the lookup-hashtable
lookupResult
public boolean lookupResult(int result)
- Lookup in the hashtable if a result is expected
or is not expected
- Parameters:
result - to be looked up to the lookup-hashtable- Returns:
- true, if expected, false otherwise
lookupResult
public boolean lookupResult(java.lang.Object result)
- Lookup in the hashtable if a returned result object is expected
or is not expected
- Parameters:
result - to be looked up to the lookup-hashtable- Returns:
- true, if expected, false otherwise
clearResultLookup
public void clearResultLookup()
- Clear the result lookup hashtable (Delete all entries).
getTitle
public java.lang.String getTitle()
toString
public java.lang.String toString()
- Overrides:
- toString in class java.lang.Object
|