1   /*
2    * $Id: JmsConnectorTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.providers.jms;
12  
13  import org.mule.tck.providers.AbstractConnectorTestCase;
14  import org.mule.umo.provider.UMOConnector;
15  
16  import com.mockobjects.dynamic.C;
17  import com.mockobjects.dynamic.Mock;
18  
19  import javax.jms.Connection;
20  import javax.jms.ConnectionFactory;
21  import javax.jms.ExceptionListener;
22  import javax.jms.TextMessage;
23  
24  import org.apache.commons.collections.IteratorUtils;
25  
26  public class JmsConnectorTestCase extends AbstractConnectorTestCase
27  {
28      private JmsConnector connector;
29  
30      /*
31       * (non-Javadoc)
32       * 
33       * @see org.mule.tck.providers.AbstractConnectorTestCase#getConnectorName()
34       */
35      public UMOConnector getConnector() throws Exception
36      {
37          if (connector == null)
38          {
39              connector = new JmsConnector();
40              connector.setName("TestConnector");
41              connector.setSpecification(JmsConstants.JMS_SPECIFICATION_11);
42  
43              Mock connectionFactory = new Mock(ConnectionFactory.class);
44              Mock connection = new Mock(Connection.class);
45              connectionFactory.expectAndReturn("createConnection", connection.proxy());
46              connection.expect("setExceptionListener", C.isA(ExceptionListener.class));
47              connection.expect("close");
48              connection.expect("start");
49              connection.expect("stop");
50              connection.expect("stop");
51              connection.expect("setClientID", "mule.TestConnector");
52              connector.setConnectionFactory((ConnectionFactory)connectionFactory.proxy());
53              connector.initialise();
54          }
55          return connector;
56      }
57  
58      public String getTestEndpointURI()
59      {
60          return "jms://test.queue";
61      }
62  
63      public Object getValidMessage() throws Exception
64      {
65          return getMessage();
66      }
67  
68      public static Object getMessage() throws Exception
69      {
70          Mock message = new Mock(TextMessage.class);
71  
72          message.expectAndReturn("getText", "Test JMS Message");
73          message.expectAndReturn("getText", "Test JMS Message");
74  
75          message.expectAndReturn("getJMSCorrelationID", null);
76          message.expectAndReturn("getJMSMessageID", "1234567890");
77          message.expectAndReturn("getJMSDeliveryMode", new Integer(1));
78          message.expectAndReturn("getJMSDestination", null);
79          message.expectAndReturn("getJMSPriority", new Integer(4));
80          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
81          message.expectAndReturn("getJMSReplyTo", null);
82          message.expectAndReturn("getJMSExpiration", new Long(0));
83          message.expectAndReturn("getJMSTimestamp", new Long(0));
84          message.expectAndReturn("getJMSType", null);
85  
86          message.expect("toString");
87  
88          message.expectAndReturn("getPropertyNames",
89              IteratorUtils.asEnumeration(IteratorUtils.emptyIterator()));
90  
91          return message.proxy();
92      }
93  
94  }