1
2
3
4
5
6
7 package org.mule.tck;
8
9 import org.mule.api.component.Component;
10 import org.mule.api.component.JavaComponent;
11 import org.mule.api.config.ConfigurationBuilder;
12 import org.mule.api.construct.FlowConstruct;
13 import org.mule.api.processor.MessageProcessor;
14 import org.mule.api.registry.RegistrationException;
15 import org.mule.api.service.Service;
16 import org.mule.component.AbstractJavaComponent;
17 import org.mule.config.i18n.MessageFactory;
18 import org.mule.config.spring.SpringXmlConfigurationBuilder;
19 import org.mule.construct.SimpleFlowConstruct;
20 import org.mule.construct.SimpleService;
21 import org.mule.tck.functional.FunctionalTestComponent;
22 import org.mule.util.IOUtils;
23
24 import java.io.IOException;
25 import java.io.InputStream;
26
27
28
29
30
31
32
33
34
35
36 @Deprecated
37 public abstract class FunctionalTestCase extends AbstractMuleTestCase
38 {
39 public FunctionalTestCase()
40 {
41 super();
42
43 setStartContext(true);
44 }
45
46 @Override
47 protected ConfigurationBuilder getBuilder() throws Exception
48 {
49 return new SpringXmlConfigurationBuilder(getConfigResources());
50 }
51
52 protected abstract String getConfigResources();
53
54
55
56
57
58
59
60
61 protected Object getComponent(String serviceName) throws Exception
62 {
63 final FlowConstruct flowConstruct = muleContext.getRegistry().lookupObject(serviceName);
64
65 if (flowConstruct != null)
66 {
67 return getComponent(flowConstruct);
68 }
69 else
70 {
71 throw new RegistrationException(MessageFactory.createStaticMessage("Service " + serviceName
72 + " not found in Registry"));
73 }
74 }
75
76
77
78
79
80
81
82
83 protected Object getComponent(FlowConstruct flowConstruct) throws Exception
84 {
85 if (flowConstruct instanceof Service)
86 {
87 return getComponentObject(((Service) flowConstruct).getComponent());
88 }
89 else if (flowConstruct instanceof SimpleService)
90 {
91 return getComponentObject(((SimpleService) flowConstruct).getComponent());
92 }
93 else if (flowConstruct instanceof SimpleFlowConstruct)
94 {
95 SimpleFlowConstruct flow = (SimpleFlowConstruct)flowConstruct;
96
97 for (MessageProcessor processor : flow.getMessageProcessors())
98 {
99 if(processor instanceof Component)
100 {
101 return getComponentObject(((Component) processor));
102 }
103 }
104
105 }
106 throw new RegistrationException(
107 MessageFactory.createStaticMessage("Can't get component from flow construct "
108 + flowConstruct.getName()));
109 }
110
111
112
113
114
115
116
117
118
119 protected FunctionalTestComponent getFunctionalTestComponent(String serviceName) throws Exception
120 {
121 return (FunctionalTestComponent) getComponent(serviceName);
122 }
123
124 protected FlowConstruct getFlowConstruct(String name) throws Exception
125 {
126 return muleContext.getRegistry().lookupFlowConstruct(name);
127 }
128
129 protected String loadResourceAsString(String name) throws IOException
130 {
131 return IOUtils.getResourceAsString(name, getClass());
132 }
133
134 protected InputStream loadResource(String name) throws IOException
135 {
136 return IOUtils.getResourceAsStream(name, getClass());
137 }
138
139 private Object getComponentObject(Component component) throws Exception
140 {
141 if (component instanceof JavaComponent)
142 {
143 return ((AbstractJavaComponent) component).getObjectFactory().getInstance(muleContext);
144 }
145 else
146 {
147 fail("Component is not a JavaComponent and therefore has no component object instance");
148 return null;
149 }
150 }
151 }