1   /*
2    * $Id: JcaComponentTestCase.java 10133 2007-12-26 16:51:40Z 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.ra;
12  
13  import org.mule.MuleManager;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.impl.model.ModelFactory;
16  import org.mule.tck.AbstractMuleTestCase;
17  import org.mule.umo.UMOComponent;
18  import org.mule.umo.UMOEvent;
19  import org.mule.umo.UMOException;
20  import org.mule.umo.endpoint.UMOEndpoint;
21  import org.mule.umo.endpoint.UMOImmutableEndpoint;
22  
23  public class JcaComponentTestCase extends AbstractMuleTestCase // AbstractComponentTestCase
24  {
25  
26      // Cannot extend AbstractComponentTestCase because of inconsistent behaviour. See
27      // MULE-2843
28  
29      private UMOComponent component;
30  
31      private TestJCAWorkManager workManager;
32  
33      protected void doSetUp() throws Exception
34      {
35          // Create and register JcaModel
36          workManager = new TestJCAWorkManager();
37          JcaModel jcaModel = (JcaModel) ModelFactory.createModel(JcaModel.JCA_MODEL_TYPE);
38          jcaModel.setWorkManager(new DelegateWorkManager(workManager));
39          MuleManager.getInstance().registerModel(jcaModel);
40  
41          // Create, register, initialise and start JcaComponent
42          String name = "JcaComponent#";
43          MuleDescriptor descriptor = new MuleDescriptor(name);
44          descriptor.setModelName(jcaModel.getName());
45          component = jcaModel.registerComponent(descriptor);
46          assertNotNull(component);
47      }
48  
49      protected void doTearDown() throws Exception
50      {
51          workManager = null;
52          component = null;
53      }
54  
55      public void testSendEvent() throws Exception
56      {
57          component.initialise();
58          component.start();
59          UMOEndpoint endpoint = getTestEndpoint("jcaInFlowEndpoint", UMOImmutableEndpoint.ENDPOINT_TYPE_RECEIVER);
60          UMOEvent event = getTestEvent("Message", endpoint);
61  
62          try
63          {
64              component.sendEvent(event);
65              fail("Exception expected, JcaComponent does not support sendEvent()");
66          }
67          catch (Exception e)
68          {
69          }
70      }
71  
72      public void testDispatchEvent() throws Exception
73      {
74          component.initialise();
75          component.start();
76          UMOEndpoint endpoint = getTestEndpoint("jcaInFlowEndpoint", UMOImmutableEndpoint.ENDPOINT_TYPE_RECEIVER);
77          UMOEvent event = getTestEvent("Message", endpoint);
78  
79          component.dispatchEvent(event);
80          assertEquals(1, workManager.getScheduledWorkList().size());
81          assertEquals(0, workManager.getStartWorkList().size());
82          assertEquals(0, workManager.getDoWorkList().size());
83      }
84  
85      public void testPause()
86      {
87          try
88          {
89              component.pause();
90              fail("Exception expected, JcaComponent does not support pause()");
91          }
92          catch (UMOException e)
93          {
94  
95          }
96      }
97  
98      public void testResume()
99      {
100         try
101         {
102             component.resume();
103             fail("Exception expected, JcaComponent does not support resume()");
104         }
105         catch (UMOException e)
106         {
107         }
108     }
109 
110 }