Package org.nuxeo.runtime.test.runner
Class LogCaptureFeature
- java.lang.Object
-
- org.nuxeo.runtime.test.runner.LogCaptureFeature
-
- All Implemented Interfaces:
RunnerFeature
public class LogCaptureFeature extends Object implements 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.FilterOnor a custom one implementingLogCaptureFeature.Filterclass can be provided with the annotationLogCaptureFeature.FilterWithto select the log events to capture.A
LogCaptureFeature.Resultinstance is to be injected withInjectas 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 Classes Modifier and Type Class Description protected static classLogCaptureFeature.DefaultFilterDefault Nuxeo filter which takes a logger name and a log level to accept only events matching both.static interfaceLogCaptureFeature.Filterstatic interfaceLogCaptureFeature.FilterOnstatic interfaceLogCaptureFeature.FilterWithstatic classLogCaptureFeature.NoLogCaptureFilterExceptionstatic classLogCaptureFeature.ResultLog result class.
-
Field Summary
Fields Modifier and Type Field Description protected LogCaptureFeature.FilterclassFilterFilter defined on class.protected LogCaptureFeature.FiltercurrentFilterFilter used when appending a log toappender.protected org.apache.logging.log4j.core.AppenderlogAppenderA Log4jAppenderadded toLoggerContextat beginning of tests.protected LogCaptureFeature.FiltermethodFilterFilter defined on method.protected LogCaptureFeature.ResultmyResult
-
Constructor Summary
Constructors Constructor Description LogCaptureFeature()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterMethodRun(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, wait
-
Methods inherited from interface org.nuxeo.runtime.test.runner.RunnerFeature
afterTeardown, afterTeardown, beforeSetup, beforeSetup, initialize, start, stop, testCreated
-
-
-
-
Field Detail
-
classFilter
protected LogCaptureFeature.Filter classFilter
Filter defined on class.
-
methodFilter
protected LogCaptureFeature.Filter methodFilter
Filter defined on method.
-
currentFilter
protected volatile LogCaptureFeature.Filter currentFilter
Filter used when appending a log toappender.
-
myResult
protected final LogCaptureFeature.Result myResult
-
logAppender
protected final org.apache.logging.log4j.core.Appender logAppender
A Log4jAppenderadded toLoggerContextat beginning of tests.
-
-
Method Detail
-
beforeRun
public void beforeRun(FeaturesRunner runner) throws Exception
Description copied from interface:RunnerFeatureBefore running tests. At this point Guice modules are registered and injector created.- Specified by:
beforeRunin interfaceRunnerFeature- Throws:
Exception
-
configure
public void configure(FeaturesRunner runner, com.google.inject.Binder binder)
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
public void afterRun(FeaturesRunner runner)
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
-
-