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.transport.xmpp;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.tck.functional.EventCallback;
12  import org.mule.tck.junit4.AbstractMuleContextTestCase;
13  import org.mule.util.concurrent.Latch;
14  
15  import junit.framework.Assert;
16  import org.jivesoftware.smack.packet.Message;
17  
18  import static org.junit.Assert.assertEquals;
19  
20  public class XmppCallback implements EventCallback
21  {
22      private Latch latch;
23      private Message.Type expectedMessageType;
24  
25      public XmppCallback(Latch latch, Message.Type type)
26      {
27          super();
28          this.latch = latch;
29          this.expectedMessageType = type;
30      }
31  
32      public void eventReceived(MuleEventContext context, Object component) throws Exception
33      {
34          MuleMessage muleMessage = context.getMessage();
35          Object payload = muleMessage.getPayload();
36          Assert.assertTrue(payload instanceof Message);
37          
38          Message xmppMessage = (Message) payload;
39          assertEquals(expectedMessageType, xmppMessage.getType());
40          assertEquals(AbstractMuleContextTestCase.TEST_MESSAGE, xmppMessage.getBody());
41          
42          latch.countDown();
43      }
44  }
45