1   /*
2    * $Id: GenericConnectorTestCase.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;
12  
13  import org.mule.MuleRuntimeException;
14  import org.mule.tck.AbstractMuleTestCase;
15  
16  import javax.resource.spi.work.Work;
17  import javax.resource.spi.work.WorkEvent;
18  import javax.resource.spi.work.WorkException;
19  
20  /**
21   * The test is not there in AbstractConnector, because we need to call a protected
22   * method, and the latter class is in a different package.
23   * 
24   * @author <a href="mailto:aperepel@gmail.com">Andrew Perepelytsya</a>
25   */
26  public class GenericConnectorTestCase extends AbstractMuleTestCase
27  {
28  
29      /**
30       * Throwable should not cause a ClassCastException (MULE-802).
31       * 
32       * @throws Exception
33       */
34      public void testSpiWorkThrowableHandling() throws Exception
35      {
36          try
37          {
38              AbstractConnector connector = getTestConnector();
39              connector.handleWorkException(getTestWorkEvent(), "workRejected");
40          }
41          catch (MuleRuntimeException mrex)
42          {
43              assertNotNull(mrex);
44              assertTrue(mrex.getCause().getClass() == Throwable.class);
45              assertEquals("testThrowable", mrex.getCause().getMessage());
46          }
47      }
48  
49      private WorkEvent getTestWorkEvent()
50      {
51          WorkEvent event = new WorkEvent(this, // source
52              WorkEvent.WORK_REJECTED, getTestWork(), new WorkException(new Throwable("testThrowable")));
53          return event;
54      }
55  
56      private Work getTestWork()
57      {
58          return new Work()
59          {
60              public void release()
61              {
62                  // noop
63              }
64  
65              public void run()
66              {
67                  // noop
68              }
69          };
70      }
71  }