opencard.tests.terminal
Class CommandBean
java.lang.Object
|
+--opencard.core.service.CardService
|
+--opencard.tests.terminal.TestBean
|
+--opencard.tests.terminal.CommandBean
- Direct Known Subclasses:
- AskRandom, DirectCommand, EraseBinary, GenerateKey, GetResponse, ReadBinary, ReadRecord, Search, Select, UpdateBinary, VerifyCHV
- public abstract class CommandBean
- extends TestBean
The CommandBean is the superclass of all CommandBeans, encapsulating a
specific Command APDU.
It's superclass TestBean provides test specific features like
- Check if the Result is expected or not (Low-level evaluation)
- Friendly look Log-Outputs/Traces.
This superclass implements the largest part of the required functionality:
- Define the requires Attributes of an command (CLA, INS, DATA, P1, ...)
- Associate a PassThruCardService
- Assemble the Command APDU
- Execute the APDU
- Select a set of commands to be used with a specific card
In order to check the result a hashtable is maintained where all likely
possible return codes and OCF-Exceptions are listed and marked as Expected
or unexpected.
Each subclass, defining a specific CommandAPDU must implement the following:
- Declare a default constructor:
Set a Label for the friendly log-output (e.g. "Select Command")
Since the CommandBeans should be beans, please declare only the default
constructor.
- Each subclass needs a method setCommandBytes() which sets a apropriate
command parameters for a specific card type using a CommandCodeFactory.
The CardType must be set by the Test Case.
- declare friendly methods to set the command's instance specific parameters
e.g. setPath(byte[] path) or
setLength(int length) or
setData(byte[] path)
These methods should transform the given parameters into the attributes
P1, P2, P3 and CommandData of the APDU
When using a CommandBean 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 the PassThruCardService with a smartcard object
e.g.: select.initialize(sc);
- Set the specific parameters like path, data etc.
e.g.: select.setPath(new byte[]{(byte)0x2F,(byte)0x01});
- define the likely possible result status words or OCF Exceptions as
expected or unexpected
e.g.: select.addExpectedReturnCode(0x9000);
e.g.: select.addUnxpectedReturnCode(0x9A00);
e.g.: select.addUnxpectedReturnCode(CardTerminalException.class);
- execute the Command
e.g.: boolean result = select.execute()
the beans throws a TestFailedException if the exceution 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();
Note: Please be sure to add the PassThruCardService to you
opencard.properties - file since these CommandBean use this CardService
to access the terminal/card.
- Version:
- $Id: CommandBean.java,v 1.1 1999/12/03 09:31:36 damke Exp $
- See Also:
TestBean,
Select,
ReadBinary,
UpdateBinary
| Methods inherited from class opencard.tests.terminal.TestBean |
addExpectedResult,
addExpectedResult,
addUnexpectedResult,
addUnexpectedResult,
checkResult,
clearResultLookup,
getId,
getLabel,
getResult,
getResultString,
getTitle,
isDetails,
lookupResult,
lookupResult,
setDetails,
setId,
setLabel,
setResult,
setResult,
setResult |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
response
protected ResponseAPDU response
- ResponseAPDU to be analysed for this command
CommandBean
public CommandBean()
resetCardService
public void resetCardService()
- Invalidates the assigned PassThruCardService by setting it to null.
setCardService
public void setCardService(SmartCard sc)
- Instantiates a new PassThruCardService using a sartcard object.
- Parameters:
SmartCard-object - to be used for getting the CardService
getIns
public byte getIns()
setIns
public void setIns(byte ins)
getCla
public byte getCla()
setCla
public void setCla(byte cla)
getP1
public byte getP1()
setP1
public void setP1(byte p1)
getP2
public byte getP2()
setP2
public void setP2(byte p2)
getLe
public byte getLe()
setLe
public void setLe(byte le)
setParameters
protected void setParameters(byte[] parameters)
- Set the Parameters CLA, INS, P1, P2, P3 using a byte array
getCommandData
public byte[] getCommandData()
setCommandData
public void setCommandData(byte[] commandData)
getMode
public int getMode()
setMode
public void setMode(int mode)
assemble
protected CommandAPDU assemble()
- Assemble this CommandAPDU using the current values of the Parameters.
- Returns:
- the CommandAPDU to be used for execute()
getCardType
public int getCardType()
setCardType
public void setCardType(int type)
setCommandBytes
protected abstract void setCommandBytes()
- define the command specific values for the command parameters:
initialize
public void initialize(SmartCard sc)
throws TestInitException
- Get a passthrough CardService to handle this command and initialize
the bean.
- Parameters:
Use - the given smartcard-object to get a PassThruCardService
execute
public void execute()
throws TestFailedException,
TestInitException
- Execute the Command using a previously CardService
- Throws:
- throws - an TestFailedException, if result of this exceution
is unexpected or not listed in the result lookup table
- Overrides:
- execute in class TestBean
getResponseData
public byte[] getResponseData()
toString
public java.lang.String toString()
- Overrides:
- toString in class TestBean
|