1   /*
2    * $Id: JmsMessageReceiverTestCase.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.jms;
12  
13  import org.mule.MuleManager;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.impl.endpoint.MuleEndpoint;
16  import org.mule.tck.providers.AbstractMessageReceiverTestCase;
17  import org.mule.tck.testmodels.fruit.Orange;
18  import org.mule.umo.endpoint.UMOEndpoint;
19  import org.mule.umo.provider.UMOConnector;
20  import org.mule.umo.provider.UMOMessageReceiver;
21  
22  import com.mockobjects.dynamic.Mock;
23  
24  import javax.jms.Connection;
25  import javax.jms.ConnectionFactory;
26  
27  public class JmsMessageReceiverTestCase extends AbstractMessageReceiverTestCase
28  {
29      private JmsConnector connector;
30  
31      protected void doSetUp() throws Exception
32      {
33          MuleManager.getInstance().registerConnector(getConnector());
34          super.doSetUp();
35      }
36  
37      public void testReceive() throws Exception
38      {
39          JmsMessageReceiver receiver = (JmsMessageReceiver)getMessageReceiver();
40          assertNotNull(receiver.getComponent());
41          assertNotNull(receiver.getConnector());
42          assertNotNull(receiver.getEndpoint());
43          // hmm how do we unit test a message receive
44          // receiver.onMessage((Message) getValidMessage());
45      }
46  
47      /*
48       * (non-Javadoc)
49       * 
50       * @see org.mule.tck.providers.AbstractMessageReceiverTestCase#getMessageReceiver()
51       */
52      public UMOMessageReceiver getMessageReceiver() throws Exception
53      {
54          MuleDescriptor descriptor = getTestDescriptor("orange", Orange.class.getName());
55          return new JmsMessageReceiver(endpoint.getConnector(), getTestComponent(descriptor), endpoint);
56      }
57  
58      public UMOConnector getConnector() throws Exception
59      {
60          if (connector == null)
61          {
62              connector = new JmsConnector();
63              connector.setName("TestConnector");
64              connector.setSpecification("1.1");
65  
66              Mock connectionFactory = new Mock(ConnectionFactory.class);
67              Mock connection = new Mock(Connection.class);
68              connectionFactory.expectAndReturn("createConnection", connection.proxy());
69              connection.expect("close");
70              connection.expect("start");
71              connection.expect("stop");
72              connector.setConnectionFactory((ConnectionFactory)connectionFactory.proxy());
73          }
74          return connector;
75      }
76  
77      public Object getValidMessage() throws Exception
78      {
79          return JmsConnectorTestCase.getMessage();
80      }
81  
82      public UMOEndpoint getEndpoint() throws Exception
83      {
84          endpoint = new MuleEndpoint("jms://testcase", true);
85          endpoint.setConnector(getConnector());
86          return endpoint;
87      }
88  
89  }