一部のデータベースコンテンツを変更するスポック/スプリングテストがあり、そのレコードをロールバックする方法を知りたいです。
現在、生のSQLステートメントを実行し、フィールドデータを保存し、テストが成功した後、そのデータを復元します。しかし、私の推測では、これはより簡単な方法で行うことができますか?
@ContextConfiguration(locations = "classpath*:applicationContext-test.xml")
class RepositoryTest extends Specification {
@Shared sql = Sql.newInstance("jdbc:sqlserver://...")
ResourceRepository resourceRepository;
def "Save test"() {
setup:
// copy the row before we do changes! we need to restore this later on!
def row = sql.firstRow("select id, content, status from table-name where id = 12345")
when:
...
then:
..
cleanup:
sql.execute("""
update table-name set content = ${row.content}, status = ${row.status}
where id = ${row.id}
""")
}
}