You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by mc...@apache.org on 2004/02/25 12:28:05 UTC
cvs commit: avalon/logging/test/src/test/org/apache/avalon/logging/logkit/test DefaultLoggingManagerTestCase.java LoggingManagerHelper.java
mcconnell 2004/02/25 03:28:05
Added: logging/test .cvsignore maven.xml project.xml
logging/test/conf/log4j log4j.properties log4j.xml
logging.xml
logging/test/conf/logkit logging.xml
logging/test/src/test/org/apache/avalon/logging/log4j/test
DefaultLoggingManagerTestCase.java
LoggingManagerHelper.java
logging/test/src/test/org/apache/avalon/logging/logkit/test
DefaultLoggingManagerTestCase.java
LoggingManagerHelper.java
Log:
Add system test package.
Revision Changes Path
1.1 avalon/logging/test/.cvsignore
Index: .cvsignore
===================================================================
maven.log
velocity.log
build.properties
target
.classpath
.project
1.1 avalon/logging/test/maven.xml
Index: maven.xml
===================================================================
<project default="test:test">
</project>
1.1 avalon/logging/test/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<project>
<extend>${basedir}/../../project.xml</extend>
<groupId>avalon-logging</groupId>
<id>avalon-logkit-test</id>
<name>Avalon Logging Test</name>
<package>org.apache.avalon.logging</package>
<currentVersion>1.0-SNAPSHOT</currentVersion>
<inceptionYear>2002</inceptionYear>
<shortDescription>Avalon Logging Test.</shortDescription>
<dependencies>
<dependency>
<groupId>avalon-repository</groupId>
<artifactId>avalon-repository-main</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>avalon-framework</groupId>
<artifactId>avalon-framework-api</artifactId>
<version>4.1.5</version>
</dependency>
<dependency>
<groupId>avalon-logging</groupId>
<artifactId>avalon-logging-api</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
1.1 avalon/logging/test/conf/log4j/log4j.properties
<<Binary file>>
1.1 avalon/logging/test/conf/log4j/log4j.xml
Index: log4j.xml
===================================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration
xmlns:log4j="http://jakarta.apache.org/log4j/"
debug="false"
>
<appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
<param name="Target" value="System.err"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>
</layout>
</appender>
<category name="org.apache.avalon.logging">
<priority value="DEBUG"/>
</category>
<category name="kernel.logger">
<priority value="WARN"/>
</category>
<category name="kernel.logger.test">
<priority value="DEBUG"/>
</category>
<root>
<appender-ref ref="CONSOLE"/>
</root>
</log4j:configuration>
1.1 avalon/logging/test/conf/log4j/logging.xml
Index: logging.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<logging>
<src>../conf/log4j/log4j.xml</src>
<update>1000</update>
</logging>
1.1 avalon/logging/test/conf/logkit/logging.xml
Index: logging.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<logging debug="false">
<!--
Declaration of a set of logging targets.
-->
<targets>
<!--
This target establishes output to the the System.out stream.
The format argument ensures that we don't get stack traces -
but just the error report.
-->
<stream id="standard">
<name>System.out</name>
<format type="console"/>
</stream>
<!--
This target logs to a rotating file located in
target/simple-XXX.log
-->
<file id="simple">
<filename>simple.log</filename>
<append>true</append>
<rotation type="revolving" init="1" max="10">
<size>100k</size>
</rotation>
</file>
<!--
The multicast target redirects log event to a set of
named targets.
-->
<multicast id="multicast">
<targetref id="standard"/>
<targetref id="simple"/>
</multicast>
<!--
This target is a demonstration of the declaration of
a datagram plugin target.
-->
<target id="datagram"
artifact="avalon-logging/avalon-logkit-datagram#1.0-SNAPSHOT">
<address hostname="localhost" port="0"/>
</target>
<!--
The target is a demonstration of the declaration of
the syslog plugin target.
-->
<target id="syslog"
artifact="avalon-logging/avalon-logkit-syslog#1.0-SNAPSHOT">
<address hostname="localhost" port="514" facility="USER"/>
<format type="extended">
%7.7{priority} %23.23{time:yyyy-MM-dd HH:mm:ss:SSS} [%25.25{category}] : %{message}\n%{throwable}
</format>
</target>
<!--
The target shows the configuration of a plugable smtp target (which
has not been committed to CVS yet).
-->
<!--
<target id="smtp"
artifact="avalon-logging/avalon-logkit-smtp#1.0-SNAPSHOT">
<to>mcconnell@osm.net</to>
<from>info@dpml.net</from>
<subject>logging target test</subject>
<maximum-size>1</maximum-size>
<session>
</session>
</target>
-->
</targets>
<!--
Declaration of the initial logging categories. These categories
and the respective priorities and assigned targets are used by the
testcase to validate that the logging system is functioning properly.
-->
<categories priority="info" target="multicast">
<categories name="kernel">
<categories name="logger" priority="warn">
<category name="test" priority="fatal_error"/>
</categories>
<category name="roger-ramjet" priority="debug"/>
</categories>
</categories>
<!--
Selection of the logging channel for use by the logging
system following establishment of inital targets and categories.
-->
<logger name="kernel.logger"/>
</logging>
1.1 avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/DefaultLoggingManagerTestCase.java
Index: DefaultLoggingManagerTestCase.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.logging.log4j.test;
import java.io.File;
import java.net.URL;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.logging.provider.LoggingManager;
import org.apache.avalon.logging.provider.LoggingException;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.provider.Factory;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.provider.Builder;
import org.apache.avalon.repository.main.DefaultInitialContext;
import org.apache.avalon.repository.main.DefaultBuilder;
import org.apache.avalon.util.env.Env;
import org.apache.avalon.util.exception.ExceptionHelper;
/**
*
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $
*/
public class DefaultLoggingManagerTestCase extends TestCase
{
//-------------------------------------------------------------------
// state
//-------------------------------------------------------------------
InitialContext m_context;
LoggingManager m_manager;
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
/**
* Constructor for DefaultInitialContextTest.
* @param name the test name
*/
public DefaultLoggingManagerTestCase( String name )
{
super( name );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
protected void setUp() throws Exception
{
m_manager = LoggingManagerHelper.setUpLoggingManager( "log4j/logging.xml" );
}
public void testKernelLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.logger" );
logger.debug( "ERROR: SHOULD NOT SHOW! - this is a debug message from the kernel" );
logger.info( "ERROR: SHOULD NOT SHOW! - this is a info message from the kernel" );
logger.warn( "this is a warning message from the kernel" );
logger.error(
"this is an error message from the kernel",
new LoggingException(
"Intentional Exception for TestCase.",
new LoggingException(
"This is not a problem.",
new LoggingException( "It is used to test the Logging framework." ) ) ) );
logger.fatalError( "If the TestCase does not fail, everything is OK." );
}
public void testKernelTestLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.logger.test" );
logger.debug( "this is a debug message from test" );
logger.info( "this is a info message from test" );
logger.warn( "this is a warning message from test" );
logger.error(
"this is an error message from test",
new LoggingException(
"Intentional Exception for TestCase.",
new LoggingException(
"nested level 1",
new LoggingException( "nested level 2" ) ) ) );
logger.fatalError( "this is a fatal message from test" );
}
public void testRogerRamjetLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.roger-ramjet" );
logger.debug( "this is a debug message from roger ramjet" );
logger.info( "this is a info message from roger ramjet" );
logger.warn( "this is a warning message from roger ramjet" );
logger.error(
"this is an error message from roger ramjet",
new LoggingException(
"Intentional Exception for TestCase.",
new LoggingException(
"nested level 1",
new LoggingException( "nested level 2" ) ) ) );
logger.fatalError( "this is a fatal message from roger ramjet" );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
private static File getMavenRepositoryDirectory()
{
return new File( getMavenHomeDirectory(), "repository" );
}
private static File getMavenHomeDirectory()
{
return new File( getMavenHome() );
}
private static String getMavenHome()
{
try
{
String local =
System.getProperty(
"maven.home.local",
Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
if( null != local ) return local;
return System.getProperty( "user.home" ) + File.separator + ".maven";
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to access environment.";
final String message =
ExceptionHelper.packException( error, e, true );
throw new RuntimeException( message );
}
}
protected File getBaseDir()
{
return new File( System.getProperty( "basedir" ) );
}
}
1.1 avalon/logging/test/src/test/org/apache/avalon/logging/log4j/test/LoggingManagerHelper.java
Index: LoggingManagerHelper.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.logging.log4j.test;
import java.io.File;
import java.net.URL;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.logging.provider.LoggingManager;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.provider.Factory;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.provider.Builder;
import org.apache.avalon.repository.main.DefaultInitialContextFactory;
import org.apache.avalon.repository.main.DefaultBuilder;
import org.apache.avalon.util.env.Env;
import org.apache.avalon.util.exception.ExceptionHelper;
/**
*
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $
*/
public class LoggingManagerHelper
{
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
/**
* Setup the logging system.
* @param filename the name of a file in the test/conf directory
* @param bootstrap the boostrap logger logging level
* @return the logging manager
*/
public static LoggingManager setUpLoggingManager( String filename ) throws Exception
{
DefaultInitialContextFactory initial =
new DefaultInitialContextFactory( "avalon", getBaseDir() );
initial.setCacheDirectory( getMavenRepositoryDirectory() );
InitialContext context = initial.createInitialContext();
//
// FIX ME - remove hard reference (get from a property)
//
Artifact artifact = Artifact.createArtifact(
"avalon-logging", "avalon-log4j-impl", "1.0-SNAPSHOT" );
Builder builder = context.newBuilder( artifact );
Factory factory = builder.getFactory();
Map criteria = factory.createDefaultCriteria();
//
// customize the criteria
//
File basedir = getBaseDir();
File target = new File( basedir, "target" );
File conf = new File( basedir, "conf" );
File file = new File( conf, filename );
criteria.put( "avalon.logging.configuration", file );
criteria.put( "avalon.logging.basedir", target );
//
// create the logging manager
//
return (LoggingManager) factory.create( criteria );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
private static File getMavenRepositoryDirectory()
{
return new File( getMavenHomeDirectory(), "repository" );
}
private static File getMavenHomeDirectory()
{
return new File( getMavenHome() );
}
private static String getMavenHome()
{
try
{
String local =
System.getProperty(
"maven.home.local",
Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
if( null != local ) return local;
return System.getProperty( "user.home" ) + File.separator + ".maven";
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to access environment.";
final String message =
ExceptionHelper.packException( error, e, true );
throw new RuntimeException( message );
}
}
protected static File getBaseDir()
{
return new File( System.getProperty( "basedir" ) );
}
}
1.1 avalon/logging/test/src/test/org/apache/avalon/logging/logkit/test/DefaultLoggingManagerTestCase.java
Index: DefaultLoggingManagerTestCase.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.logging.logkit.test;
import java.io.File;
import java.net.URL;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.logging.provider.LoggingManager;
import org.apache.avalon.logging.provider.LoggingException;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.provider.Factory;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.provider.Builder;
import org.apache.avalon.repository.main.DefaultInitialContext;
import org.apache.avalon.repository.main.DefaultBuilder;
import org.apache.avalon.util.env.Env;
import org.apache.avalon.util.exception.ExceptionHelper;
/**
*
*
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $
*/
public class DefaultLoggingManagerTestCase extends TestCase
{
//-------------------------------------------------------------------
// state
//-------------------------------------------------------------------
InitialContext m_context;
LoggingManager m_manager;
//-------------------------------------------------------------------
// constructor
//-------------------------------------------------------------------
/**
* Constructor for DefaultInitialContextTest.
* @param name the test name
*/
public DefaultLoggingManagerTestCase( String name )
{
super( name );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
protected void setUp() throws Exception
{
m_manager = LoggingManagerHelper.setUpLoggingManager( "logkit/logging.xml" );
}
public void testKernelLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.logger" );
logger.debug( "this is a debug message from the kernel" );
logger.info( "this is a info message from the kernel" );
logger.warn( "this is a warning message from the kernel" );
logger.error(
"this is an error message from the kernel",
new LoggingException(
"Intentional Exception for TestCase.",
new LoggingException(
"This is not a problem.",
new LoggingException( "It is used to test the Logging framework." ) ) ) );
logger.fatalError( "If the TestCase does not fail, everything is OK." );
}
public void testKernelTestLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.logger.test" );
logger.debug( "this is a debug message from test" );
logger.info( "this is a info message from test" );
logger.warn( "this is a warning message from test" );
logger.error(
"this is an error message from test",
new LoggingException(
"woops",
new LoggingException(
"my fault",
new LoggingException( "bad attitude" ) ) ) );
logger.fatalError( "this is a fatal message from test" );
}
public void testRogerRamjetLogging() throws Exception
{
Logger logger = m_manager.getLoggerForCategory( "kernel.roger-ramjet" );
logger.debug( "this is a debug message from roger ramjet" );
logger.info( "this is a info message from roger ramjet" );
logger.warn( "this is a warning message from roger ramjet" );
logger.error(
"this is an error message from roger ramjet",
new LoggingException(
"woops",
new LoggingException(
"my fault",
new LoggingException( "bad attitude" ) ) ) );
logger.fatalError( "this is a fatal message from roger ramjet" );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
private static File getMavenRepositoryDirectory()
{
return new File( getMavenHomeDirectory(), "repository" );
}
private static File getMavenHomeDirectory()
{
return new File( getMavenHome() );
}
private static String getMavenHome()
{
try
{
String local =
System.getProperty(
"maven.home.local",
Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
if( null != local ) return local;
return System.getProperty( "user.home" ) + File.separator + ".maven";
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to access environment.";
final String message =
ExceptionHelper.packException( error, e, true );
throw new RuntimeException( message );
}
}
protected File getBaseDir()
{
return new File( System.getProperty( "basedir" ) );
}
}
1.1 avalon/logging/test/src/test/org/apache/avalon/logging/logkit/test/LoggingManagerHelper.java
Index: LoggingManagerHelper.java
===================================================================
/*
* Copyright 2004 Apache Software Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
* implied.
*
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.avalon.logging.logkit.test;
import java.io.File;
import java.net.URL;
import java.util.Map;
import junit.framework.TestCase;
import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.logging.provider.LoggingManager;
import org.apache.avalon.repository.Artifact;
import org.apache.avalon.repository.provider.Factory;
import org.apache.avalon.repository.provider.InitialContext;
import org.apache.avalon.repository.provider.Builder;
import org.apache.avalon.repository.main.DefaultInitialContextFactory;
import org.apache.avalon.repository.main.DefaultBuilder;
import org.apache.avalon.util.env.Env;
import org.apache.avalon.util.exception.ExceptionHelper;
/**
* @author <a href="mailto:dev@avalon.apache.org">Avalon Development Team</a>
* @version $Revision: 1.1 $
*/
public class LoggingManagerHelper
{
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
/**
* Setup the logging system.
* @param filename the name of a file in the test/conf directory
* @param bootstrap the boostrap logger logging level
* @return the logging manager
*/
public static LoggingManager setUpLoggingManager( String filename ) throws Exception
{
DefaultInitialContextFactory initial =
new DefaultInitialContextFactory( "avalon", getBaseDir() );
initial.setCacheDirectory( getMavenRepositoryDirectory() );
InitialContext context = initial.createInitialContext();
//
// FIX ME - remove hard reference (get from a property)
//
Artifact artifact = Artifact.createArtifact(
"avalon-logging", "avalon-logkit-impl", "1.0-SNAPSHOT" );
Builder builder = context.newBuilder( artifact );
Factory factory = builder.getFactory();
Map criteria = factory.createDefaultCriteria();
//
// customize the criteria
//
File basedir = getBaseDir();
File target = new File( basedir, "target" );
File conf = new File( basedir, "conf" );
File file = new File( conf, filename );
criteria.put( "avalon.logging.configuration", file );
criteria.put( "avalon.logging.basedir", target );
//
// create the logging manager
//
return (LoggingManager) factory.create( criteria );
}
//-------------------------------------------------------------------
// utilities
//-------------------------------------------------------------------
private static File getMavenRepositoryDirectory()
{
return new File( getMavenHomeDirectory(), "repository" );
}
private static File getMavenHomeDirectory()
{
return new File( getMavenHome() );
}
private static String getMavenHome()
{
try
{
String local =
System.getProperty(
"maven.home.local",
Env.getEnvVariable( "MAVEN_HOME_LOCAL" ) );
if( null != local ) return local;
return System.getProperty( "user.home" ) + File.separator + ".maven";
}
catch( Throwable e )
{
final String error =
"Internal error while attempting to access environment.";
final String message =
ExceptionHelper.packException( error, e, true );
throw new RuntimeException( message );
}
}
protected static File getBaseDir()
{
return new File( System.getProperty( "basedir" ) );
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org