Search in sources :

Example 11 with LoggingListener

use of org.elasticsearch.test.junit.listeners.LoggingListener in project crate by crate.

the class LoggingListenerTests method testCustomLevelPerClassAndPerMethod.

public void testCustomLevelPerClassAndPerMethod() throws Exception {
    LoggingListener loggingListener = new LoggingListener();
    Description suiteDescription = Description.createSuiteDescription(AnnotatedTestClass.class);
    Logger abcLogger = LogManager.getLogger("abc");
    Logger xyzLogger = LogManager.getLogger("xyz");
    final Level level = LogManager.getRootLogger().getLevel();
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
    loggingListener.testRunStarted(suiteDescription);
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
    Method method = TestClass.class.getMethod("annotatedTestMethod");
    TestLogging annotation = method.getAnnotation(TestLogging.class);
    Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation);
    loggingListener.testStarted(testDescription);
    assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE));
    assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
    loggingListener.testFinished(testDescription);
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
    Method method2 = TestClass.class.getMethod("annotatedTestMethod2");
    TestLogging annotation2 = method2.getAnnotation(TestLogging.class);
    Description testDescription2 = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod2", annotation2);
    loggingListener.testStarted(testDescription2);
    assertThat(xyzLogger.getLevel(), equalTo(Level.DEBUG));
    assertThat(abcLogger.getLevel(), equalTo(Level.TRACE));
    loggingListener.testFinished(testDescription2);
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(Level.WARN));
    loggingListener.testRunFinished(new Result());
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
}
Also used : Description(org.junit.runner.Description) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) LoggingListener(org.elasticsearch.test.junit.listeners.LoggingListener) Level(org.apache.logging.log4j.Level) Method(java.lang.reflect.Method) Logger(org.apache.logging.log4j.Logger) Result(org.junit.runner.Result)

Example 12 with LoggingListener

use of org.elasticsearch.test.junit.listeners.LoggingListener in project crate by crate.

the class LoggingListenerTests method testCustomLevelPerMethod.

public void testCustomLevelPerMethod() throws Exception {
    LoggingListener loggingListener = new LoggingListener();
    Description suiteDescription = Description.createSuiteDescription(TestClass.class);
    Logger xyzLogger = LogManager.getLogger("xyz");
    Logger abcLogger = LogManager.getLogger("abc");
    final Level level = LogManager.getRootLogger().getLevel();
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
    loggingListener.testRunStarted(suiteDescription);
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
    Method method = TestClass.class.getMethod("annotatedTestMethod");
    TestLogging annotation = method.getAnnotation(TestLogging.class);
    Description testDescription = Description.createTestDescription(LoggingListenerTests.class, "annotatedTestMethod", annotation);
    loggingListener.testStarted(testDescription);
    assertThat(xyzLogger.getLevel(), equalTo(Level.TRACE));
    assertThat(abcLogger.getLevel(), equalTo(level));
    loggingListener.testFinished(testDescription);
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
    loggingListener.testRunFinished(new Result());
    assertThat(xyzLogger.getLevel(), equalTo(level));
    assertThat(abcLogger.getLevel(), equalTo(level));
}
Also used : Description(org.junit.runner.Description) TestLogging(org.elasticsearch.test.junit.annotations.TestLogging) LoggingListener(org.elasticsearch.test.junit.listeners.LoggingListener) Level(org.apache.logging.log4j.Level) Method(java.lang.reflect.Method) Logger(org.apache.logging.log4j.Logger) Result(org.junit.runner.Result)

Aggregations

LoggingListener (org.elasticsearch.test.junit.listeners.LoggingListener)12 Description (org.junit.runner.Description)12 Method (java.lang.reflect.Method)6 Level (org.apache.logging.log4j.Level)6 Logger (org.apache.logging.log4j.Logger)6 TestLogging (org.elasticsearch.test.junit.annotations.TestLogging)6 Result (org.junit.runner.Result)6