001package de.cuioss.test.juli.junit5;
002
003import static java.lang.annotation.ElementType.TYPE;
004import static java.lang.annotation.RetentionPolicy.RUNTIME;
005
006import java.lang.annotation.Documented;
007import java.lang.annotation.Retention;
008import java.lang.annotation.Target;
009import java.util.logging.Level;
010
011import org.junit.jupiter.api.extension.ExtendWith;
012
013import de.cuioss.test.juli.LogAsserts;
014import de.cuioss.test.juli.TestLogLevel;
015import de.cuioss.test.juli.TestLoggerFactory;
016
017/**
018 * Meta-annotation that allows test classes to be extended with {@link TestLoggerController}
019 * instead of using {@code @ExtendWith(TestLoggerController.class)}.
020 * <p>
021 * Used on a Junit 5 test this annotation ensures that the test-logger / assertion system is
022 * initialized properly, see {@link TestLoggerFactory#install()}, and
023 * {@link TestLoggerFactory#configureLogger()}, and the actual log-statements are cleared
024 * before each test. After all tests the test-logger is uninstalled again, see
025 * {@link TestLoggerFactory#uninstall()}.
026 * </p>
027 * <p>
028 * Use the annotations for specifying the log-level to be set for the concrete unit-tests. The level
029 * defined within this annotation will overwrite settings found either within
030 * {@link System#getProperty(String)} and "cui_logger.properties"
031 * </p>
032 * <p>
033 * Use {@link LogAsserts} to make assertions to logged data.
034 * </p>
035 *
036 * @author Oliver Wolff
037 *
038 */
039@Documented
040@Retention(RUNTIME)
041@Target(TYPE)
042@ExtendWith(TestLoggerController.class)
043public @interface EnableTestLogger {
044
045    /**
046     * @return The {@link TestLogLevel} to be set before each test. It defaults to
047     *         {@link TestLogLevel#INFO}
048     */
049    TestLogLevel rootLevel() default TestLogLevel.INFO;
050
051    /**
052     * @return the types for which {@link TestLogLevel#TRACE} will be enabled, which implicitly maps
053     *         to {@link Level#FINEST}
054     */
055    Class<?>[] trace() default {};
056
057    /**
058     * @return the types for which {@link TestLogLevel#DEBUG} will be enabled, which implicitly maps
059     *         to {@link Level#FINE}
060     */
061    Class<?>[] debug() default {};
062
063    /**
064     * @return the types for which {@link TestLogLevel#INFO} will be enabled, which implicitly
065     *         maps to {@link Level#INFO}
066     */
067    Class<?>[] info() default {};
068
069    /**
070     * @return the types for which {@link TestLogLevel#WARN} will be enabled, which implicitly maps
071     *         to {@link Level#WARNING}
072     */
073    Class<?>[] warn() default {};
074
075    /**
076     * @return the types for which {@link TestLogLevel#ERROR} will be enabled, which implicitly maps
077     *         to {@link Level#SEVERE}
078     */
079    Class<?>[] error() default {};
080}