1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck; |
12 | |
|
13 | |
import org.mule.api.component.JavaComponent; |
14 | |
import org.mule.api.config.ConfigurationBuilder; |
15 | |
import org.mule.api.registry.RegistrationException; |
16 | |
import org.mule.api.service.Service; |
17 | |
import org.mule.component.AbstractJavaComponent; |
18 | |
import org.mule.config.spring.SpringXmlConfigurationBuilder; |
19 | |
import org.mule.util.IOUtils; |
20 | |
|
21 | |
import java.io.IOException; |
22 | |
import java.io.InputStream; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public abstract class FunctionalTestCase extends AbstractMuleTestCase |
32 | |
{ |
33 | |
public FunctionalTestCase() |
34 | |
{ |
35 | 346 | super(); |
36 | |
|
37 | 346 | setStartContext(true); |
38 | 346 | } |
39 | |
|
40 | |
protected ConfigurationBuilder getBuilder() throws Exception |
41 | |
{ |
42 | 290 | return new SpringXmlConfigurationBuilder(getConfigurationResources()); |
43 | |
} |
44 | |
|
45 | |
|
46 | |
protected String getConfigurationResources() |
47 | |
{ |
48 | 290 | return getConfigResources(); |
49 | |
} |
50 | |
|
51 | |
protected abstract String getConfigResources(); |
52 | |
|
53 | |
protected Object getComponent(String serviceName) throws Exception |
54 | |
{ |
55 | 6 | Service service = muleContext.getRegistry().lookupService(serviceName); |
56 | 6 | if (service != null) |
57 | |
{ |
58 | 6 | return getComponent(service); |
59 | |
} |
60 | |
else |
61 | |
{ |
62 | 0 | throw new RegistrationException("Service " + serviceName + " not found in Registry"); |
63 | |
} |
64 | |
} |
65 | |
|
66 | |
protected Object getComponent(Service service) throws Exception |
67 | |
{ |
68 | 22 | if (service.getComponent() instanceof JavaComponent) |
69 | |
{ |
70 | 22 | return ((AbstractJavaComponent) service.getComponent()).getObjectFactory().getInstance(); |
71 | |
} |
72 | |
else |
73 | |
{ |
74 | 0 | fail("Componnent is not a JavaComponent and therefore has no component object instance"); |
75 | 0 | return null; |
76 | |
} |
77 | |
} |
78 | |
|
79 | |
protected String loadResourceAsString(String name) throws IOException |
80 | |
{ |
81 | 2 | return IOUtils.getResourceAsString(name, getClass()); |
82 | |
} |
83 | |
|
84 | |
protected InputStream loadResource(String name) throws IOException |
85 | |
{ |
86 | 0 | return IOUtils.getResourceAsStream(name, getClass()); |
87 | |
} |
88 | |
} |