|
| 1 | +/* |
| 2 | + * Copyright 2012-2022 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.test.autoconfigure.data.elasticsearch; |
| 18 | + |
| 19 | +import java.lang.annotation.Documented; |
| 20 | +import java.lang.annotation.ElementType; |
| 21 | +import java.lang.annotation.Inherited; |
| 22 | +import java.lang.annotation.Retention; |
| 23 | +import java.lang.annotation.RetentionPolicy; |
| 24 | +import java.lang.annotation.Target; |
| 25 | + |
| 26 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 27 | + |
| 28 | +import org.springframework.boot.autoconfigure.ImportAutoConfiguration; |
| 29 | +import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 30 | +import org.springframework.boot.test.autoconfigure.OverrideAutoConfiguration; |
| 31 | +import org.springframework.boot.test.autoconfigure.core.AutoConfigureCache; |
| 32 | +import org.springframework.boot.test.autoconfigure.filter.TypeExcludeFilters; |
| 33 | +import org.springframework.context.annotation.ComponentScan.Filter; |
| 34 | +import org.springframework.core.annotation.AliasFor; |
| 35 | +import org.springframework.core.env.Environment; |
| 36 | +import org.springframework.test.context.BootstrapWith; |
| 37 | +import org.springframework.test.context.junit.jupiter.SpringExtension; |
| 38 | + |
| 39 | +/** |
| 40 | + * Annotation that can be used for a Data Elasticsearch test that focuses |
| 41 | + * <strong>only</strong> on Data Elasticsearch components. |
| 42 | + * <p> |
| 43 | + * Using this annotation will disable full auto-configuration and instead apply only |
| 44 | + * configuration relevant to Data Elasticsearch tests. |
| 45 | + * <p> |
| 46 | + * When using JUnit 4, this annotation should be used in combination with |
| 47 | + * {@code @RunWith(SpringRunner.class)}. |
| 48 | + * |
| 49 | + * @author Eddú Meléndez |
| 50 | + * @since 2.7.0 |
| 51 | + */ |
| 52 | +@Target(ElementType.TYPE) |
| 53 | +@Retention(RetentionPolicy.RUNTIME) |
| 54 | +@Documented |
| 55 | +@Inherited |
| 56 | +@BootstrapWith(DataElasticsearchTestContextBootstrapper.class) |
| 57 | +@ExtendWith(SpringExtension.class) |
| 58 | +@OverrideAutoConfiguration(enabled = false) |
| 59 | +@TypeExcludeFilters(DataElasticsearchTypeExcludeFilter.class) |
| 60 | +@AutoConfigureCache |
| 61 | +@AutoConfigureDataElasticsearch |
| 62 | +@ImportAutoConfiguration |
| 63 | +public @interface DataElasticsearchTest { |
| 64 | + |
| 65 | + /** |
| 66 | + * Properties in form {@literal key=value} that should be added to the Spring |
| 67 | + * {@link Environment} before the test runs. |
| 68 | + * @return the properties to add |
| 69 | + */ |
| 70 | + String[] properties() default {}; |
| 71 | + |
| 72 | + /** |
| 73 | + * Determines if default filtering should be used with |
| 74 | + * {@link SpringBootApplication @SpringBootApplication}. By default no beans are |
| 75 | + * included. |
| 76 | + * @see #includeFilters() |
| 77 | + * @see #excludeFilters() |
| 78 | + * @return if default filters should be used |
| 79 | + */ |
| 80 | + boolean useDefaultFilters() default true; |
| 81 | + |
| 82 | + /** |
| 83 | + * A set of include filters which can be used to add otherwise filtered beans to the |
| 84 | + * application context. |
| 85 | + * @return include filters to apply |
| 86 | + */ |
| 87 | + Filter[] includeFilters() default {}; |
| 88 | + |
| 89 | + /** |
| 90 | + * A set of exclude filters which can be used to filter beans that would otherwise be |
| 91 | + * added to the application context. |
| 92 | + * @return exclude filters to apply |
| 93 | + */ |
| 94 | + Filter[] excludeFilters() default {}; |
| 95 | + |
| 96 | + /** |
| 97 | + * Auto-configuration exclusions that should be applied for this test. |
| 98 | + * @return auto-configuration exclusions to apply |
| 99 | + */ |
| 100 | + @AliasFor(annotation = ImportAutoConfiguration.class, attribute = "exclude") |
| 101 | + Class<?>[] excludeAutoConfiguration() default {}; |
| 102 | + |
| 103 | +} |
0 commit comments