|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjunit.framework.Assert
junit.framework.TestCase
org.apache.avalon.fortress.testcase.FortressTestCase
public class FortressTestCase
JUnit TestCase for Avalon Components in Fortress.
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:
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> <logger 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> </logger> <context> <entry name="foo" value="bar"/> <entry name="baz" class="my.context.Class"/> </context> <roles> <role name="org.apache.avalon.excalibur.datasource.DataSourceComponent" <component shorthand="jdbc" class="org.apache.avalon.excalibur.datasource.JdbcDataSource" handler="org.apache.avalon.fortress.impl.handler.ThreadSafeComponentHandler"/> </role> </roles> <components> <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> </components> </testcase>
Element Explanation:
annotation
, logger
,
context
, roles
, and components
title
element, naming the test, and a para
element which is used to describe the test.logger
element takes two optional
attributes:
"lm"
)logger
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, Service
Manager, and all components if they do not have category
elements declated in the logger
element.
(Defaults to "INFO")<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 Logger Manager, please refer to the Log Kit documentation.
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 logger
element.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 logger
element.
Field Summary | |
---|---|
private static java.lang.String |
FORMAT
|
private org.apache.avalon.fortress.impl.DefaultContainer |
m_container
|
private org.apache.avalon.fortress.impl.DefaultContainerManager |
m_containerManager
|
private org.apache.avalon.framework.logger.Logger |
m_logger
|
private org.apache.avalon.excalibur.logger.LoggerManager |
m_loggerManager
|
private org.apache.avalon.framework.service.ServiceManager |
m_serviceManager
|
private static java.util.HashMap |
m_tests
|
Constructor Summary | |
---|---|
FortressTestCase(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. |
private void |
done()
Disposes Fortress |
private java.lang.String |
getBaseClassName(java.lang.Class clazz)
Exctract the base class name of a class. |
protected org.apache.avalon.framework.logger.Logger |
getLogger()
Return the logger |
protected boolean |
hasService(java.lang.String key)
|
protected java.lang.Object |
lookup(java.lang.String key)
|
protected void |
prepare()
Initializes Fortress. |
protected void |
prepare(java.io.InputStream testconf)
Initializes Fortress. |
protected void |
release(java.lang.Object object)
|
void |
run(junit.framework.TestResult result)
Override run so that we can have code that is run once. |
private void |
setCurrentLogger(java.lang.String name)
Sets the logger which will be returned by getLogger and getLogEnabledLogger |
private org.apache.avalon.framework.context.Context |
setupContext(org.apache.avalon.framework.configuration.Configuration conf,
org.apache.avalon.framework.context.Context parentContext)
Set up a context according to the xtest configuration specifications context element. |
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, failNotEquals, failNotSame, failSame |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String FORMAT
private org.apache.avalon.framework.logger.Logger m_logger
private org.apache.avalon.fortress.impl.DefaultContainerManager m_containerManager
private org.apache.avalon.fortress.impl.DefaultContainer m_container
private org.apache.avalon.excalibur.logger.LoggerManager m_loggerManager
private org.apache.avalon.framework.service.ServiceManager m_serviceManager
private static java.util.HashMap m_tests
Constructor Detail |
---|
public FortressTestCase(java.lang.String name)
Method Detail |
---|
protected final boolean hasService(java.lang.String key)
protected final java.lang.Object lookup(java.lang.String key) throws org.apache.avalon.framework.service.ServiceException
org.apache.avalon.framework.service.ServiceException
protected final void release(java.lang.Object object)
protected org.apache.avalon.framework.logger.Logger getLogger()
public final void run(junit.framework.TestResult result)
run
so that we can have code that is run once.
run
in interface junit.framework.Test
run
in class junit.framework.TestCase
protected void prepare() throws java.lang.Exception
java.lang.Exception
protected final void prepare(java.io.InputStream testconf) throws java.lang.Exception
testconf
- The configuration file is passed as an InputStream
A common way to supply a InputStream is to overide the prepare() 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 prepare method.
the mentioned initialize method is also the place to set a different logging priority
to the member variable m_logPriority.
java.lang.Exception
private void setCurrentLogger(java.lang.String name)
private org.apache.avalon.framework.context.Context setupContext(org.apache.avalon.framework.configuration.Configuration conf, org.apache.avalon.framework.context.Context parentContext) throws java.lang.Exception
java.lang.Exception
protected void addContext(org.apache.avalon.framework.context.DefaultContext context)
private java.lang.String getBaseClassName(java.lang.Class clazz)
private void done()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |