View Javadoc

1   /*
2    * $Id: JmsMuleMessageFactoryTestCase.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.jms;
12  
13  import org.mule.api.MuleMessage;
14  import org.mule.api.transport.MuleMessageFactory;
15  import org.mule.transport.AbstractMuleMessageFactoryTestCase;
16  
17  import com.mockobjects.dynamic.C;
18  import com.mockobjects.dynamic.Mock;
19  
20  import javax.jms.TextMessage;
21  
22  import org.apache.commons.collections.IteratorUtils;
23  
24  public class JmsMuleMessageFactoryTestCase extends AbstractMuleMessageFactoryTestCase
25  {
26      private static final String MESSAGE_TEXT = "Test JMS Message";
27  
28      @Override
29      protected MuleMessageFactory doCreateMuleMessageFactory()
30      {
31          return new JmsMuleMessageFactory(muleContext);
32      }
33  
34      @Override
35      protected Object getValidTransportMessage() throws Exception
36      {
37          Mock message = new Mock(TextMessage.class);
38          message.expectAndReturn("getText", MESSAGE_TEXT);
39          message.expectAndReturn("getJMSCorrelationID", null);
40          message.expectAndReturn("getJMSDeliveryMode", Integer.valueOf(1));
41          message.expectAndReturn("getJMSDestination", null);
42          message.expectAndReturn("getJMSExpiration", Long.valueOf(0));
43          message.expectAndReturn("getJMSMessageID", "1234567890");
44          message.expectAndReturn("getJMSPriority", Integer.valueOf(4));
45          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
46          message.expectAndReturn("getJMSReplyTo", null);
47          message.expectAndReturn("getJMSTimestamp", Long.valueOf(0));
48          message.expectAndReturn("getJMSType", null);
49          message.expectAndReturn("getPropertyNames", IteratorUtils.asEnumeration(
50              IteratorUtils.arrayIterator(new Object[] { "foo" })));
51          message.expectAndReturn("getObjectProperty", C.eq("foo"), "bar");
52          message.expectAndReturn("equals", C.eq(MESSAGE_TEXT), true);
53          
54          return message.proxy();
55      }
56  
57      @Override
58      protected Object getUnsupportedTransportMessage()
59      {
60          return "this is an invalid transport message for JmsMuleMessageFactory";
61      }
62  
63      @Override
64      public void testValidPayload() throws Exception
65      {
66          MuleMessageFactory factory = createMuleMessageFactory();
67          
68          Object payload = getValidTransportMessage();
69          MuleMessage message = factory.create(payload, encoding);
70          assertNotNull(message);
71          assertEquals(payload, message.getPayload());
72          // message factory populates the inbound scope
73          assertEquals("bar", message.getInboundProperty("foo"));
74      }
75  }