View Javadoc

1   /*
2    * $Id: GenericConnectorTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.transport;
12  
13  import org.mule.api.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  public class GenericConnectorTestCase extends AbstractMuleTestCase
25  {
26  
27      /**
28       * Throwable should not cause a ClassCastException (MULE-802).
29       * 
30       * @throws Exception
31       */
32      public void testSpiWorkThrowableHandling() throws Exception
33      {
34          try
35          {
36              AbstractConnector connector = getTestConnector();
37              connector.handleWorkException(getTestWorkEvent(), "workRejected");
38          }
39          catch (MuleRuntimeException mrex)
40          {
41              assertNotNull(mrex);
42              assertTrue(mrex.getCause().getClass() == Throwable.class);
43              assertEquals("testThrowable", mrex.getCause().getMessage());
44          }
45      }
46  
47      private WorkEvent getTestWorkEvent()
48      {
49          WorkEvent event = new WorkEvent(this, // source
50              WorkEvent.WORK_REJECTED, getTestWork(), new WorkException(new Throwable("testThrowable")));
51          return event;
52      }
53  
54      private Work getTestWork()
55      {
56          return new Work()
57          {
58              public void release()
59              {
60                  // noop
61              }
62  
63              public void run()
64              {
65                  // noop
66              }
67          };
68      }
69  }