org.apache.avalon.excalibur.testcase
Class ExcaliburTestCase

java.lang.Object
  extended byjunit.framework.Assert
      extended byjunit.framework.TestCase
          extended byorg.apache.avalon.excalibur.testcase.ExcaliburTestCase
All Implemented Interfaces:
junit.framework.Test

Deprecated. ECM is no longer supported

public class ExcaliburTestCase
extends junit.framework.TestCase

JUnit TestCase for Avalon Components.

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

manager
This instance variable contains an initialized ComponentLocator which can be used to lookup Components configured in the test configuration file. (see below)
getLogger()
This method returns the default logger for this test case

The following test case configuration can be used as a basis for new tests. Detailed are explanations of the configuration elements can be found after the example. The example will log all logger output to the console and to a log file.

   <testcase>
     <annotation>
       <![CDATA[
         <title>{Name of test}</title>
         <para>
           {Description of test}
           The configuration is specified in the file located in
           <parameter>avalon-excalibur/src/test/{path and name of conf file}.xtext</parameter>.
         </para>
       ]]>
     </annotation>

     <logkit log-level="INFO">
       <factories>
         <factory type="stream" class="org.apache.avalon.excalibur.logger.factory.StreamTargetFactory"/>
         <factory type="file" class="org.apache.avalon.excalibur.logger.factory.FileTargetFactory"/>
       </factories>

       <targets>
         <stream id="console">
           <stream>System.out</stream>
           <format type="avalon">
             %7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%30.30{category}] (%{context}): %{message}\n%{throwable}
           </format>
         </stream>
         <file id="log-file">
           <filename>TEST-{full test class name}.log</filename>
           <format type="avalon">
             %7.7{priority} %23.23{time:yyyy-MM-dd' 'HH:mm:ss.SSS} [%30.30{category}] (%{context}): %{message}\n%{throwable}
           </format>
         </file>
       </targets>

       <categories>
         <category name="test" log-level="INFO">
           <log-target id-ref="console"/>
           <log-target id-ref="log-file"/>
         </category>
         <category name="jdbc" log-level="INFO">
           <log-target id-ref="console"/>
           <log-target id-ref="log-file"/>
         </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" logger="jdbc">
           <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>
 

Element Explanation:

testcase
Defines a test case configuration. Must contain one each of the following elements: annotation, logkit, context, roles, and components
.
annotation
Defines a test annotation. This element should define a block of XML enclosed within a CDATA element. The XML should be made up of a title element, naming the test, and a para element which is used to describe the test.
logkit
Configures the logger used by the test cases and the components used by the tests. The logkit element takes two optional attributes:
logger
Uses to name the logger which is used to bootstrap the LogKit logger. (Defaults to "lm")
log-level
Because the logger used by the LogKit must be created before the Log Kit Manager is initialized, it must be fully configured before the logkit element is parsed. This attribute allows the Log Kit's log priority to be set. This log level will also become the default for the Role Manager, Component Manager, and all components if they do not have category elements declated in the logkit element. (Defaults to "INFO")
The loggers used by test cases and components can be easily configured from within this file. The default test configuration, shown above, includes a "test" category. This category is used to configure the default logger for all test cases. If it is set to "DEBUG", then all test debug logging will be enabled. To enalble debug logging for a single test case, a child category must be defined for the "testCheckTotals" test case as follows:
       <categories>
         <category name="test" log-level="INFO">
           <log-target id-ref="console"/>
           <log-target id-ref="log-file"/>

           <category name="testCheckTotals" log-level="DEBUG">
             <log-target id-ref="console"/>
             <log-target id-ref="log-file"/>
           </category>
         </category>
       </categories>
  
For general information on how to configure the LogKit Manager, please refer to the Log Kit documentation.
context
Allows context properties to be set in the context passed to any Contextualizable components.
roles
Roles configuration for the Components configured in the components element. The logger used by the RoleManager can be configured using a logger attribute, which defaults to "rm". By default this logger will have the same log level and formatting as the LogKit logger. It can be configured by adding a category within the logkit element.
components
Used to configure any Components used by the test cases. The logger used by the ComponentLocator can be configured using a logger attribute, which defaults to "cm". By default this logger will have the same log level and formatting as the LogKit logger. It can be configured by adding a category within the logkit element.

Version:
$Id: ExcaliburTestCase.java,v 1.6 2004/02/28 11:47:27 cziegeler Exp $
Author:
Avalon Development Team

Field Summary
protected  ComponentManager manager
          Deprecated.  
 
Constructor Summary
ExcaliburTestCase(java.lang.String name)
          Deprecated.  
 
Method Summary
protected  void addContext(DefaultContext context)
          Deprecated. This method may be overwritten by subclasses to put additional objects into the context programmatically.
protected  LogKitLogger getLogEnabledLogger()
          Deprecated. Return the logger
protected  Logger getLogger()
          Deprecated. Return the logger
protected  java.lang.Object lookup(java.lang.String key)
          Deprecated.  
protected  void prepare()
          Deprecated. Initializes the ComponentLocator The configuration file is determined by the class name plus .xtest appended, all '.' replaced by '/' and loaded as a resource via classpath
protected  void prepare(java.io.InputStream testconf)
          Deprecated. Initializes the ComponentLocator
protected  void release(Component object)
          Deprecated.  
 void run(junit.framework.TestResult result)
          Deprecated. Override run so that we can have code that is run once.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, runBare, runTest, setName, setUp, tearDown, toString
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, 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

manager

protected ComponentManager manager
Deprecated. 
Constructor Detail

ExcaliburTestCase

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

getLogger

protected Logger getLogger()
Deprecated. 
Return the logger


getLogEnabledLogger

protected LogKitLogger getLogEnabledLogger()
Deprecated. 
Return the logger


prepare

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

Throws:
java.lang.Exception

prepare

protected final void prepare(java.io.InputStream testconf)
                      throws java.lang.Exception
Deprecated. 
Initializes the ComponentLocator

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.
Throws:
java.lang.Exception

run

public final void run(junit.framework.TestResult result)
Deprecated. 
Override run so that we can have code that is run once.


addContext

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


lookup

protected final java.lang.Object lookup(java.lang.String key)
                                 throws ComponentException
Deprecated. 
Throws:
ComponentException

release

protected final void release(Component object)
Deprecated. 


Copyright © 1997-2005 The Apache Software Foundation. All Rights Reserved.