1
2
3
4
5
6
7
8
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.initialise();
93 component.start();
94
95 assertNull(component.borrowComponentLifecycleAdaptor());
96
97 Object obj = component.getObjectFactory().getInstance(muleContext);
98 assertNotNull(obj);
99
100 component.stop();
101 component.dispose();
102
103
104
105
106
107
108
109
110
111 }
112
113 }