View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.tck.functional;
8   
9   import org.mule.RequestContext;
10  import org.mule.api.MuleEventContext;
11  import org.mule.api.transformer.TransformerException;
12  import org.mule.context.notification.CustomNotification;
13  
14  /**
15   * A <code>FunctionlTestNotification</code> is fired by the {@link org.mule.tck.functional.FunctionalTestComponent}
16   * when it receives an event. Test cases can register a {@link org.mule.tck.functional.FunctionalTestNotificationListener}
17   * with Mule to receive these notifications and make assertions about the number of messages received or the content
18   * of the message.
19   * <p/>
20   * This Notification contains the current MuleEventContext and reply message. The resource Identifier for this event
21   * is the service name that received the message.  This means you can register to listen to Notifications from a
22   * selected {@link org.mule.tck.functional.FunctionalTestComponent}. i.e.
23   * <code>
24   * muleContext.registerListener(this, "*JmsTestCompoennt");
25   * </code>
26   * <p/>
27   * This registration would only receive {@link org.mule.tck.functional.FunctionalTestNotification} objects
28   * from components called 'MyJmsTestComponent' and 'YourJmsTestComponent' but not 'HerFileTestComponent'.
29   *
30   * @see org.mule.tck.functional.FunctionalTestComponent
31   * @see org.mule.tck.functional.FunctionalTestNotificationListener
32   * @see org.mule.api.MuleContext
33   */
34  public class FunctionalTestNotification extends CustomNotification
35  {
36      /** Serial version */
37      private static final long serialVersionUID = -3435373745940904597L;
38  
39      public static final int EVENT_RECEIVED = -999999;
40  
41      static
42      {
43          registerAction("event received", EVENT_RECEIVED);
44      }
45  
46      private final Object replyMessage;
47      private final MuleEventContext eventContext;
48  
49      public FunctionalTestNotification(Object message, int action)
50      {
51          super(message, action);
52          this.replyMessage = null;
53          this.eventContext = RequestContext.getEventContext();
54          resourceIdentifier = eventContext.getFlowConstruct().getName();
55  
56      }
57  
58      public FunctionalTestNotification(MuleEventContext context, Object replyMessage, int action)
59              throws TransformerException
60      {
61          super(context.getMessage().getPayload(), action);
62          resourceIdentifier = context.getFlowConstruct().getName();
63          this.replyMessage = replyMessage;
64          this.eventContext = context;
65      }
66  
67      public Object getReplyMessage()
68      {
69          return replyMessage;
70      }
71  
72      public MuleEventContext getEventContext()
73      {
74          return eventContext;
75      }
76  }