1   /*
2    * $Id: OracleJmsConnectorTestCase.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.oracle.jms;
12  
13  import org.mule.tck.providers.AbstractConnectorTestCase;
14  import org.mule.umo.provider.UMOConnector;
15  
16  import com.mockobjects.dynamic.Mock;
17  
18  import java.util.Enumeration;
19  
20  import javax.jms.Connection;
21  import javax.jms.ConnectionFactory;
22  import javax.jms.TextMessage;
23  
24  public class OracleJmsConnectorTestCase extends AbstractConnectorTestCase
25  {
26  
27      private OracleJmsConnector connector;
28  
29      public UMOConnector getConnector() throws Exception
30      {
31          if (connector == null)
32          {
33              connector = new OracleJmsConnector();
34              connector.setName("TestConnector");
35              connector.setUrl("jdbc:oracle:oci:@TEST_DB");
36              connector.setUsername("scott");
37              connector.setPassword("tiger");
38  
39              Mock connectionFactory = new Mock(ConnectionFactory.class);
40              Mock connection = new Mock(Connection.class);
41              connectionFactory.expectAndReturn("createConnection", connection.proxy());
42              connection.expect("close");
43              connection.expect("start");
44              connection.expect("stop");
45              connection.expect("stop");
46              connection.expect("setClientID", "mule.TestConnector");
47              connector.setConnectionFactory((ConnectionFactory)connectionFactory.proxy());
48              connector.initialise();
49          }
50          return connector;
51      }
52  
53      public String getTestEndpointURI()
54      {
55          return "jms://TEST_QUEUE";
56      }
57  
58      public Object getValidMessage() throws Exception
59      {
60          return getMessage();
61      }
62  
63      public static Object getMessage() throws Exception
64      {
65          Mock message = new Mock(TextMessage.class);
66          message.expectAndReturn("getText", "Test JMS Message");
67          message.expectAndReturn("getText", "Test JMS Message");
68          message.expectAndReturn("getJMSCorrelationID", null);
69          message.expectAndReturn("getJMSMessageID", "1234567890");
70          message.expectAndReturn("getJMSDeliveryMode", new Integer(1));
71          message.expectAndReturn("getJMSDestination", null);
72          message.expectAndReturn("getJMSPriority", new Integer(4));
73          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
74          message.expectAndReturn("getJMSReplyTo", null);
75          message.expectAndReturn("getJMSExpiration", new Long(0));
76          message.expectAndReturn("getJMSTimestamp", new Long(0));
77          message.expectAndReturn("getJMSType", null);
78          message.expectAndReturn("getPropertyNames", new Enumeration()
79          {
80  
81              public boolean hasMoreElements()
82              {
83                  return false;
84              }
85  
86              public Object nextElement()
87              {
88                  return null;
89              }
90          });
91          return message.proxy();
92      }
93  }