Class 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)
    • 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

      • 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 interface ExceptionHandler
        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.