Skip to content

Commit 332de60

Browse files
committed
Update @⁠Sql docs regarding Kotlin and Java 8
1 parent 769128a commit 332de60

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

framework-docs/modules/ROOT/pages/testing/testcontext-framework/executing-sql.adoc

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -179,12 +179,11 @@ script, depending on where `@Sql` is declared. If a default cannot be detected,
179179

180180
If you need to configure multiple sets of SQL scripts for a given test class or test
181181
method but with different syntax configuration, different error handling rules, or
182-
different execution phases per set, you can declare multiple instances of `@Sql`. With
183-
Java 8, you can use `@Sql` as a repeatable annotation. Otherwise, you can use the
184-
`@SqlGroup` annotation as an explicit container for declaring multiple instances of
185-
`@Sql`.
182+
different execution phases per set, you can declare multiple instances of `@Sql`. You can
183+
either use `@Sql` as a repeatable annotation, or you can use the `@SqlGroup` annotation
184+
as an explicit container for declaring multiple instances of `@Sql`.
186185

187-
The following example shows how to use `@Sql` as a repeatable annotation with Java 8:
186+
The following example shows how to use `@Sql` as a repeatable annotation:
188187

189188
[tabs]
190189
======
@@ -204,17 +203,21 @@ Kotlin::
204203
+
205204
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
206205
----
207-
// Repeatable annotations with non-SOURCE retention are not yet supported by Kotlin
206+
@Test
207+
@Sql("/test-schema.sql", config = SqlConfig(commentPrefix = "`"))
208+
@Sql("/test-user-data.sql")
209+
fun userTest() {
210+
// run code that uses the test schema and test data
211+
}
208212
----
209213
======
210214

211215
In the scenario presented in the preceding example, the `test-schema.sql` script uses a
212216
different syntax for single-line comments.
213217

214218
The following example is identical to the preceding example, except that the `@Sql`
215-
declarations are grouped together within `@SqlGroup`. With Java 8 and above, the use of
216-
`@SqlGroup` is optional, but you may need to use `@SqlGroup` for compatibility with
217-
other JVM languages such as Kotlin.
219+
declarations are grouped together within `@SqlGroup`. The use of `@SqlGroup` is optional,
220+
but you may need to use `@SqlGroup` for compatibility with other JVM languages.
218221

219222
[tabs]
220223
======
@@ -239,7 +242,8 @@ Kotlin::
239242
@Test
240243
@SqlGroup(
241244
Sql("/test-schema.sql", config = SqlConfig(commentPrefix = "`")),
242-
Sql("/test-user-data.sql"))
245+
Sql("/test-user-data.sql")
246+
)
243247
fun userTest() {
244248
// Run code that uses the test schema and test data
245249
}
@@ -249,10 +253,10 @@ Kotlin::
249253
[[testcontext-executing-sql-declaratively-script-execution-phases]]
250254
=== Script Execution Phases
251255

252-
By default, SQL scripts are run before the corresponding test method. However, if
253-
you need to run a particular set of scripts after the test method (for example, to clean
254-
up database state), you can use the `executionPhase` attribute in `@Sql`, as the
255-
following example shows:
256+
By default, SQL scripts are run before the corresponding test method. However, if you
257+
need to run a particular set of scripts after the test method (for example, to clean up
258+
database state), you can set the `executionPhase` attribute in `@Sql` to
259+
`AFTER_TEST_METHOD`, as the following example shows:
256260

257261
[tabs]
258262
======
@@ -281,20 +285,19 @@ Kotlin::
281285
[source,kotlin,indent=0,subs="verbatim,quotes",role="secondary"]
282286
----
283287
@Test
284-
@SqlGroup(
285-
Sql("create-test-data.sql",
286-
config = SqlConfig(transactionMode = ISOLATED)),
287-
Sql("delete-test-data.sql",
288-
config = SqlConfig(transactionMode = ISOLATED),
289-
executionPhase = AFTER_TEST_METHOD))
288+
@Sql("create-test-data.sql",
289+
config = SqlConfig(transactionMode = ISOLATED))
290+
@Sql("delete-test-data.sql",
291+
config = SqlConfig(transactionMode = ISOLATED),
292+
executionPhase = AFTER_TEST_METHOD)
290293
fun userTest() {
291294
// run code that needs the test data to be committed
292295
// to the database outside of the test's transaction
293296
}
294297
----
295298
======
296299

297-
Note that `ISOLATED` and `AFTER_TEST_METHOD` are statically imported from
300+
NOTE: `ISOLATED` and `AFTER_TEST_METHOD` are statically imported from
298301
`Sql.TransactionMode` and `Sql.ExecutionPhase`, respectively.
299302

300303
[[testcontext-executing-sql-declaratively-script-configuration]]

0 commit comments

Comments
 (0)