Package org.nuxeo.runtime.test.runner
Class LogCaptureFeature
java.lang.Object
org.nuxeo.runtime.test.runner.LogCaptureFeature
- All Implemented Interfaces:
RunnerFeature
Test feature to capture from a log4j appender to check that some log4j calls have been correctly called.
On a test class or a test method using this feature, a default filter can be configured with the annotation
LogCaptureFeature.FilterOn or a custom one implementing LogCaptureFeature.Filter class can be
provided with the annotation LogCaptureFeature.FilterWith to select the log events to capture.
A LogCaptureFeature.Result instance is to be injected with Inject as an attribute of the
test.
The method LogCaptureFeature.Result.assertHasEvent() can then be called from test methods to check that
matching log calls (events) have been captured.
- Since:
- 5.7
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classDefault Nuxeo filter which takes a logger name and a log level to accept only events matching both.static interfacestatic @interfacestatic @interfacestatic classstatic classLog result class. -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected LogCaptureFeature.FilterFilter defined on class.protected LogCaptureFeature.FilterFilter used when appending a log toappender.protected final org.apache.logging.log4j.core.AppenderA Log4jAppenderadded toLoggerContextat beginning of tests.protected LogCaptureFeature.FilterFilter defined on method.protected final LogCaptureFeature.Result -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test) After a test method was ran.voidafterRun(FeaturesRunner runner) After tests were run.voidbeforeMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test) Before a test method is invoked.voidbeforeRun(FeaturesRunner runner) Before running tests.voidconfigure(FeaturesRunner runner, com.google.inject.Binder binder) Configures Guice bindings if any is required by the feature.protected LogCaptureFeature.FilterinstantiateFilter(Supplier<LogCaptureFeature.FilterWith> filterWith, Supplier<LogCaptureFeature.FilterOn> filterOn) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.nuxeo.runtime.test.runner.RunnerFeature
afterTeardown, afterTeardown, beforeSetup, beforeSetup, initialize, start, stop, testCreated
-
Field Details
-
classFilter
Filter defined on class. -
methodFilter
Filter defined on method. -
currentFilter
Filter used when appending a log toappender. -
myResult
-
logAppender
protected final org.apache.logging.log4j.core.Appender logAppenderA Log4jAppenderadded toLoggerContextat beginning of tests.
-
-
Constructor Details
-
LogCaptureFeature
public LogCaptureFeature()
-
-
Method Details
-
beforeRun
Description copied from interface:RunnerFeatureBefore running tests. At this point Guice modules are registered and injector created.- Specified by:
beforeRunin interfaceRunnerFeature- Throws:
Exception
-
configure
Description copied from interface:RunnerFeatureConfigures Guice bindings if any is required by the feature. This is called after the framework is started and before Guice module is built. The tests are launched after guice module is built.- Specified by:
configurein interfaceRunnerFeature
-
beforeMethodRun
public void beforeMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test) throws Exception Description copied from interface:RunnerFeatureBefore a test method is invoked.- Specified by:
beforeMethodRunin interfaceRunnerFeature- Throws:
Exception
-
afterMethodRun
public void afterMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test) Description copied from interface:RunnerFeatureAfter a test method was ran.- Specified by:
afterMethodRunin interfaceRunnerFeature
-
afterRun
Description copied from interface:RunnerFeatureAfter tests were run.- Specified by:
afterRunin interfaceRunnerFeature
-
instantiateFilter
protected LogCaptureFeature.Filter instantiateFilter(Supplier<LogCaptureFeature.FilterWith> filterWith, Supplier<LogCaptureFeature.FilterOn> filterOn) throws Exception - Throws:
Exception
-