View Javadoc

1   /*
2    * $Id: XmppCallback.java 22431 2011-07-18 07:40:35Z dirk.olmes $
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.functional.EventCallback;
16  import org.mule.tck.junit4.AbstractMuleContextTestCase;
17  import org.mule.util.concurrent.Latch;
18  
19  import junit.framework.Assert;
20  import org.jivesoftware.smack.packet.Message;
21  
22  import static org.junit.Assert.assertEquals;
23  
24  public class XmppCallback implements EventCallback
25  {
26      private Latch latch;
27      private Message.Type expectedMessageType;
28  
29      public XmppCallback(Latch latch, Message.Type type)
30      {
31          super();
32          this.latch = latch;
33          this.expectedMessageType = type;
34      }
35  
36      public void eventReceived(MuleEventContext context, Object component) throws Exception
37      {
38          MuleMessage muleMessage = context.getMessage();
39          Object payload = muleMessage.getPayload();
40          Assert.assertTrue(payload instanceof Message);
41          
42          Message xmppMessage = (Message) payload;
43          assertEquals(expectedMessageType, xmppMessage.getType());
44          assertEquals(AbstractMuleContextTestCase.TEST_MESSAGE, xmppMessage.getBody());
45          
46          latch.countDown();
47      }
48  }
49