|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnz.ac.waikato.modeljunit.Model
public class Model
This class is a wrapper around a user-supplied EFSM model.
It uses reflection to find all the actions and guards of the model.
It allows a tester class (see Tester
and its subclasses)
to check the guards, call the actions and keep track of the current
state. It also provides a general listener facility that can be
used to print progress messages, record model coverage metrics etc.
To use this wrapper, you write a special EFSM class
(see FsmModel
) that models part of the behaviour of
your SUT, then pass an instance of that class to the constructor
of this class. Then you can pass an instance of this class to
one of the Tester
subclasses, such as RandomTester
,
in order to generate/execute test sequences. However, many of those
classes provide a convenience constructor that creates this Model
wrapper for you.
Field Summary | |
---|---|
protected java.util.ArrayList<java.lang.reflect.Method> |
fsmActions_
All the @Action methods of fsmClass_. |
protected FsmModel |
fsmModel_
The implementation under test (null means none yet). |
protected java.util.ArrayList<Transition> |
fsmSequence_
Current test sequence TODO: decide whether this needs to be builtin or a listener. |
protected java.lang.Object |
fsmState_
The current state of the implementation under test. |
protected java.io.Writer |
output_
Output device used for messages and warnings. |
protected static java.lang.Object[] |
VOID_ARGS
An empty array of objects. |
Constructor Summary | |
---|---|
Model(FsmModel model)
Constructs an EFSM model from the given FsmModel object. |
Method Summary | |
---|---|
ModelListener |
addListener(ModelListener listen)
Add a listener. |
ModelListener |
addListener(java.lang.String name)
Add one of the predefined model listeners or coverage metrics. |
boolean |
doAction(int index)
Try to take the given Action from the current state. |
void |
doReset()
Reset the FSM to its initial state. |
void |
doReset(java.lang.String reason)
Reset the FSM to its initial state. |
int |
enabled(int index)
Is Action number 'index' enabled? Returns 0 if Action number 'index' is disabled, or a positive number if it is enabled. |
java.util.BitSet |
enabledGuards()
Return a fresh BitSet of all actions that are enabled in the current state. |
java.lang.String |
getActionName(int index)
Returns the name of the given Action. |
int |
getActionNumber(java.lang.String name)
Looks up an Action by name and returns its number. |
java.lang.Object |
getCurrentState()
Returns the current state of the implementation under test. |
GraphListener |
getGraphListener()
Get the GraphListener for this model. |
ModelListener |
getListener(java.lang.String name)
Get a listener by name, or null if that name is unused. |
java.util.Set<java.lang.String> |
getListenerNames()
The set of names of all the current coverage metrics and listeners |
java.lang.Object |
getModel()
Returns the model object that is begin tested. |
java.lang.Class |
getModelClass()
Returns the FSM class that is the test model. |
java.lang.String |
getModelName()
Returns the name of the FSM class that is the test model. |
int |
getNumActions()
The total number of Actions. |
java.io.Writer |
getOutput()
The current output stream, which is used for messages and warnings. |
boolean |
getTesting()
True means we are generating real tests. |
static java.lang.String |
getVersion()
The version of ModelJUnit |
boolean |
isEnabled(int index)
Is Action number 'index' enabled? Returns true if Action number 'index' is enabled. |
boolean |
isInitialState()
True iff the current state is the initial state. |
boolean |
isTerminal()
True iff the current state is a terminal state. |
protected void |
loadModelClass(java.lang.Class fsm)
Loads the given class and finds its @Action methods. |
void |
notifyDoneGuard(java.lang.Object state,
int action,
boolean enabled,
int value)
Sends a doneGuard event to all listeners |
void |
notifyDoneReset(java.lang.String reason,
boolean testing)
Sends a doneReset event to all listeners |
void |
notifyDoneTransition(int action,
Transition tr)
Sends a doneTransition event to all listeners |
void |
notifyFailure(TestFailureException ex)
Sends a failure event to all listeners. |
void |
notifyStartAction(java.lang.Object state,
int action,
java.lang.String name)
Sends a startAction event to all listeners |
void |
printMessage(java.lang.String msg)
Print a message to the current output writer (see getOutput() ). |
void |
printWarning(java.lang.String msg)
Prints a warning message to the current output writer. |
void |
removeAllListeners()
Remove all coverage listeners. |
ModelListener |
removeListener(java.lang.String name)
Remove a coverage listener by name. |
java.io.Writer |
setOutput(java.io.Writer output)
Sets the current output stream. |
boolean |
setTesting(boolean testing)
Sets the testing flag. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected FsmModel fsmModel_
protected java.util.ArrayList<java.lang.reflect.Method> fsmActions_
protected java.lang.Object fsmState_
protected java.util.ArrayList<Transition> fsmSequence_
protected static final java.lang.Object[] VOID_ARGS
protected java.io.Writer output_
Constructor Detail |
---|
public Model(FsmModel model)
model
- Method Detail |
---|
public static final java.lang.String getVersion()
public int getActionNumber(java.lang.String name)
doAction(int)
) or to check the guard of the
action (see isEnabled(int)
).
name
- The name of an Action.
public java.lang.Class getModelClass()
public java.lang.String getModelName()
public java.lang.Object getModel()
public java.lang.Object getCurrentState()
public java.lang.String getActionName(int index)
public int getNumActions()
public boolean getTesting()
public boolean setTesting(boolean testing)
public java.io.Writer getOutput()
public java.io.Writer setOutput(java.io.Writer output)
output
-
protected void loadModelClass(java.lang.Class fsm)
public void doReset()
public void doReset(java.lang.String reason)
reason
- Why the reset was performed (an adjective).public boolean isInitialState()
public boolean isEnabled(int index)
public int enabled(int index)
index
- Index into the fsmActions_ array.
public java.util.BitSet enabledGuards()
public boolean isTerminal()
public boolean doAction(int index)
index
- Index into the fsmTransitions array.
public ModelListener addListener(ModelListener listen)
public ModelListener addListener(java.lang.String name)
name
- The informal lowercase name of a Listener object.
java.lang.RuntimeException
- if name is not a known kind of listener.public ModelListener removeListener(java.lang.String name)
public void removeAllListeners()
public GraphListener getGraphListener()
public ModelListener getListener(java.lang.String name)
name
- The name of a listener.
public java.util.Set<java.lang.String> getListenerNames()
public void notifyDoneReset(java.lang.String reason, boolean testing)
public void notifyDoneGuard(java.lang.Object state, int action, boolean enabled, int value)
public void notifyStartAction(java.lang.Object state, int action, java.lang.String name)
public void notifyDoneTransition(int action, Transition tr)
public void notifyFailure(TestFailureException ex)
TestFailureException
- if a listener throws it.public void printWarning(java.lang.String msg)
public void printMessage(java.lang.String msg)
getOutput()
).
This automatically adds a newline on the end of msg.
It does a flush after each call, so that messages appear promptly.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |