1
2
3
4
5
6
7
8
9
10
11 package org.mule.test.components;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertNotNull;
15 import static org.junit.Assert.assertTrue;
16
17 import org.junit.Test;
18 import org.mule.api.construct.FlowConstruct;
19 import org.mule.tck.junit4.FunctionalTestCase;
20 import org.mule.tck.testmodels.fruit.Orange;
21
22 public class ServiceDescriptorFlowTestCase extends FunctionalTestCase
23 {
24
25 @Override
26 protected String getConfigResources()
27 {
28 return "org/mule/test/components/service-factory-functional-test-flow.xml";
29 }
30
31 @Test
32 public void testGenericObjectFactory() throws Exception
33 {
34 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange1");
35
36 Object flow = getComponent(c);
37 assertTrue("Flow should be an Orange", flow instanceof Orange);
38
39 assertEquals(new Integer(10), ((Orange) flow).getSegments());
40 }
41
42 @Test
43 public void testGenericObjectFactoryWithProperties() throws Exception
44 {
45 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange2");
46
47
48 Object flow = getComponent(c);
49 assertTrue("Flow should be an Orange", flow instanceof Orange);
50 assertEquals(new Integer(8), ((Orange) flow).getSegments());
51 assertEquals("Florida Sunny", ((Orange) flow).getBrand());
52
53
54 flow = getComponent(c);
55 assertTrue("Service should be an Orange", flow instanceof Orange);
56 assertEquals(new Integer(8), ((Orange) flow).getSegments());
57 assertEquals("Florida Sunny", ((Orange) flow).getBrand());
58 }
59
60 @Test
61 public void testSingletonObjectFactory() throws Exception
62 {
63 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange3");
64
65 Object flow = getComponent(c);
66 assertTrue("Flow should be an Orange", flow instanceof Orange);
67
68 assertEquals(new Integer(10), ((Orange) flow).getSegments());
69 }
70
71 @Test
72 public void testSpringSingleton() throws Exception
73 {
74 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange4");
75
76 Object flow = getComponent(c);
77 assertTrue("Flow should be an Orange", flow instanceof Orange);
78
79 assertEquals(new Integer(10), ((Orange) flow).getSegments());
80 }
81
82 @Test
83 public void testSpringFactoryBean() throws Exception
84 {
85 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange5");
86
87 Object flow = getComponent(c);
88 assertNotNull(flow);
89 assertTrue("Flow should be an Orange but is: " + flow.getClass(), flow instanceof Orange);
90 assertEquals(new Integer(8), ((Orange) flow).getSegments());
91 assertEquals("Florida Sunny", ((Orange) flow).getBrand());
92 }
93
94 @Test
95 public void testPojoAsFactoryBean() throws Exception
96 {
97 FlowConstruct c = muleContext.getRegistry().lookupFlowConstruct("orange6");
98
99 Object flow = getComponent(c);
100 assertNotNull(flow);
101 assertTrue("Flow should be an Orange but is: " + flow.getClass(), flow instanceof Orange);
102 assertEquals("Florida Sunny", ((Orange) flow).getBrand());
103 }
104 }