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.MuleMessage;
10  import org.mule.api.transport.MuleMessageFactory;
11  import org.mule.transport.AbstractMuleMessageFactoryTestCase;
12  import org.mule.util.UUID;
13  
14  import org.jivesoftware.smack.packet.Message;
15  import org.junit.Test;
16  
17  import static org.junit.Assert.assertEquals;
18  import static org.junit.Assert.assertNotNull;
19  
20  public class XmppMuleMessageFactoryTestCase extends AbstractMuleMessageFactoryTestCase
21  {
22      @Override
23      protected MuleMessageFactory doCreateMuleMessageFactory()
24      {
25          return new XmppMuleMessageFactory(muleContext);
26      }
27  
28      @Override
29      protected Object getValidTransportMessage() throws Exception
30      {
31          Message xmppMessage = new Message();
32          xmppMessage.setBody(TEST_MESSAGE);
33          return xmppMessage;
34      }
35  
36      @Override
37      protected Object getUnsupportedTransportMessage()
38      {
39          return "this is an invalid transport message for XmppMuleMessageFactory";
40      }
41      
42      @Test
43      public void testPacketWithMessageProperties() throws Exception
44      {
45          String uuid = UUID.getUUID();
46          
47          Message payload = (Message) getValidTransportMessage();
48          payload.setSubject("the subject");
49          payload.setProperty("foo", "foo-value");
50          payload.setPacketID(uuid);
51       
52          MuleMessageFactory factory = createMuleMessageFactory();
53          MuleMessage message = factory.create(payload, encoding);
54          assertNotNull(message);
55          assertEquals(Message.class, message.getPayload().getClass());
56          assertEquals(TEST_MESSAGE, ((Message) message.getPayload()).getBody());
57          
58          assertEquals(uuid, message.getUniqueId());
59          assertInboundProperty("foo-value", message, "foo");
60          assertInboundProperty("the subject", message, XmppConnector.XMPP_SUBJECT);
61      }
62      
63      private void assertInboundProperty(Object expected, MuleMessage message, String key)
64      {
65          Object value = message.getInboundProperty(key);
66          assertEquals(expected, value);
67      }
68  }
69