Package ptolemy.actor.lib
Class TestExceptionAttribute
- java.lang.Object
-
- ptolemy.kernel.util.NamedObj
-
- ptolemy.kernel.util.Attribute
-
- ptolemy.actor.AbstractInitializableAttribute
-
- ptolemy.actor.lib.TestExceptionAttribute
-
- All Implemented Interfaces:
java.lang.Cloneable
,Initializable
,Changeable
,Debuggable
,DebugListener
,Derivable
,ExceptionHandler
,HierarchyListener
,ModelErrorHandler
,MoMLExportable
,Moveable
,Nameable
public class TestExceptionAttribute extends AbstractInitializableAttribute implements ExceptionHandler
This actor tests for exceptions that are expected to occur when running a test model. When an exception is thrown by the model, this actor is invoked. It has two working modes, training mode and non-training mode. If in training mode, this actor handles an exception by recording the exception message. If not in training mode, this actor first compares the previously stored (assumed correct) message to the exception message and then throws an exception if the two messages are not the same. Also, if a test runs to completion without throwing an exception, this actor throws an exception in its wrapup() method. An exception is expected.- Since:
- Ptolemy II 10.0
- Version:
- $Id$
- Author:
- Edward A. Lee
- Pt.AcceptedRating:
- Yellow (hyzheng)
- Pt.ProposedRating:
- Yellow (hyzheng)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
-
-
Field Summary
Fields Modifier and Type Field Description StringParameter
correctExceptionMessage
The correct exception message to be compared against.Parameter
matchPrefixOfLength
If greater than zero, then check that the first n characters of the exception message match, where n is the value of this parameter.static java.lang.String
TRAINING_MODE_ERROR_MESSAGE
Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.SharedParameter
trainingMode
If true, then collect the exception message and set the correctExceptionMessage parameter with the content of the exception.-
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _deferChangeRequests, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
-
-
Constructor Summary
Constructors Constructor Description TestExceptionAttribute(CompositeEntity container, java.lang.String name)
Create a new actor in the specified container with the specified name.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
handleException(NamedObj context, java.lang.Throwable exception)
Handle an exception thrown in a test.void
initialize()
Initialize.void
wrapup()
Call the super.wrapup() method.-
Methods inherited from class ptolemy.actor.AbstractInitializableAttribute
_getInitializableContainer, addInitializable, clone, hierarchyChanged, hierarchyWillChange, preinitialize, removeInitializable, setContainer
-
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
-
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _containedDecorators, _copyChangeRequestList, _debug, _debug, _debug, _debug, _debug, _description, _executeChangeRequests, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _notifyHierarchyListenersAfterChange, _notifyHierarchyListenersBeforeChange, _propagateValue, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, addHierarchyListener, attributeChanged, attributeDeleted, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, decorators, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, notifyOfNameChange, propagateExistence, propagateValue, propagateValues, removeAttribute, removeChangeListener, removeDebugListener, removeHierarchyListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
-
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ptolemy.kernel.util.Nameable
description, getContainer, getDisplayName, getFullName, getName, getName, setName
-
-
-
-
Field Detail
-
correctExceptionMessage
public StringParameter correctExceptionMessage
The correct exception message to be compared against.
-
matchPrefixOfLength
public Parameter matchPrefixOfLength
If greater than zero, then check that the first n characters of the exception message match, where n is the value of this parameter. Otherwise, if this is zero or negative, then check all the characters. This is an integer that defaults to zero.
-
trainingMode
public SharedParameter trainingMode
If true, then collect the exception message and set the correctExceptionMessage parameter with the content of the exception. This parameter is a boolean, and it defaults to false. It is a shared parameter, meaning that changing it for any one instance in a model will change it for all instances in the model.
-
TRAINING_MODE_ERROR_MESSAGE
public static final java.lang.String TRAINING_MODE_ERROR_MESSAGE
Exception message that is used if we are running under the nightly build and the trainingMode parameter is true.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TestExceptionAttribute
public TestExceptionAttribute(CompositeEntity container, java.lang.String name) throws NameDuplicationException, IllegalActionException
Create a new actor in the specified container with the specified name. The name must be unique within the container or an exception is thrown. The container argument must not be null, or a NullPointerException will be thrown.- Parameters:
container
- The container.name
- The name of this actor within the container.- Throws:
IllegalActionException
- If this actor cannot be contained by the proposed container (see the setContainer() method).NameDuplicationException
- If the name coincides with an entity already in the container.
-
-
Method Detail
-
initialize
public void initialize() throws IllegalActionException
Initialize.- Specified by:
initialize
in interfaceInitializable
- Overrides:
initialize
in classAbstractInitializableAttribute
- Throws:
IllegalActionException
- If thrown by a subclass.
-
handleException
public boolean handleException(NamedObj context, java.lang.Throwable exception) throws IllegalActionException
Handle an exception thrown in a test. If in training mode, simply record the exception message. If not in training mode, first compare the stored good message against the exception message. If they are the same, do nothing. Otherwise, throw the exception again.- Specified by:
handleException
in interfaceExceptionHandler
- Parameters:
context
- The object in which the error occurred.exception
- The exception to be handled.- Returns:
- True if the exception message is the same as the saved message.
- Throws:
IllegalActionException
- If cannot get a valid token from the trainingMode parameter or the exception message is not the same as the stored message.
-
wrapup
public void wrapup() throws IllegalActionException
Call the super.wrapup() method. Check whether this actor has been invoked to handle exceptions. If not, throw an exception. Otherwise, do nothing.- Specified by:
wrapup
in interfaceInitializable
- Overrides:
wrapup
in classAbstractInitializableAttribute
- Throws:
IllegalActionException
- If this actor has not been invoked to handle exceptions.
-
-