001/* 002 * Copyright 2023 the original author or authors. 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.test.juli.junit5; 017 018import static java.lang.annotation.ElementType.TYPE; 019import static java.lang.annotation.RetentionPolicy.RUNTIME; 020 021import java.lang.annotation.Documented; 022import java.lang.annotation.Retention; 023import java.lang.annotation.Target; 024import java.util.logging.Level; 025 026import org.junit.jupiter.api.extension.ExtendWith; 027 028import de.cuioss.test.juli.LogAsserts; 029import de.cuioss.test.juli.TestLogLevel; 030import de.cuioss.test.juli.TestLoggerFactory; 031 032/** 033 * Meta-annotation that allows test classes to be extended with 034 * {@link TestLoggerController} instead of using 035 * {@code @ExtendWith(TestLoggerController.class)}. 036 * <p> 037 * Used on a Junit 5 test this annotation ensures that the test-logger / 038 * assertion system is initialized properly, see 039 * {@link TestLoggerFactory#install()}, and 040 * {@link TestLoggerFactory#configureLogger()}, and the actual log-statements 041 * are cleared before each test. After all tests the test-logger is uninstalled 042 * again, see {@link TestLoggerFactory#uninstall()}. 043 * </p> 044 * <p> 045 * Use the annotations for specifying the log-level to be set for the concrete 046 * unit-tests. The level defined within this annotation will overwrite settings 047 * found either within {@link System#getProperty(String)} and 048 * "cui_logger.properties" 049 * </p> 050 * <p> 051 * Use {@link LogAsserts} to make assertions to logged data. 052 * </p> 053 * 054 * @author Oliver Wolff 055 * 056 */ 057@Documented 058@Retention(RUNTIME) 059@Target(TYPE) 060@ExtendWith(TestLoggerController.class) 061public @interface EnableTestLogger { 062 063 /** 064 * @return The {@link TestLogLevel} to be set before each test. It defaults to 065 * {@link TestLogLevel#INFO} 066 */ 067 TestLogLevel rootLevel() default TestLogLevel.INFO; 068 069 /** 070 * @return the types for which {@link TestLogLevel#TRACE} will be enabled, which 071 * implicitly maps to {@link Level#FINEST} 072 */ 073 Class<?>[] trace() default {}; 074 075 /** 076 * @return the types for which {@link TestLogLevel#DEBUG} will be enabled, which 077 * implicitly maps to {@link Level#FINE} 078 */ 079 Class<?>[] debug() default {}; 080 081 /** 082 * @return the types for which {@link TestLogLevel#INFO} will be enabled, which 083 * implicitly maps to {@link Level#INFO} 084 */ 085 Class<?>[] info() default {}; 086 087 /** 088 * @return the types for which {@link TestLogLevel#WARN} will be enabled, which 089 * implicitly maps to {@link Level#WARNING} 090 */ 091 Class<?>[] warn() default {}; 092 093 /** 094 * @return the types for which {@link TestLogLevel#ERROR} will be enabled, which 095 * implicitly maps to {@link Level#SEVERE} 096 */ 097 Class<?>[] error() default {}; 098}