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.FilterOn
or a custom one implementingLogCaptureFeature.Filter
class can be provided with the annotationLogCaptureFeature.FilterWith
to select the log events to capture.A
LogCaptureFeature.Result
instance is to be injected withInject
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 Classes Modifier and Type Class Description protected static class
LogCaptureFeature.DefaultFilter
Default Nuxeo filter which takes a logger name and a log level to accept only events matching both.static interface
LogCaptureFeature.Filter
static interface
LogCaptureFeature.FilterOn
static interface
LogCaptureFeature.FilterWith
static class
LogCaptureFeature.NoLogCaptureFilterException
static class
LogCaptureFeature.Result
Log result class.
-
Field Summary
Fields Modifier and Type Field Description protected LogCaptureFeature.Filter
classFilter
Filter defined on class.protected LogCaptureFeature.Filter
currentFilter
Filter used when appending a log toappender
.protected org.apache.logging.log4j.core.Appender
logAppender
A Log4jAppender
added toLoggerContext
at beginning of tests.protected LogCaptureFeature.Filter
methodFilter
Filter defined on method.protected LogCaptureFeature.Result
myResult
-
Constructor Summary
Constructors Constructor Description LogCaptureFeature()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
afterMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test)
After a test method was ran.void
afterRun(FeaturesRunner runner)
After tests were run.void
beforeMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test)
Before a test method is invoked.void
beforeRun(FeaturesRunner runner)
Before running tests.void
configure(FeaturesRunner runner, com.google.inject.Binder binder)
Configures Guice bindings if any is required by the feature.protected LogCaptureFeature.Filter
instantiateFilter(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 Log4jAppender
added toLoggerContext
at beginning of tests.
-
-
Method Detail
-
beforeRun
public void beforeRun(FeaturesRunner runner) throws Exception
Description copied from interface:RunnerFeature
Before running tests. At this point Guice modules are registered and injector created.- Specified by:
beforeRun
in interfaceRunnerFeature
- Throws:
Exception
-
configure
public void configure(FeaturesRunner runner, com.google.inject.Binder binder)
Description copied from interface:RunnerFeature
Configures 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:
configure
in interfaceRunnerFeature
-
beforeMethodRun
public void beforeMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test) throws Exception
Description copied from interface:RunnerFeature
Before a test method is invoked.- Specified by:
beforeMethodRun
in interfaceRunnerFeature
- Throws:
Exception
-
afterMethodRun
public void afterMethodRun(FeaturesRunner runner, org.junit.runners.model.FrameworkMethod method, Object test)
Description copied from interface:RunnerFeature
After a test method was ran.- Specified by:
afterMethodRun
in interfaceRunnerFeature
-
afterRun
public void afterRun(FeaturesRunner runner)
Description copied from interface:RunnerFeature
After tests were run.- Specified by:
afterRun
in interfaceRunnerFeature
-
instantiateFilter
protected LogCaptureFeature.Filter instantiateFilter(Supplier<LogCaptureFeature.FilterWith> filterWith, Supplier<LogCaptureFeature.FilterOn> filterOn) throws Exception
- Throws:
Exception
-
-