View Javadoc

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