View Javadoc

1   /*
2    * $Id: SimpleCallableJavaComponentTestCase.java 19946 2010-10-15 16:39:15Z aperepel $
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.component;
12  
13  import org.mule.api.DefaultMuleException;
14  import org.mule.object.PrototypeObjectFactory;
15  import org.mule.tck.testmodels.fruit.Apple;
16  import org.mule.tck.testmodels.fruit.Orange;
17  
18  public class SimpleCallableJavaComponentTestCase extends AbstractComponentTestCase
19  {
20  
21      public void testComponentCreationWithObjectFactory() throws Exception
22      {
23          PrototypeObjectFactory objectFactory = new PrototypeObjectFactory(
24              Apple.class);
25          objectFactory.setObjectClass(Apple.class);
26          objectFactory.initialise();
27  
28          SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(
29              objectFactory);
30  
31          assertNotNull(component.getObjectFactory());
32          assertEquals(objectFactory, component.getObjectFactory());
33          assertEquals(Apple.class, component.getObjectFactory().getObjectClass());
34          assertEquals(Apple.class, component.getObjectType());
35  
36          objectFactory = new PrototypeObjectFactory(Orange.class);
37          objectFactory.setObjectClass(Orange.class);
38          objectFactory.initialise();
39  
40          try
41          {
42              component = new SimpleCallableJavaComponent(objectFactory);
43          }
44          catch (Exception e)
45          {
46              assertSame(DefaultMuleException.class, e.getClass());
47          }
48      }
49  
50      public void testDirectComponentCreation() throws Exception
51      {
52          SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(Apple.class);
53  
54          assertNotNull(component.getObjectFactory());
55          assertEquals(Apple.class, component.getObjectFactory().getObjectClass());
56          assertEquals(Apple.class, component.getObjectType());
57  
58          try
59          {
60              component = new SimpleCallableJavaComponent(Orange.class);
61          }
62          catch (Exception e)
63          {
64              assertSame(DefaultMuleException.class, e.getClass());
65          }
66      }
67  
68      public void testSimpleComponentCreation() throws Exception
69      {
70          SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(
71              new Apple());
72  
73          assertNotNull(component.getObjectFactory());
74          assertEquals(Apple.class, component.getObjectFactory().getObjectClass());
75          assertEquals(Apple.class, component.getObjectType());
76  
77          try
78          {
79              component = new SimpleCallableJavaComponent(new Orange());
80          }
81          catch (Exception e)
82          {
83              assertSame(DefaultMuleException.class, e.getClass());
84          }
85      }
86  
87      public void testLifecycle() throws Exception
88      {
89          SimpleCallableJavaComponent component = new SimpleCallableJavaComponent(
90              new Apple());
91          component.setFlowConstruct(getTestService());
92          component.setMuleContext(muleContext);
93          component.initialise();
94          component.start();
95  
96          assertNull(component.borrowComponentLifecycleAdaptor());
97  
98          Object obj = component.getObjectFactory().getInstance(muleContext);
99          assertNotNull(obj);
100 
101         component.stop();
102         component.dispose();
103 //        try
104 //        {
105 //            component.checkDisposed();
106 //        }
107 //        catch (Exception e)
108 //        {
109 //            assertSame(DisposeException.class, e.getClass());
110 //        }
111 
112     }
113 
114 }