1   /*
2    * $Id: SedaComponentTestCase.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.impl.model.seda;
12  
13  import org.mule.MuleRuntimeException;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.MuleTestUtils;
17  
18  import javax.resource.spi.work.Work;
19  import javax.resource.spi.work.WorkEvent;
20  import javax.resource.spi.work.WorkException;
21  
22  /**
23   * @author <a href="mailto:aperepel@gmail.com">Andrew Perepelytsya</a>
24   */
25  public class SedaComponentTestCase extends AbstractMuleTestCase
26  {
27  
28      public void testSpiWorkThrowableHandling() throws Exception
29      {
30          try
31          {
32              // getTestComponent() currently already returns a SedaComponent, but
33              // here we are safe-guarding for any future changes
34              MuleDescriptor descriptor = MuleTestUtils.getTestDescriptor("test", "java.lang.Object");
35              SedaComponent component = new SedaComponent(descriptor, new SedaModel());
36  
37              component.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          return new WorkEvent(this, // source
50              WorkEvent.WORK_REJECTED, getTestWork(), new WorkException(new Throwable("testThrowable")));
51      }
52  
53      private Work getTestWork()
54      {
55          return new Work()
56          {
57              public void release()
58              {
59                  // noop
60              }
61  
62              public void run()
63              {
64                  // noop
65              }
66          };
67      }
68  }