KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > tck > FunctionalTestCase


1 /*
2  * $Id: FunctionalTestCase.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.tck;
12
13 import org.mule.MuleManager;
14 import org.mule.util.ClassUtils;
15 import org.mule.config.ConfigurationBuilder;
16 import org.mule.umo.manager.DefaultWorkListener;
17
18 import javax.resource.spi.work.WorkEvent JavaDoc;
19
20 /**
21  * Is a base tast case for tests that initialise Mule using a configuration file. The
22  * default configuration builder used is the MuleXmlConfigurationBuilder. This you
23  * need to have the mule-modules-builders module/jar on your classpath. If you want
24  * to use a different builder, just overload the <code>getBuilder()</code> method
25  * of this class to return the type of builder you want to use with your test. Note
26  * you can overload the <code>getBuilder()</code> to return an initialised instance
27  * of the QuickConfiguratonBuilder, this allows the developer to programmatically
28  * build a Mule instance and roves the need for additional config files for the test.
29  */

30 public abstract class FunctionalTestCase extends AbstractMuleTestCase
31 {
32
33     public static final String JavaDoc DEFAULT_BUILDER_CLASS = "org.mule.config.builders.MuleXmlConfigurationBuilder";
34
35     protected final void doSetUp() throws Exception JavaDoc
36     {
37         doPreFunctionalSetUp();
38         // Should we set up te manager for every method?
39
if (!getTestInfo().isDisposeManagerPerSuite())
40         {
41             setupManager();
42         }
43         doPostFunctionalSetUp();
44     }
45
46     protected void suitePreSetUp() throws Exception JavaDoc
47     {
48         if (getTestInfo().isDisposeManagerPerSuite())
49         {
50             setupManager();
51         }
52     }
53
54     protected void setupManager() throws Exception JavaDoc
55     {
56         MuleManager.getConfiguration().setWorkListener(new TestingWorkListener());
57         ConfigurationBuilder builder = getBuilder();
58         builder.configure(getConfigResources(), null);
59     }
60
61     protected final void doTearDown() throws Exception JavaDoc
62     {
63         doFunctionalTearDown();
64     }
65
66     protected ConfigurationBuilder getBuilder() throws Exception JavaDoc
67     {
68
69         try
70         {
71             Class JavaDoc builderClass = ClassUtils.loadClass(DEFAULT_BUILDER_CLASS, getClass());
72             return (ConfigurationBuilder)builderClass.newInstance();
73         }
74         catch (ClassNotFoundException JavaDoc e)
75         {
76             throw new ClassNotFoundException JavaDoc(
77                 "The builder "
78                                 + DEFAULT_BUILDER_CLASS
79                                 + " is not on your classpath and "
80                                 + "the getBuilder() method of this class has not been overloaded to return adifferent builder. Please "
81                                 + "check your functional test.", e);
82         }
83
84     }
85
86     protected void doPreFunctionalSetUp() throws Exception JavaDoc
87     {
88         // template method
89
}
90
91     protected void doPostFunctionalSetUp() throws Exception JavaDoc
92     {
93         // template method
94
}
95
96     protected void doFunctionalTearDown() throws Exception JavaDoc
97     {
98         // template method
99
}
100
101     protected abstract String JavaDoc getConfigResources();
102
103     public class TestingWorkListener extends DefaultWorkListener
104     {
105         protected void handleWorkException(WorkEvent JavaDoc event, String JavaDoc type)
106         {
107             super.handleWorkException(event, type);
108             if (event.getException() != null)
109             {
110                 Throwable JavaDoc t = event.getException().getCause();
111                 if (t != null)
112                 {
113
114                     if (t instanceof Error JavaDoc)
115                     {
116                         throw (Error JavaDoc)t;
117                     }
118                     else if (t instanceof RuntimeException JavaDoc)
119                     {
120                         throw (RuntimeException JavaDoc)t;
121                     }
122                 }
123
124             }
125         }
126     }
127
128 }
129
Popular Tags