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