001/* 002 * Copyright 2012-2017 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.properties; 018 019import java.lang.annotation.Documented; 020import java.lang.annotation.ElementType; 021import java.lang.annotation.Retention; 022import java.lang.annotation.RetentionPolicy; 023import java.lang.annotation.Target; 024 025import org.springframework.context.annotation.PropertySource; 026import org.springframework.test.context.TestPropertySource; 027 028/** 029 * Indicates that attributes from a test annotation should be mapped into a 030 * {@link PropertySource}. Can be used at the type level, or on individual attributes. For 031 * example, the following annotation declaration: <pre class="code"> 032 * @Retention(RUNTIME) 033 * @PropertyMapping("my.example") 034 * public @interface Example { 035 * 036 * String name(); 037 * 038 * } 039 * </pre> When used on a test class as follows: <pre class="code"> 040 * @Example(name="Spring") 041 * public class MyTest { 042 * } 043 * </pre> will result in a {@literal my.example.name} property being added with the value 044 * {@literal "Spring"}. 045 * <p> 046 * 047 * @author Phillip Webb 048 * @since 1.4.0 049 * @see AnnotationsPropertySource 050 * @see TestPropertySource 051 */ 052@Retention(RetentionPolicy.RUNTIME) 053@Target({ ElementType.TYPE, ElementType.METHOD }) 054@Documented 055public @interface PropertyMapping { 056 057 /** 058 * Defines the property mapping. When used at the type-level, this value will be used 059 * as a prefix for all mapped attributes. When used on an attribute, the value 060 * overrides the generated (kebab case) name. 061 * @return the property mapping 062 */ 063 String value() default ""; 064 065 /** 066 * Determines if mapping should be skipped. When specified at the type-level indicates 067 * if skipping should occur by default or not. When used at the attribute-level, 068 * overrides the type-level default. 069 * @return if mapping should be skipped 070 */ 071 SkipPropertyMapping skip() default SkipPropertyMapping.NO; 072 073}