1   /*
2    * $Id: SedaComponentTestCase.java 10131 2007-12-26 15:00:53Z dfeist $
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  public class SedaComponentTestCase extends AbstractMuleTestCase // AbstractComponentTestCase
23  {
24      // Cannot extend AbstractComponentTestCase because of inconsistent behaviour. See
25      // MULE-2843
26  
27      // protected void doSetUp() throws Exception
28      // {
29      // MuleManager.getInstance().setQueueManager(new TransactionalQueueManager());
30      //        
31      // UMODescriptor descriptor = new MuleDescriptor("direct");
32      // descriptor.setImplementation(new Object());
33      // SedaModel sedaModel = new SedaModel();
34      // sedaModel.setQueueProfile(new QueueProfile());
35      // component = sedaModel.createComponent(descriptor);
36      // }
37      //
38      // protected void doTearDown() throws Exception
39      // {
40      // component = null;
41      // }
42  
43      public void testSpiWorkThrowableHandling() throws Exception
44      {
45          try
46          {
47              // getTestComponent() currently already returns a SedaComponent, but
48              // here we are safe-guarding for any future changes
49              MuleDescriptor descriptor = MuleTestUtils.getTestDescriptor("test", "java.lang.Object");
50              SedaComponent component = new SedaComponent(descriptor, new SedaModel());
51  
52              component.handleWorkException(getTestWorkEvent(), "workRejected");
53          }
54          catch (MuleRuntimeException mrex)
55          {
56              assertNotNull(mrex);
57              assertTrue(mrex.getCause().getClass() == Throwable.class);
58              assertEquals("testThrowable", mrex.getCause().getMessage());
59          }
60      }
61  
62      private WorkEvent getTestWorkEvent()
63      {
64          return new WorkEvent(this, // source
65              WorkEvent.WORK_REJECTED, getTestWork(), new WorkException(new Throwable("testThrowable")));
66      }
67  
68      private Work getTestWork()
69      {
70          return new Work()
71          {
72              public void release()
73              {
74                  // noop
75              }
76  
77              public void run()
78              {
79                  // noop
80              }
81          };
82      }
83  }