1   /*
2    * $Id: OracleInContainerJmsConnectorTestCase.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  import oracle.jdbc.pool.OracleDataSource;
25  
26  public class OracleInContainerJmsConnectorTestCase extends AbstractConnectorTestCase
27  {
28  
29      private OracleInContainerJmsConnector connector;
30  
31      // @Override
32      public UMOConnector createConnector() throws Exception
33      {
34          if (connector == null)
35          {
36              connector = new OracleInContainerJmsConnector();
37              connector.setName("TestConnector");
38              OracleDataSource dataSource = new OracleDataSource();
39              dataSource.setDataSourceName("Mule Oracle AQ Provider");
40              dataSource.setURL("jdbc:oracle:oci:@TEST_DB");
41              dataSource.setUser("scott");
42              dataSource.setPassword("tiger");
43              connector.setDataSource(dataSource);
44  
45              Mock connectionFactory = new Mock(ConnectionFactory.class);
46              Mock connection = new Mock(Connection.class);
47              connectionFactory.expectAndReturn("createConnection", connection.proxy());
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          message.expectAndReturn("getText", "Test JMS Message");
73          message.expectAndReturn("getText", "Test JMS Message");
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          message.expectAndReturn("getPropertyNames", new Enumeration()
85          {
86  
87              public boolean hasMoreElements()
88              {
89                  return false;
90              }
91  
92              public Object nextElement()
93              {
94                  return null;
95              }
96          });
97          return message.proxy();
98      }
99  }