001/* 002 * Copyright 2012-2018 the original author or authors. 003 * 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 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 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 */ 016 017package org.springframework.boot.test.autoconfigure.data.redis; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Inherited; 022import java.lang.annotation.Retention; 023import java.lang.annotation.RetentionPolicy; 024import java.lang.annotation.Target; 025 026import org.junit.jupiter.api.extension.ExtendWith; 027 028import org.springframework.boot.autoconfigure.ImportAutoConfiguration; 029import org.springframework.boot.autoconfigure.SpringBootApplication; 030import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; 031import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; 032import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; 033import org.springframework.context.annotation.ComponentScan.Filter; 034import org.springframework.core.annotation.AliasFor; 035import org.springframework.core.env.Environment; 036import org.springframework.test.context.BootstrapWith; 037import org.springframework.test.context.junit.jupiter.SpringExtension; 038 039/** 040 * Annotation that can be used in combination with {@code @RunWith(SpringRunner.class)} 041 * for a typical Data Redis test. Can be used when a test focuses <strong>only</strong> on 042 * Redis components. 043 * <p> 044 * Using this annotation will disable full auto-configuration and instead apply only 045 * configuration relevant to Redis tests. 046 * 047 * @author Jayaram Pradhan 048 * @author Artsiom Yudovin 049 * @since 2.0.0 050 */ 051@Target(ElementType.TYPE) 052@Retention(RetentionPolicy.RUNTIME) 053@Documented 054@Inherited 055@BootstrapWith(DataRedisTestContextBootstrapper.class) 056@ExtendWith(SpringExtension.class) 057@OverrideAutoConfiguration(enabled = false) 058@TypeExcludeFilters(DataRedisTypeExcludeFilter.class) 059@AutoConfigureCache 060@AutoConfigureDataRedis 061@ImportAutoConfiguration 062public @interface DataRedisTest { 063 064 /** 065 * Properties in form {@literal key=value} that should be added to the Spring 066 * {@link Environment} before the test runs. 067 * @return the properties to add 068 * @since 2.1.0 069 */ 070 String[] properties() default {}; 071 072 /** 073 * Determines if default filtering should be used with 074 * {@link SpringBootApplication @SpringBootApplication}. By default no beans are 075 * included. 076 * @see #includeFilters() 077 * @see #excludeFilters() 078 * @return if default filters should be used 079 */ 080 boolean useDefaultFilters() default true; 081 082 /** 083 * A set of include filters which can be used to add otherwise filtered beans to the 084 * application context. 085 * @return include filters to apply 086 */ 087 Filter[] includeFilters() default {}; 088 089 /** 090 * A set of exclude filters which can be used to filter beans that would otherwise be 091 * added to the application context. 092 * @return exclude filters to apply 093 */ 094 Filter[] excludeFilters() default {}; 095 096 /** 097 * Auto-configuration exclusions that should be applied for this test. 098 * @return auto-configuration exclusions to apply 099 */ 100 @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude") 101 Class<?>[] excludeAutoConfiguration() default {}; 102 103}