1   /*
2    * $Id: JmsConnectorTestCase.java 10787 2008-02-12 18:51:50Z dfeist $
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.transport.jms;
12  
13  import org.mule.api.transport.Connector;
14  import org.mule.transport.AbstractConnectorTestCase;
15  import org.mule.transport.jms.JmsConnector;
16  import org.mule.transport.jms.JmsConstants;
17  
18  import com.mockobjects.dynamic.C;
19  import com.mockobjects.dynamic.Mock;
20  
21  import javax.jms.Connection;
22  import javax.jms.ConnectionFactory;
23  import javax.jms.ExceptionListener;
24  import javax.jms.TextMessage;
25  
26  import org.apache.commons.collections.IteratorUtils;
27  
28  public class JmsConnectorTestCase extends AbstractConnectorTestCase
29  {
30  
31      /*
32       * (non-Javadoc)
33       * 
34       * @see org.mule.tck.providers.AbstractConnectorTestCase#getConnectorName()
35       */
36      // @Override
37      public Connector createConnector() throws Exception
38      {
39          JmsConnector newConnector = new JmsConnector();
40          newConnector.setName("TestConnector");
41          newConnector.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          newConnector.setConnectionFactory((ConnectionFactory) connectionFactory.proxy());
53  
54          return newConnector;
55      }
56  
57      public String getTestEndpointURI()
58      {
59          return "jms://test.queue";
60      }
61  
62      public Object getValidMessage() throws Exception
63      {
64          return getMessage();
65      }
66  
67      public static Object getMessage() throws Exception
68      {
69          Mock message = new Mock(TextMessage.class);
70  
71          message.expectAndReturn("getText", "Test JMS Message");
72          message.expectAndReturn("getText", "Test JMS Message");
73  
74          message.expectAndReturn("getJMSCorrelationID", null);
75          message.expectAndReturn("getJMSMessageID", "1234567890");
76          message.expectAndReturn("getJMSDeliveryMode", new Integer(1));
77          message.expectAndReturn("getJMSDestination", null);
78          message.expectAndReturn("getJMSPriority", new Integer(4));
79          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
80          message.expectAndReturn("getJMSReplyTo", null);
81          message.expectAndReturn("getJMSExpiration", new Long(0));
82          message.expectAndReturn("getJMSTimestamp", new Long(0));
83          message.expectAndReturn("getJMSType", null);
84  
85          message.expect("toString");
86  
87          message.expectAndReturn("getPropertyNames",
88              IteratorUtils.asEnumeration(IteratorUtils.emptyIterator()));
89  
90          return message.proxy();
91      }
92  
93  }