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