Skip to content

Commit 631edf5

Browse files
nlanghjurausch
authored andcommitted
fix: otp-1787: migrate from junit assume to spock IgnoreIf and use temporaryFolder annotation for workflows tests
1 parent dafb6dd commit 631edf5

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

src/workflow-test/groovy/de/dkfz/tbi/otp/analysis/pair/roddy/AbstractRoddyBamFilePairAnalysisWorkflowTests.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
*/
2222
package de.dkfz.tbi.otp.analysis.pair.roddy
2323

24-
import org.junit.Assume
24+
import spock.lang.IgnoreIf
2525
import spock.lang.Shared
2626

2727
import de.dkfz.tbi.otp.analysis.pair.AbstractBamFilePairAnalysisWorkflowTests
@@ -51,9 +51,9 @@ abstract class AbstractRoddyBamFilePairAnalysisWorkflowTests<Instance extends Ba
5151
createConfig()
5252
}
5353

54+
@IgnoreIf({ instance.ignoreRoddyBamFileTest })
5455
void "testWholeWorkflowWithRoddyBamFile"() {
5556
given:
56-
Assume.assumeFalse(ignoreRoddyBamFileTest)
5757
SessionUtils.withTransaction {
5858
setupRoddyBamFile()
5959
setupData()
@@ -66,9 +66,9 @@ abstract class AbstractRoddyBamFilePairAnalysisWorkflowTests<Instance extends Ba
6666
checkInstance()
6767
}
6868

69+
@IgnoreIf({ instance.ignoreExternalBamFileTest })
6970
void "testWholeWorkflowWithExternalBamFile"() {
7071
given:
71-
Assume.assumeFalse(ignoreExternalBamFileTest)
7272
SessionUtils.withTransaction {
7373
setupExternalBamFile()
7474
setupData()

src/workflow-test/groovy/de/dkfz/tbi/otp/workflowTest/AbstractWorkflowSpec.groovy

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ import grails.util.Holders
2626
import groovy.json.JsonOutput
2727
import groovy.sql.Sql
2828
import groovy.transform.TupleConstructor
29-
import org.junit.Rule
30-
import org.junit.rules.TemporaryFolder
31-
import org.junit.rules.TestName
3229
import org.slf4j.Logger
3330
import org.slf4j.LoggerFactory
3431
import spock.lang.Specification
32+
import spock.lang.TempDir
3533

3634
import de.dkfz.roddy.BEException
3735
import de.dkfz.roddy.execution.jobs.*
@@ -55,7 +53,9 @@ import de.dkfz.tbi.otp.workflowExecution.log.WorkflowError
5553
import de.dkfz.tbi.otp.workflowExecution.log.WorkflowLog
5654
import de.dkfz.tbi.util.TimeFormats
5755

56+
import javax.inject.Inject
5857
import javax.sql.DataSource
58+
import java.lang.reflect.Method
5959
import java.nio.file.*
6060
import java.nio.file.attribute.PosixFilePermission
6161
import java.time.Duration
@@ -108,14 +108,8 @@ abstract class AbstractWorkflowSpec extends Specification implements UserAndRole
108108
/**
109109
* Needed to save the place of the database dump afterwards.
110110
*/
111-
@Rule
112-
TemporaryFolder temporaryFolder
113-
114-
/**
115-
* Allow the access of the current test method name
116-
*/
117-
@Rule
118-
TestName methodName
111+
@TempDir
112+
Path tempDir
119113

120114
/**
121115
* holds the remote file system
@@ -221,10 +215,10 @@ abstract class AbstractWorkflowSpec extends Specification implements UserAndRole
221215

222216
@SuppressWarnings("CatchThrowable")
223217
void setup() {
224-
log.debug("Start to setup ${getClass().simpleName}.${methodName.methodName}")
218+
log.debug("Start to setup ${getClass().simpleName}.${specificationContext.currentIteration.name}")
225219
SessionUtils.withTransaction {
226220
sql = new Sql(dataSource)
227-
schemaDump = new File(temporaryFolder.newFolder(), "test-database-dump.sql")
221+
schemaDump = tempDir.resolve("test-database-dump.sql").toFile()
228222
sql.execute("SCRIPT NODATA DROP TO ?", [schemaDump.absolutePath])
229223
log.debug("database dump written to ${schemaDump}")
230224

@@ -247,9 +241,10 @@ abstract class AbstractWorkflowSpec extends Specification implements UserAndRole
247241

248242
@SuppressWarnings("CatchThrowable")
249243
void cleanup() {
244+
String methodName = specificationContext.currentIteration.name
250245
try {
251246
log.info("--------------------------------------------------")
252-
log.info("Starting cleanup after test '${getClass().simpleName}.${methodName.methodName}' for base directory: ${workingDirectory}")
247+
log.info("Starting cleanup after test '${getClass().simpleName}.${methodName}' for base directory: ${workingDirectory}")
253248

254249
workflowSystemService.stopWorkflowSystem()
255250

@@ -272,7 +267,7 @@ abstract class AbstractWorkflowSpec extends Specification implements UserAndRole
272267
sql.execute("DROP ALL OBJECTS")
273268
sql.execute("RUNSCRIPT FROM ?", [schemaDump.absolutePath])
274269

275-
log.info "Finish test '${getClass().simpleName}.${methodName.methodName}' using base directory: ${workingDirectory}"
270+
log.info "Finish test '${getClass().simpleName}.${methodName}' using base directory: ${workingDirectory}"
276271
} catch (Throwable t) {
277272
//exception in cleanup was not reported with stacktrace, therefore add own logging
278273
log.error("cleanup error", t)

0 commit comments

Comments
 (0)