org.apache.avalon.excalibur.testcase
Class ExcaliburTestCase

java.lang.Object
  |
  +--junit.framework.Assert
        |
        +--junit.framework.TestCase
              |
              +--org.apache.avalon.excalibur.testcase.ExcaliburTestCase
All Implemented Interfaces:
junit.framework.Test

public class ExcaliburTestCase
extends junit.framework.TestCase

JUnit TestCase for Avalon Components

This class will extends the JUnit TestCase class to setup an environment to easily test Avalon Components. The following methods and instance variables are exposed for convenience testing:

m_logPriority
This variable contains the log priority of the default logger setup at startup of the test. Overwrite the initialize() method to set a different Priority.
manager
This instance variable contains a initialized ComponentManager according to the test case configuration file (see below)
getLogger()
This method returns the default logger for this test case

The test case configuration file has the following structure:

   <testcase>
     <annotation>
       <![CDATA[
         <title>DataSourceComponent tests</title>
         <para>
           This is some <emphasis>text</emphasis> to
           describethe tests made herein. Unfortunately the
           ConfigurationBuilder used to read the test case configuration
           file doesn't allow to have mixed context. This should be fixed
           in a future version .
         </para>
       ]]>
     </annotation>

     <logkit>
       <factories>
         <factory type="file" class="org.apache.avalon.excalibur.logger.facatory.FileTargetFactory"/>
         <factory type="property-filter" class="org.apache.avalon.excalibur.logger.facatory.FilterTargetFactory"/>
         <factory type="servlet" class="org.apache.avalon.excalibur.logger.facatory.ServletTargetFactory"/>
         ...
       </factories>

       <targets>
         <file id="root">
           <filename>dev/logs/main.log</filename>
         </file>
         <file id="classloader">
           <filename>dev/logs/classloader.log</filename>
         </file>
         <priority-filter id="servlet" log-level="ERROR">
           <servlet/>
         </priority-filter>
       </targets>

       <categories>
         <category name="cocoon" log-level="INFO">
           <log-target id-ref="root"/>
           <log-target id-ref="servlet"/>

           <category name="classloader" log-level="DEBUG">
             <log-target id-ref="classloader"/>
           </category>
         </category>
       </categories>
     </logkit>

     <context>
       <entry name="foo" value="bar"/>
       <entry name="baz" class="my.context.Class"/>
     </context>

     <roles>
       <role name="org.apache.avalon.excalibur.datasource.DataSourceComponentSelector"
             shorthand="datasources"
             default-class="org.apache.avalon.excalibur.component.ExcaliburComponentSelector">
          <hint shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.JdbcDataSource"/>
       </role>
     </roles>

     <components>
       <datasources>
         <jdbc name="personell">
           <pool-controller min="5" max="10"/>
           <jdbc name="personnel">
           <dburl>jdbc:odbc:test</dburl>
           <user>test</user>
           <password>test</password>
           <driver>sun.jdbc.odbc.JdbcOdbcDriver</driver>
         </jdbc>
       </datasources>
     </components>
   </testcase>
 

Version:
$Id: ExcaliburTestCase.java,v 1.4 2001/08/25 14:52:59 giacomo Exp $
Author:
Giacomo Pati

Field Summary
protected  org.apache.log.Priority m_logPriority
           
protected  org.apache.avalon.framework.component.ComponentManager manager
           
 
Constructor Summary
ExcaliburTestCase(java.lang.String name)
           
 
Method Summary
protected  void addContext(org.apache.avalon.framework.context.DefaultContext context)
          This method may be overwritten by subclasses to put additional objects into the context programmatically.
protected  org.apache.log.Logger getLogger()
          Return the logger
protected  void initialize()
          Initializes the ComponentManager The configuration file is determined by the class name plus .xtest appended, all '.' replaced by '/' and loaded as a resource via classpath
protected  void initialize(java.io.InputStream testconf)
          Initializes the ComponentManager
 void setUp()
           
 void tearDown()
           
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, name, run, run, runBare, runTest, setName, toString
 
Methods inherited from class junit.framework.Assert
assert, assert, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertNotNull, assertNotNull, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_logPriority

protected org.apache.log.Priority m_logPriority

manager

protected org.apache.avalon.framework.component.ComponentManager manager
Constructor Detail

ExcaliburTestCase

public ExcaliburTestCase(java.lang.String name)
Method Detail

setUp

public void setUp()
           throws java.lang.Exception
Overrides:
setUp in class junit.framework.TestCase

tearDown

public void tearDown()
              throws java.lang.Exception
Overrides:
tearDown in class junit.framework.TestCase

getLogger

protected org.apache.log.Logger getLogger()
Return the logger

initialize

protected void initialize()
                   throws java.lang.Exception
Initializes the ComponentManager The configuration file is determined by the class name plus .xtest appended, all '.' replaced by '/' and loaded as a resource via classpath

initialize

protected final void initialize(java.io.InputStream testconf)
                         throws java.lang.Exception
Initializes the ComponentManager
Parameters:
testconf - The configuration file is passed as a InputStream A common way to supply a InputStream is to overwrite the initialize() method in the sub class, do there whatever is needed to get the right InputStream object supplying a conformant xtest configuartion and pass it to this initialize method. the mentioned initialize method is also the place to set a different logging priority to the member variable m_logPriority.

addContext

protected void addContext(org.apache.avalon.framework.context.DefaultContext context)
This method may be overwritten by subclasses to put additional objects into the context programmatically.


Copyright © 2001 Apache Jakarta Project. All Rights Reserved.