01: /*
02: * $Id: FunctionalTestCase.java 11373 2008-03-15 05:03:10Z dfeist $
03: * --------------------------------------------------------------------------------------
04: * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
05: *
06: * The software in this package is published under the terms of the CPAL v1.0
07: * license, a copy of which has been included with this distribution in the
08: * LICENSE.txt file.
09: */
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.tck.functional.FunctionalTestComponent;
20:
21: /**
22: * Is a base tast case for tests that initialise Mule using a configuration file. The
23: * default configuration builder used is the MuleXmlConfigurationBuilder. This you
24: * need to have the mule-modules-builders module/jar on your classpath. If you want
25: * to use a different builder, just overload the <code>getBuilder()</code> method
26: * of this class to return the type of builder you want to use with your test. Note
27: * you can overload the <code>getBuilder()</code> to return an initialised instance
28: * of the QuickConfiguratonBuilder, this allows the developer to programmatically
29: * build a Mule instance and roves the need for additional config files for the test.
30: */
31: public abstract class FunctionalTestCase extends AbstractMuleTestCase {
32: /** Expected response after the test message has passed through the FunctionalTestComponent. */
33: public static final String TEST_MESSAGE_RESPONSE = FunctionalTestComponent
34: .received(TEST_MESSAGE);
35:
36: public FunctionalTestCase() {
37: super ();
38: // A functional test case starts up the management context by default.
39: setStartContext(true);
40: }
41:
42: protected ConfigurationBuilder getBuilder() throws Exception {
43: return new SpringXmlConfigurationBuilder(
44: getConfigurationResources());
45: }
46:
47: //Delegate to an abstract method to ensure that FunctionalTestCases know they need to pass in config resources
48: protected String getConfigurationResources() {
49: return getConfigResources();
50: }
51:
52: protected abstract String getConfigResources();
53:
54: protected Object getComponent(String serviceName) throws Exception {
55: Service service = muleContext.getRegistry().lookupService(
56: serviceName);
57: if (service != null) {
58: return getComponent(service);
59: } else {
60: throw new RegistrationException("Service " + serviceName
61: + " not found in Registry");
62: }
63: }
64:
65: protected Object getComponent(Service service) throws Exception {
66: if (service.getComponent() instanceof JavaComponent) {
67: return ((AbstractJavaComponent) service.getComponent())
68: .getObjectFactory().getInstance();
69: } else {
70: fail("Componnent is not a JavaComponent and therefore has no component object instance");
71: return null;
72: }
73: }
74: }
|