Package org.opennms.core.test
Class MockLogAppender
- java.lang.Object
-
- org.opennms.core.test.MockLogAppender
-
public abstract class MockLogAppender extends java.lang.Object
MockLogAppender class. If you do not specify the log level specifically, the level will default to DEBUG. You can control the level by using the
Used in unit tests to check that the level of logging produced by a test was suitable. In some cases, the test will be that no messages were logged at a higher priority than specified, e.g. Error messages logged when only Notice were expected. Some other tests may wish to ensure that an Error or Warn message was indeed logged as expected Remember: "Greater" in regards to level relates to priority; the higher the level, the less should usually be logged (e.g. Errors (highest) should be only the highest priority messages about really bad things, as compared to Debug (lowest) which is any old rubbish that might be interesting to a developer)setupLogging(boolean, String)
orsetupLogging(boolean, String, Properties)
methods.- Version:
- $Id: $
- Author:
- brozow
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
DEFAULT_LOG_LEVEL
-
Constructor Summary
Constructors Constructor Description MockLogAppender()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addEvent(LoggingEvent loggingEvent)
static void
assertLogAtLevel(Level level)
assertLogAtLevelstatic void
assertLogMatched(Level level, java.lang.String message)
static void
assertNoErrorOrGreater()
static void
assertNoFatalOrGreater()
static void
assertNoLogging()
static void
assertNoLogMatched(Level level, java.lang.String message)
static void
assertNotGreaterOrEqual(Level level)
assertNotGreaterOrEqualstatic void
assertNoWarningsOrGreater()
assertNoWarningsOrGreaterstatic LoggingEvent[]
getEvents()
getEventsstatic LoggingEvent[]
getEventsAtLevel(Level level)
getEventsAtLevelstatic LoggingEvent[]
getEventsGreaterOrEqual(Level level)
getEventsGreaterOrEqualstatic boolean
noWarningsOrHigherLogged()
noWarningsOrHigherLoggedstatic void
resetState()
resetEventsstatic void
setupLogging()
setupLoggingstatic void
setupLogging(boolean toConsole)
setupLoggingstatic void
setupLogging(boolean toConsole, java.lang.String level)
setupLoggingstatic void
setupLogging(boolean toConsole, java.lang.String level, java.util.Properties config)
setupLoggingstatic void
setupLogging(boolean toConsole, java.util.Properties props)
setupLoggingstatic void
setupLogging(java.util.Properties config)
setupLogging
-
-
-
Method Detail
-
resetState
public static void resetState()
resetEvents
-
getEvents
public static LoggingEvent[] getEvents()
getEvents
-
getEventsGreaterOrEqual
public static LoggingEvent[] getEventsGreaterOrEqual(Level level)
getEventsGreaterOrEqual
-
getEventsAtLevel
public static LoggingEvent[] getEventsAtLevel(Level level)
getEventsAtLevel
Returns events that were logged at the specified level
-
setupLogging
public static void setupLogging()
setupLogging
-
setupLogging
public static void setupLogging(java.util.Properties config)
setupLogging
- Parameters:
config
- aProperties
object.
-
setupLogging
public static void setupLogging(boolean toConsole)
setupLogging
- Parameters:
toConsole
- a boolean.
-
setupLogging
public static void setupLogging(boolean toConsole, java.util.Properties props)
setupLogging
- Parameters:
toConsole
- a boolean.props
- aProperties
object.
-
setupLogging
public static void setupLogging(boolean toConsole, java.lang.String level)
setupLogging
- Parameters:
toConsole
- a boolean.level
- aString
object.
-
setupLogging
public static void setupLogging(boolean toConsole, java.lang.String level, java.util.Properties config)
setupLogging
- Parameters:
toConsole
- a boolean.level
- aString
object.config
- aProperties
object.
-
noWarningsOrHigherLogged
public static boolean noWarningsOrHigherLogged()
noWarningsOrHigherLogged
- Returns:
- a boolean.
-
assertNotGreaterOrEqual
public static void assertNotGreaterOrEqual(Level level) throws junit.framework.AssertionFailedError
assertNotGreaterOrEqual
- Throws:
junit.framework.AssertionFailedError
- if any.
-
assertNoWarningsOrGreater
public static void assertNoWarningsOrGreater() throws junit.framework.AssertionFailedError
assertNoWarningsOrGreater
- Throws:
junit.framework.AssertionFailedError
- if any.
-
assertNoErrorOrGreater
public static void assertNoErrorOrGreater() throws junit.framework.AssertionFailedError
- Throws:
junit.framework.AssertionFailedError
-
assertNoFatalOrGreater
public static void assertNoFatalOrGreater() throws junit.framework.AssertionFailedError
- Throws:
junit.framework.AssertionFailedError
-
assertLogAtLevel
public static void assertLogAtLevel(Level level) throws junit.framework.AssertionFailedError
assertLogAtLevel
Asserts that a message was logged at the requested level. Useful for testing code that *should* have logged an error message (or a notice or some other special case)- Throws:
junit.framework.AssertionFailedError
- if any.
-
addEvent
public static void addEvent(LoggingEvent loggingEvent)
-
assertNoLogging
public static void assertNoLogging() throws junit.framework.AssertionFailedError
- Throws:
junit.framework.AssertionFailedError
-
assertLogMatched
public static void assertLogMatched(Level level, java.lang.String message)
-
assertNoLogMatched
public static void assertNoLogMatched(Level level, java.lang.String message)
-
-