1 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 ; 19 20 30 public abstract class FunctionalTestCase extends AbstractMuleTestCase 31 { 32 33 public static final String DEFAULT_BUILDER_CLASS = "org.mule.config.builders.MuleXmlConfigurationBuilder"; 34 35 protected final void doSetUp() throws Exception 36 { 37 doPreFunctionalSetUp(); 38 if (!getTestInfo().isDisposeManagerPerSuite()) 40 { 41 setupManager(); 42 } 43 doPostFunctionalSetUp(); 44 } 45 46 protected void suitePreSetUp() throws Exception 47 { 48 if (getTestInfo().isDisposeManagerPerSuite()) 49 { 50 setupManager(); 51 } 52 } 53 54 protected void setupManager() throws Exception 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 62 { 63 doFunctionalTearDown(); 64 } 65 66 protected ConfigurationBuilder getBuilder() throws Exception 67 { 68 69 try 70 { 71 Class builderClass = ClassUtils.loadClass(DEFAULT_BUILDER_CLASS, getClass()); 72 return (ConfigurationBuilder)builderClass.newInstance(); 73 } 74 catch (ClassNotFoundException e) 75 { 76 throw new ClassNotFoundException ( 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 87 { 88 } 90 91 protected void doPostFunctionalSetUp() throws Exception 92 { 93 } 95 96 protected void doFunctionalTearDown() throws Exception 97 { 98 } 100 101 protected abstract String getConfigResources(); 102 103 public class TestingWorkListener extends DefaultWorkListener 104 { 105 protected void handleWorkException(WorkEvent event, String type) 106 { 107 super.handleWorkException(event, type); 108 if (event.getException() != null) 109 { 110 Throwable t = event.getException().getCause(); 111 if (t != null) 112 { 113 114 if (t instanceof Error ) 115 { 116 throw (Error )t; 117 } 118 else if (t instanceof RuntimeException ) 119 { 120 throw (RuntimeException )t; 121 } 122 } 123 124 } 125 } 126 } 127 128 } 129 | Popular Tags |