1   /*
2    * $Id: OracleInContainerJmsConnectorTestCase.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  import oracle.jdbc.pool.OracleDataSource;
25  
26  public class OracleInContainerJmsConnectorTestCase extends AbstractConnectorTestCase
27  {
28  
29      private OracleInContainerJmsConnector connector;
30  
31      public UMOConnector getConnector() throws Exception
32      {
33          if (connector == null)
34          {
35              connector = new OracleInContainerJmsConnector();
36              connector.setName("TestConnector");
37              OracleDataSource dataSource = new OracleDataSource();
38              dataSource.setDataSourceName("Mule Oracle AQ Provider");
39              dataSource.setURL("jdbc:oracle:oci:@TEST_DB");
40              dataSource.setUser("scott");
41              dataSource.setPassword("tiger");
42              connector.setDataSource(dataSource);
43  
44              Mock connectionFactory = new Mock(ConnectionFactory.class);
45              Mock connection = new Mock(Connection.class);
46              connectionFactory.expectAndReturn("createConnection", connection.proxy());
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          message.expectAndReturn("getText", "Test JMS Message");
72          message.expectAndReturn("getText", "Test JMS Message");
73          message.expectAndReturn("getJMSCorrelationID", null);
74          message.expectAndReturn("getJMSMessageID", "1234567890");
75          message.expectAndReturn("getJMSDeliveryMode", new Integer(1));
76          message.expectAndReturn("getJMSDestination", null);
77          message.expectAndReturn("getJMSPriority", new Integer(4));
78          message.expectAndReturn("getJMSRedelivered", Boolean.FALSE);
79          message.expectAndReturn("getJMSReplyTo", null);
80          message.expectAndReturn("getJMSExpiration", new Long(0));
81          message.expectAndReturn("getJMSTimestamp", new Long(0));
82          message.expectAndReturn("getJMSType", null);
83          message.expectAndReturn("getPropertyNames", new Enumeration()
84          {
85  
86              public boolean hasMoreElements()
87              {
88                  return false;
89              }
90  
91              public Object nextElement()
92              {
93                  return null;
94              }
95          });
96          return message.proxy();
97      }
98  }