1   /*
2    * $Id: JmsConnectorTestCase.java 7968 2007-08-21 12:01:57Z holger $
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      // @Override
36      public UMOConnector createConnector() throws Exception
37      {
38          if (connector == null)
39          {
40              connector = new JmsConnector();
41              connector.setName("TestConnector");
42              connector.setSpecification(JmsConstants.JMS_SPECIFICATION_11);
43  
44              Mock connectionFactory = new Mock(ConnectionFactory.class);
45              Mock connection = new Mock(Connection.class);
46              connectionFactory.expectAndReturn("createConnection", connection.proxy());
47              connection.expect("setExceptionListener", C.isA(ExceptionListener.class));
48              connection.expect("close");
49              connection.expect("start");
50              connection.expect("stop");
51              connection.expect("stop");
52              connection.expect("setClientID", "mule.TestConnector");
53              connector.setConnectionFactory((ConnectionFactory)connectionFactory.proxy());
54              connector.initialise();
55          }
56          return connector;
57      }
58  
59      public String getTestEndpointURI()
60      {
61          return "jms://test.queue";
62      }
63  
64      public Object getValidMessage() throws Exception
65      {
66          return getMessage();
67      }
68  
69      public static Object getMessage() throws Exception
70      {
71          Mock message = new Mock(TextMessage.class);
72  
73          message.expectAndReturn("getText", "Test JMS Message");
74          message.expectAndReturn("getText", "Test JMS Message");
75  
76          message.expectAndReturn("getJMSCorrelationID", null);
77          message.expectAndReturn("getJMSMessageID", "1234567890");
78          message.expectAndReturn("getJMSDeliveryMode", new Integer(1));
79          message.expectAndReturn("getJMSDestination", null);
80          message.expectAndReturn("getJMSPriority", new Integer(4));
81          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
82          message.expectAndReturn("getJMSReplyTo", null);
83          message.expectAndReturn("getJMSExpiration", new Long(0));
84          message.expectAndReturn("getJMSTimestamp", new Long(0));
85          message.expectAndReturn("getJMSType", null);
86  
87          message.expect("toString");
88  
89          message.expectAndReturn("getPropertyNames",
90              IteratorUtils.asEnumeration(IteratorUtils.emptyIterator()));
91  
92          return message.proxy();
93      }
94  
95  }