View Javadoc

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