Skip to content

Commit b0c6357

Browse files
committed
Test @SQL as a merged composed annotation
Issue: SPR-13973
1 parent fc83933 commit b0c6357

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
}

spring-test/src/test/java/org/springframework/test/context/jdbc/MetaAnnotationSqlScriptsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -31,7 +31,7 @@
3131

3232
/**
3333
* Integration tests that verify support for using {@link Sql @Sql} and
34-
* {@link SqlGroup @SqlGroup} as a meta-annotations.
34+
* {@link SqlGroup @SqlGroup} as meta-annotations.
3535
*
3636
* @author Sam Brannen
3737
* @since 4.1

0 commit comments

Comments
 (0)