|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright 2002-2016 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 | + *      http://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.test.context.jdbc; | 
|  | 18 | + | 
|  | 19 | +import java.lang.annotation.Retention; | 
|  | 20 | + | 
|  | 21 | +import org.junit.Test; | 
|  | 22 | + | 
|  | 23 | +import org.springframework.core.annotation.AliasFor; | 
|  | 24 | +import org.springframework.test.annotation.DirtiesContext; | 
|  | 25 | +import org.springframework.test.context.ContextConfiguration; | 
|  | 26 | +import org.springframework.test.context.jdbc.Sql.ExecutionPhase; | 
|  | 27 | +import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; | 
|  | 28 | + | 
|  | 29 | +import static java.lang.annotation.RetentionPolicy.*; | 
|  | 30 | +import static org.junit.Assert.*; | 
|  | 31 | +import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.*; | 
|  | 32 | + | 
|  | 33 | +/** | 
|  | 34 | + * Integration tests that verify support for using {@link Sql @Sql} as a | 
|  | 35 | + * merged, composed annotation. | 
|  | 36 | + * | 
|  | 37 | + * @author Sam Brannen | 
|  | 38 | + * @since 4.3 | 
|  | 39 | + */ | 
|  | 40 | +@ContextConfiguration(classes = EmptyDatabaseConfig.class) | 
|  | 41 | +@DirtiesContext | 
|  | 42 | +public class ComposedAnnotationSqlScriptsTests extends AbstractTransactionalJUnit4SpringContextTests { | 
|  | 43 | + | 
|  | 44 | +	@Test | 
|  | 45 | +	@ComposedSql( | 
|  | 46 | +		scripts = { "drop-schema.sql", "schema.sql" }, | 
|  | 47 | +		statements = "INSERT INTO user VALUES('Dilbert')", | 
|  | 48 | +		executionPhase = BEFORE_TEST_METHOD | 
|  | 49 | +	) | 
|  | 50 | +	public void composedSqlAnnotation() { | 
|  | 51 | +		assertEquals("Number of rows in the 'user' table.", 1, countRowsInTable("user")); | 
|  | 52 | +	} | 
|  | 53 | + | 
|  | 54 | + | 
|  | 55 | +	@Sql | 
|  | 56 | +	@Retention(RUNTIME) | 
|  | 57 | +	@interface ComposedSql { | 
|  | 58 | + | 
|  | 59 | +		@AliasFor(annotation = Sql.class) | 
|  | 60 | +		String[] value() default {}; | 
|  | 61 | + | 
|  | 62 | +		@AliasFor(annotation = Sql.class) | 
|  | 63 | +		String[] scripts() default {}; | 
|  | 64 | + | 
|  | 65 | +		@AliasFor(annotation = Sql.class) | 
|  | 66 | +		String[] statements() default {}; | 
|  | 67 | + | 
|  | 68 | +		@AliasFor(annotation = Sql.class) | 
|  | 69 | +		ExecutionPhase executionPhase(); | 
|  | 70 | +	} | 
|  | 71 | + | 
|  | 72 | +} | 
0 commit comments