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
Modifier and TypeClassDescriptionprotected static class
Default Nuxeo filter which takes a logger name and a log level to accept only events matching both.static interface
static @interface
static @interface
static class
static class
Log result class. -
Field Summary
Modifier and TypeFieldDescriptionprotected LogCaptureFeature.Filter
Filter defined on class.protected LogCaptureFeature.Filter
Filter used when appending a log toappender
.protected final org.apache.logging.log4j.core.Appender
A Log4jAppender
added toLoggerContext
at beginning of tests.protected LogCaptureFeature.Filter
Filter defined on method.protected final LogCaptureFeature.Result
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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 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 Log4jAppender
added toLoggerContext
at beginning of tests.
-
-
Constructor Details
-
LogCaptureFeature
public LogCaptureFeature()
-
-
Method Details
-
beforeRun
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
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
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
-