View Javadoc

1   /*
2    * $Id: XmppCallback.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.transport.xmpp;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.util.concurrent.Latch;
18  
19  import junit.framework.Assert;
20  
21  import org.jivesoftware.smack.packet.Message;
22  
23  public class XmppCallback implements EventCallback
24  {
25      private Latch latch;
26      private Message.Type expectedMessageType;
27  
28      public XmppCallback(Latch latch, Message.Type type)
29      {
30          super();
31          this.latch = latch;
32          this.expectedMessageType = type;
33      }
34  
35      public void eventReceived(MuleEventContext context, Object component) throws Exception
36      {
37          MuleMessage muleMessage = context.getMessage();
38          Object payload = muleMessage.getPayload();
39          Assert.assertTrue(payload instanceof Message);
40          
41          Message xmppMessage = (Message) payload;
42          XmppMessageSyncTestCase.assertEquals(expectedMessageType, xmppMessage.getType());
43          XmppMessageSyncTestCase.assertEquals(AbstractMuleTestCase.TEST_MESSAGE, xmppMessage.getBody());
44          
45          latch.countDown();
46      }
47  }
48