View Javadoc

1   /*
2    * $Id: XmppChatAsyncTestCase.java 22449 2011-07-19 07:40:43Z justin.calleja $
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 static org.junit.Assert.assertEquals;
14  
15  import java.util.Arrays;
16  import java.util.Collection;
17  
18  import org.jivesoftware.smack.packet.Message;
19  import org.junit.runners.Parameterized.Parameters;
20  import org.mule.transport.xmpp.JabberSender.Callback;
21  
22  public class XmppChatAsyncTestCase extends XmppMessageAsyncTestCase
23  {
24  
25      public XmppChatAsyncTestCase(ConfigVariant variant, String configResources)
26      {
27          super(variant, configResources);
28      }
29  
30      @Parameters
31      public static Collection<Object[]> parameters()
32      {
33          return Arrays.asList(new Object[][]{
34              {ConfigVariant.SERVICE,
35                  AbstractXmppTestCase.COMMON_CONFIG + "," + "xmpp-chat-async-config-service.xml"},
36              {ConfigVariant.FLOW, AbstractXmppTestCase.COMMON_CONFIG + "," + "xmpp-chat-async-config-flow.xml"}});
37      }
38  
39      @Override
40      protected Message.Type expectedXmppMessageType()
41      {
42          return Message.Type.chat;
43      }
44  
45      @Override
46      protected void assertXmppMessage(Message message)
47      {
48          assertEquals(Message.Type.chat, message.getType());
49          assertEquals(TEST_MESSAGE, message.getBody());
50      }
51  
52      @Override
53      protected void sendJabberMessageFromNewThread()
54      {
55          JabberSender sender = new JabberSender(new Callback()
56          {
57              public void doit() throws Exception
58              {
59                  Thread.sleep(JABBER_SEND_THREAD_SLEEP_TIME);
60                  jabberClient.sendChatMessage(muleJabberUserId, TEST_MESSAGE);
61              }
62          });
63          startSendThread(sender);
64      }
65  }