Return-Path: X-Original-To: apmail-logging-commits-archive@minotaur.apache.org Delivered-To: apmail-logging-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7A7E010494 for ; Wed, 26 Mar 2014 03:56:45 +0000 (UTC) Received: (qmail 2102 invoked by uid 500); 26 Mar 2014 03:56:45 -0000 Delivered-To: apmail-logging-commits-archive@logging.apache.org Received: (qmail 2068 invoked by uid 500); 26 Mar 2014 03:56:39 -0000 Mailing-List: contact commits-help@logging.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@logging.apache.org Delivered-To: mailing list commits@logging.apache.org Received: (qmail 2061 invoked by uid 99); 26 Mar 2014 03:56:38 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Mar 2014 03:56:38 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 26 Mar 2014 03:56:36 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 0391123889CB; Wed, 26 Mar 2014 03:56:15 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1581681 - in /logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit: ./ InitialLoggerContext.java Date: Wed, 26 Mar 2014 03:56:14 -0000 To: commits@logging.apache.org From: mattsicker@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20140326035615.0391123889CB@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: mattsicker Date: Wed Mar 26 03:56:14 2014 New Revision: 1581681 URL: http://svn.apache.org/r1581681 Log: Add InitialLoggerContext JUnit test rule. - Implements LOG4J2-497 in a more direct manner. - Will update some unit tests to demonstrate how to use this, too. Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java (with props) Added: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java URL: http://svn.apache.org/viewvc/logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java?rev=1581681&view=auto ============================================================================== --- logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java (added) +++ logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java Wed Mar 26 03:56:14 2014 @@ -0,0 +1,44 @@ +package org.apache.logging.log4j.junit; + +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configurator; +import org.junit.rules.TestRule; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * JUnit {@link TestRule} for constructing a new LoggerContext using a specified configuration file. + */ +public class InitialLoggerContext implements TestRule { + + private final String configLocation; + + private LoggerContext context; + + public InitialLoggerContext(String configLocation) { + this.configLocation = configLocation; + } + + @Override + public Statement apply(final Statement base, final Description description) { + return new Statement() { + @Override + public void evaluate() throws Throwable { + context = Configurator.initialize( + description.getDisplayName(), + description.getTestClass().getClassLoader(), + configLocation + ); + try { + base.evaluate(); + } finally { + Configurator.shutdown(context); + } + } + }; + } + + public LoggerContext getContext() { + return context; + } +} Propchange: logging/log4j/log4j2/trunk/log4j-core/src/test/java/org/apache/logging/log4j/junit/InitialLoggerContext.java ------------------------------------------------------------------------------ svn:eol-style = native