View Javadoc

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