Coverage Report - org.mule.tck.FunctionalTestCase
 
Classes in this File Line Coverage Branch Coverage Complexity
FunctionalTestCase
91%
20/22
100%
4/4
1.556
 
 1  
 /*
 2  
  * $Id: FunctionalTestCase.java 7963 2007-08-21 08:53:15Z dirk.olmes $
 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 CPAL v1.0
 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.config.ConfigurationBuilder;
 15  
 import org.mule.util.ClassUtils;
 16  
 
 17  
 /**
 18  
  * Is a base tast case for tests that initialise Mule using a configuration file. The
 19  
  * default configuration builder used is the MuleXmlConfigurationBuilder. This you
 20  
  * need to have the mule-modules-builders module/jar on your classpath. If you want
 21  
  * to use a different builder, just overload the <code>getBuilder()</code> method
 22  
  * of this class to return the type of builder you want to use with your test. Note
 23  
  * you can overload the <code>getBuilder()</code> to return an initialised instance
 24  
  * of the QuickConfiguratonBuilder, this allows the developer to programmatically
 25  
  * build a Mule instance and roves the need for additional config files for the test.
 26  
  */
 27  178
 public abstract class FunctionalTestCase extends AbstractMuleTestCase
 28  
 {
 29  
 
 30  
     public static final String DEFAULT_BUILDER_CLASS = "org.mule.config.builders.MuleXmlConfigurationBuilder";
 31  
 
 32  
     protected final void doSetUp() throws Exception
 33  
     {
 34  178
         doPreFunctionalSetUp();
 35  
         // Should we set up te manager for every method?
 36  178
         if (!getTestInfo().isDisposeManagerPerSuite())
 37  
         {
 38  12
             setupManager();
 39  
         }
 40  178
         doPostFunctionalSetUp();
 41  178
     }
 42  
 
 43  
     protected void suitePreSetUp() throws Exception
 44  
     {
 45  14
         if (getTestInfo().isDisposeManagerPerSuite())
 46  
         {
 47  8
             setupManager();
 48  
         }
 49  14
     }
 50  
 
 51  
     protected void setupManager() throws Exception
 52  
     {
 53  20
         MuleManager.getConfiguration().setWorkListener(new TestingWorkListener());
 54  20
         ConfigurationBuilder builder = getBuilder();
 55  20
         builder.configure(getConfigResources(), null);
 56  20
     }
 57  
 
 58  
     protected final void doTearDown() throws Exception
 59  
     {
 60  178
         doFunctionalTearDown();
 61  178
     }
 62  
 
 63  
     protected ConfigurationBuilder getBuilder() throws Exception
 64  
     {
 65  
 
 66  
         try
 67  
         {
 68  14
             Class builderClass = ClassUtils.loadClass(DEFAULT_BUILDER_CLASS, getClass());
 69  14
             return (ConfigurationBuilder)builderClass.newInstance();
 70  
         }
 71  0
         catch (ClassNotFoundException e)
 72  
         {
 73  0
             throw new ClassNotFoundException(
 74  
                 "The builder "
 75  
                                 + DEFAULT_BUILDER_CLASS
 76  
                                 + " is not on your classpath and "
 77  
                                 + "the getBuilder() method of this class has not been overloaded to return a different builder. Please "
 78  
                                 + "check your functional test.", e);
 79  
         }
 80  
 
 81  
     }
 82  
 
 83  
     protected void doPreFunctionalSetUp() throws Exception
 84  
     {
 85  
         // template method
 86  178
     }
 87  
 
 88  
     protected void doPostFunctionalSetUp() throws Exception
 89  
     {
 90  
         // template method
 91  178
     }
 92  
 
 93  
     protected void doFunctionalTearDown() throws Exception
 94  
     {
 95  
         // template method
 96  178
     }
 97  
 
 98  
     protected abstract String getConfigResources();
 99  
 }