View Javadoc

1   /*
2    * $Id: XmppMuleMessageFactoryTestCase.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.MuleMessage;
14  import org.mule.api.transport.MuleMessageFactory;
15  import org.mule.transport.AbstractMuleMessageFactoryTestCase;
16  import org.mule.util.UUID;
17  
18  import org.jivesoftware.smack.packet.Message;
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      public void testPacketWithMessageProperties() throws Exception
43      {
44          String uuid = UUID.getUUID();
45          
46          Message payload = (Message) getValidTransportMessage();
47          payload.setSubject("the subject");
48          payload.setProperty("foo", "foo-value");
49          payload.setPacketID(uuid);
50       
51          MuleMessageFactory factory = createMuleMessageFactory();
52          MuleMessage message = factory.create(payload, encoding);
53          assertNotNull(message);
54          assertEquals(Message.class, message.getPayload().getClass());
55          assertEquals(TEST_MESSAGE, ((Message) message.getPayload()).getBody());
56          
57          assertEquals(uuid, message.getUniqueId());
58          assertInboundProperty("foo-value", message, "foo");
59          assertInboundProperty("the subject", message, XmppConnector.XMPP_SUBJECT);
60      }
61      
62      private void assertInboundProperty(Object expected, MuleMessage message, String key)
63      {
64          Object value = message.getInboundProperty(key);
65          assertEquals(expected, value);
66      }
67  }
68