AnsweredAssumed Answered

Unit Testing a Transition Listener

Question asked by marcthomas2012 on Aug 16, 2012
Latest reply on Aug 16, 2012 by marcthomas2012

I am currently building a workflow engine into our system using Activiti (which is great by the way). We are relying heavily on the use of listeners for triggering behaviour like adding data to our database etc.

I have provided a cut down version of the listener below to show roughly what I'm doing. Basically, the workflow configured in Activiti would add this listener as a Java class and I have added the two expressions to that configured listener.

What I would like to achieve in the unit test is to be able to pass in valid and invalid data to the notify method and verify the outcome.

My problem is though, I don't really know what I need to construct for the parameter in order to get the Activiti side of things to work and allow my code to extract the expression values.

Can anyone help?


public class AddCommentTransitionListener implements ExecutionListener, Serializable {
   private static final Logger log = Logger.getLogger(AddCommentTransitionListener.class);

   private static final long serialVersionUID = 1L;

   private Expression manualCommentExpression;
   private Expression manualCommentTypeExpression;

   private String manualComment = null;
   private CommentType manualCommentType;

   public void notify(DelegateExecution execution) throws Exception {
                // Add the comment details to the database

   private void processConfiguration(DelegateExecution execution) {
      if (execution != null) {

   private void extractManualCommentConfiguration(DelegateExecution execution) {
      if (manualCommentExpression != null) {
         manualComment = (String) manualCommentExpression.getValue(execution);

         if (manualCommentTypeExpression != null) {
            // TODO throw exception if we cannot determine the comment type or if the comment type is not
            // present
            manualCommentType = CommentType.lookup(Integer.parseInt((String) manualCommentTypeExpression
         } else {
            // TODO throw exception