From 28d338877e217289a2a0baeb1844ad42af9960b9 Mon Sep 17 00:00:00 2001 From: Thomas Sievert Date: Fri, 21 Jun 2024 11:40:30 +0200 Subject: [PATCH] add option to configure pre- and post-testtasks per test --- .../squit/config/ConfigExtensions.kt | 34 ++++- .../squit/task/SquitPostTestTask.kt | 5 + .../squit/task/SquitPreTestTask.kt | 5 + .../squit/task/SquitRequestTask.kt | 67 ++++++--- .../squit/config/ConfigExtensionsTest.kt | 32 +++++ .../SquitRequestTaskConfigurableTasksTest.kt | 127 ++++++++++++++++++ .../test-project-task-config/build.gradle | 8 ++ .../test-project-task-config/settings.gradle | 1 + .../project/configured_order/request.xml | 6 + .../project/configured_order/response.xml | 3 + .../squit/project/configured_order/test.conf | 2 + .../project/configured_order/test_post.sql | 1 + .../project/configured_order/test_pre.sql | 8 ++ .../src/squit/project/default/request.xml | 6 + .../src/squit/project/default/response.xml | 3 + .../src/squit/project/default/test_post.sql | 1 + .../src/squit/project/default/test_pre.sql | 8 ++ .../project/only_pre_db_script/request.xml | 6 + .../project/only_pre_db_script/response.xml | 3 + .../project/only_pre_db_script/test.conf | 2 + .../project/only_pre_db_script/test_post.sql | 1 + .../project/only_pre_db_script/test_pre.sql | 8 ++ .../src/squit/project/post_run.groovy | 5 + .../src/squit/project/pre_run.groovy | 5 + .../src/squit/project/test.conf | 9 ++ 25 files changed, 337 insertions(+), 19 deletions(-) create mode 100644 src/main/kotlin/de/smartsquare/squit/task/SquitPostTestTask.kt create mode 100644 src/main/kotlin/de/smartsquare/squit/task/SquitPreTestTask.kt create mode 100644 src/test/kotlin/de/smartsquare/squit/task/SquitRequestTaskConfigurableTasksTest.kt create mode 100644 src/test/resources/test-project-task-config/build.gradle create mode 100644 src/test/resources/test-project-task-config/settings.gradle create mode 100644 src/test/resources/test-project-task-config/src/squit/project/configured_order/request.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/configured_order/response.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/configured_order/test.conf create mode 100644 src/test/resources/test-project-task-config/src/squit/project/configured_order/test_post.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/configured_order/test_pre.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/default/request.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/default/response.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/default/test_post.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/default/test_pre.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/request.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/response.xml create mode 100644 src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test.conf create mode 100644 src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_post.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_pre.sql create mode 100644 src/test/resources/test-project-task-config/src/squit/project/post_run.groovy create mode 100644 src/test/resources/test-project-task-config/src/squit/project/pre_run.groovy create mode 100644 src/test/resources/test-project-task-config/src/squit/project/test.conf diff --git a/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt b/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt index 34c00355..87a576d6 100644 --- a/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt +++ b/src/main/kotlin/de/smartsquare/squit/config/ConfigExtensions.kt @@ -8,6 +8,8 @@ import com.typesafe.config.ConfigRenderOptions import com.typesafe.config.ConfigValueFactory import de.smartsquare.squit.entity.SquitDatabaseConfiguration import de.smartsquare.squit.io.FilesUtils +import de.smartsquare.squit.task.SquitPostTestTask +import de.smartsquare.squit.task.SquitPreTestTask import okhttp3.HttpUrl import okhttp3.HttpUrl.Companion.toHttpUrlOrNull import okhttp3.MediaType.Companion.toMediaTypeOrNull @@ -29,10 +31,12 @@ private const val PRE_PROCESSORS = "preProcessors" private const val PRE_PROCESSOR_SCRIPTS = "preProcessorScripts" private const val PRE_RUNNERS = "preRunners" private const val PRE_RUN_SCRIPTS = "preRunnerScripts" +private const val PRE_TEST_TASKS = "preTestTasks" private const val POST_PROCESSORS = "postProcessors" private const val POST_PROCESSOR_SCRIPTS = "postProcessorScripts" private const val POST_RUNNERS = "postRunners" private const val POST_RUN_SCRIPTS = "postRunnerScripts" +private const val POST_TEST_TASKS = "postTestTasks" private const val TAGS = "tags" private const val DATABASE_CONFIGURATIONS = "databaseConfigurations" private const val DATABASE_CONFIGURATION_NAME = "name" @@ -104,6 +108,20 @@ val Config.preRunners get() = getSafeStringList(PRE_RUNNERS) */ val Config.preRunnerScripts get() = getSafePathList(PRE_RUN_SCRIPTS) +/** + * preTestTasks to execute. + * default: PRE_RUNNERS, PRE_RUNNER_SCRIPTS, DATABASE_SCRIPTS + */ +val Config.preTestTasks get() = + when (hasPath(PRE_TEST_TASKS)) { + true -> getEnumList(SquitPreTestTask::class.java, PRE_TEST_TASKS)!! + else -> listOf( + SquitPreTestTask.PRE_RUNNERS, + SquitPreTestTask.PRE_RUNNER_SCRIPTS, + SquitPreTestTask.DATABASE_SCRIPTS + ) + } + /** * List of post-processors to use. */ @@ -124,6 +142,20 @@ val Config.postRunners get() = getSafeStringList(POST_RUNNERS) */ val Config.postRunnerScripts get() = getSafePathList(POST_RUN_SCRIPTS) +/** + * postTestTasks to execute. + * default: DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS + */ +val Config.postTestTasks get() = + when (hasPath(POST_TEST_TASKS)) { + true -> getEnumList(SquitPostTestTask::class.java, POST_TEST_TASKS)!! + else -> listOf( + SquitPostTestTask.DATABASE_SCRIPTS, + SquitPostTestTask.POST_RUNNERS, + SquitPostTestTask.POST_RUNNER_SCRIPTS + ) + } + /** * List of tags associated with the test. */ @@ -174,7 +206,7 @@ fun Config.withTestDir(testDir: Path): Config = withValue( */ fun Config.validate() = this.apply { // Call getters of properties to check existence and correct declaration. - endpoint; mediaType; shouldExclude; shouldIgnore; headers; testDir + endpoint; mediaType; shouldExclude; shouldIgnore; headers; testDir; preTestTasks; postTestTasks preProcessors.forEach { checkClass(it) } preProcessorScripts.forEach { FilesUtils.validateExistence(it) } diff --git a/src/main/kotlin/de/smartsquare/squit/task/SquitPostTestTask.kt b/src/main/kotlin/de/smartsquare/squit/task/SquitPostTestTask.kt new file mode 100644 index 00000000..7d278fb7 --- /dev/null +++ b/src/main/kotlin/de/smartsquare/squit/task/SquitPostTestTask.kt @@ -0,0 +1,5 @@ +package de.smartsquare.squit.task + +enum class SquitPostTestTask { + DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS +} diff --git a/src/main/kotlin/de/smartsquare/squit/task/SquitPreTestTask.kt b/src/main/kotlin/de/smartsquare/squit/task/SquitPreTestTask.kt new file mode 100644 index 00000000..63c7502b --- /dev/null +++ b/src/main/kotlin/de/smartsquare/squit/task/SquitPreTestTask.kt @@ -0,0 +1,5 @@ +package de.smartsquare.squit.task + +enum class SquitPreTestTask { + DATABASE_SCRIPTS, PRE_RUNNERS, PRE_RUNNER_SCRIPTS +} diff --git a/src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt b/src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt index 60e99702..5b08253d 100644 --- a/src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt +++ b/src/main/kotlin/de/smartsquare/squit/task/SquitRequestTask.kt @@ -9,8 +9,10 @@ import de.smartsquare.squit.config.mediaType import de.smartsquare.squit.config.method import de.smartsquare.squit.config.postRunnerScripts import de.smartsquare.squit.config.postRunners +import de.smartsquare.squit.config.postTestTasks import de.smartsquare.squit.config.preRunnerScripts import de.smartsquare.squit.config.preRunners +import de.smartsquare.squit.config.preTestTasks import de.smartsquare.squit.db.ConnectionCollection import de.smartsquare.squit.db.executeScript import de.smartsquare.squit.entity.SquitMetaInfo @@ -58,6 +60,7 @@ import java.util.concurrent.TimeUnit * Task for running requests against the given api. Also capable of running existing sql scripts before and after the * request. */ +@Suppress("TooManyFunctions") open class SquitRequestTask : DefaultTask() { /** @@ -246,20 +249,16 @@ open class SquitRequestTask : DefaultTask() { } private fun doPreScriptExecutions(config: Config, testDirectoryPath: Path) { - config - .preRunners - .map { - preRunnersCache.getOrPut(it) { Class.forName(it).getConstructor().newInstance() as SquitPreRunner } + config.preTestTasks.forEach { task -> + when (task!!) { + SquitPreTestTask.PRE_RUNNERS -> executePreRunners(config) + SquitPreTestTask.PRE_RUNNER_SCRIPTS -> executePreRunnerScripts(config) + SquitPreTestTask.DATABASE_SCRIPTS -> executePreDatabaseScripts(config, testDirectoryPath) } - .forEach { it.run(config) } - - config.preRunnerScripts.forEach { - GroovyShell(javaClass.classLoader) - .parse(it.toFile()) - .apply { binding = Binding(mapOf("config" to config)) } - .run() } + } + private fun executePreDatabaseScripts(config: Config, testDirectoryPath: Path) { config.databaseConfigurations.forEach { executeScriptIfExisting( testDirectoryPath.resolve("${it.name}_pre.sql"), @@ -270,7 +269,35 @@ open class SquitRequestTask : DefaultTask() { } } + private fun executePreRunnerScripts(config: Config) { + config.preRunnerScripts.forEach { + GroovyShell(javaClass.classLoader) + .parse(it.toFile()) + .apply { binding = Binding(mapOf("config" to config)) } + .run() + } + } + + private fun executePreRunners(config: Config) { + config + .preRunners + .map { + preRunnersCache.getOrPut(it) { Class.forName(it).getConstructor().newInstance() as SquitPreRunner } + } + .forEach { it.run(config) } + } + private fun doPostScriptExecutions(config: Config, testDirectoryPath: Path) { + config.postTestTasks.forEach { task -> + when (task!!) { + SquitPostTestTask.POST_RUNNER_SCRIPTS -> executePostRunnerScripts(config) + SquitPostTestTask.POST_RUNNERS -> executePostRunners(config) + SquitPostTestTask.DATABASE_SCRIPTS -> executePostDatabaseScripts(config, testDirectoryPath) + } + } + } + + private fun executePostDatabaseScripts(config: Config, testDirectoryPath: Path) { config.databaseConfigurations.forEach { executeScriptIfExisting( testDirectoryPath.resolve("${it.name}_post.sql"), @@ -279,14 +306,9 @@ open class SquitRequestTask : DefaultTask() { it.password ) } + } - config - .postRunners - .map { - postRunnersCache.getOrPut(it) { Class.forName(it).getConstructor().newInstance() as SquitPostRunner } - } - .forEach { it.run(config) } - + private fun executePostRunnerScripts(config: Config) { config.postRunnerScripts.forEach { GroovyShell(javaClass.classLoader) .parse(it.toFile()) @@ -295,6 +317,15 @@ open class SquitRequestTask : DefaultTask() { } } + private fun executePostRunners(config: Config) { + config + .postRunners + .map { + postRunnersCache.getOrPut(it) { Class.forName(it).getConstructor().newInstance() as SquitPostRunner } + } + .forEach { it.run(config) } + } + private fun constructApiCall(requestPath: Path?, config: Config): Call { val requestBody = requestPath?.toFile()?.asRequestBody(config.mediaType) diff --git a/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt b/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt index 6c589428..b41446d3 100644 --- a/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt +++ b/src/test/kotlin/de/smartsquare/squit/config/ConfigExtensionsTest.kt @@ -1,5 +1,6 @@ package de.smartsquare.squit.config +import com.typesafe.config.ConfigException.BadValue import com.typesafe.config.ConfigFactory import de.smartsquare.squit.TestUtils import okhttp3.HttpUrl.Companion.toHttpUrlOrNull @@ -491,4 +492,35 @@ class ConfigExtensionsTest { call shouldNotThrow AnyException } + + @Test + fun `config object with an invalid preTestTask`() { + val config = ConfigFactory.parseMap( + mapOf( + "endpoint" to "https://example.com", + "preTestTasks" to listOf("[NotExistingTask]"), + ) + ) + + val call = { config.validate() } + @Suppress("MaxLineLength") + call shouldThrow BadValue::class withMessage "hardcoded value: Invalid value at 'preTestTasks': " + + "The enum class SquitPreTestTask has no constant of the name '[NotExistingTask]' " + + "(should be one of [DATABASE_SCRIPTS, PRE_RUNNERS, PRE_RUNNER_SCRIPTS].)" + } + + @Test + fun `config object with an invalid postTestTask`() { + val config = ConfigFactory.parseMap( + mapOf( + "endpoint" to "https://example.com", + "postTestTasks" to listOf("[NotExistingTask]"), + ) + ) + + val call = { config.validate() } + call shouldThrow BadValue::class withMessage "hardcoded value: Invalid value at 'postTestTasks': " + + "The enum class SquitPostTestTask has no constant of the name '[NotExistingTask]' " + + "(should be one of [DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS].)" + } } diff --git a/src/test/kotlin/de/smartsquare/squit/task/SquitRequestTaskConfigurableTasksTest.kt b/src/test/kotlin/de/smartsquare/squit/task/SquitRequestTaskConfigurableTasksTest.kt new file mode 100644 index 00000000..6bb158c5 --- /dev/null +++ b/src/test/kotlin/de/smartsquare/squit/task/SquitRequestTaskConfigurableTasksTest.kt @@ -0,0 +1,127 @@ +package de.smartsquare.squit.task + +import de.smartsquare.squit.TestUtils +import de.smartsquare.squit.gradleRunner +import okhttp3.mockwebserver.MockResponse +import okhttp3.mockwebserver.MockWebServer +import org.amshove.kluent.shouldBe +import org.amshove.kluent.shouldBeAfter +import org.amshove.kluent.shouldBeBefore +import org.amshove.kluent.shouldBeEqualTo +import org.amshove.kluent.shouldBeFalse +import org.amshove.kluent.shouldExist +import org.amshove.kluent.shouldNotExist +import org.gradle.testkit.runner.TaskOutcome +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import java.sql.DriverManager +import java.time.Instant + +class SquitRequestTaskConfigurableTasksTest { + private val project = TestUtils.getResourcePath("test-project-task-config") + + private val jdbc = "jdbc:h2:$project/testDb;IFEXISTS=TRUE" + private val username = "test" + private val password = "test" + private val preRunFile = project.resolve("build/pre_run.txt").toFile() + private val postRunFile = project.resolve("build/post_run.txt").toFile() + + private lateinit var server: MockWebServer + + @BeforeEach + fun setUp() { + server = MockWebServer() + } + + @AfterEach + fun tearDown() { + server.shutdown() + + TestUtils.deleteDatabaseFiles(project) + preRunFile.delete() + postRunFile.delete() + } + + @Test + fun `should execute pre and post tasks in default order`() { + server.enqueue(MockResponse().setBody("")) + + val arguments = listOf( + "squitRunRequests", "-Psquit.endpointPlaceholder=${server.url("/")}", + "-Psquit.rootDir=$project", "-Ptags=default" + ) + + val result = gradleRunner(project, arguments).build() + + result.task(":squitRunRequests")?.outcome shouldBe TaskOutcome.SUCCESS + val preScriptExecution = Instant.ofEpochMilli(preRunFile.readText().toLong()) + val postScriptExecution = Instant.ofEpochMilli(postRunFile.readText().toLong()) + DriverManager.getConnection(jdbc, username, password).use { connection -> + val resultSet = connection.createStatement().executeQuery("SELECT * FROM TIMESTAMPS") + resultSet.next() + val preDbScriptExecution = resultSet.getTimestamp(2).toInstant() + resultSet.getString(3) shouldBeEqualTo "TEST_PRE.SQL" + resultSet.next() + resultSet.getString(3) shouldBeEqualTo "TEST_POST.SQL" + val postDbScriptExecution = resultSet.getTimestamp(2).toInstant() + preDbScriptExecution shouldBeBefore postDbScriptExecution + preScriptExecution shouldBeBefore postScriptExecution + preScriptExecution shouldBeBefore preDbScriptExecution + postScriptExecution shouldBeAfter postDbScriptExecution + } + } + + @Test + fun `should execute scripts in configured order`() { + server.enqueue(MockResponse().setBody("")) + + val arguments = listOf( + "squitRunRequests", "-Psquit.endpointPlaceholder=${server.url("/")}", + "-Psquit.rootDir=$project", "-Ptags=configured_order" + ) + + val result = gradleRunner(project, arguments).build() + + result.task(":squitRunRequests")?.outcome shouldBe TaskOutcome.SUCCESS + + val preScriptExecution = Instant.ofEpochMilli(preRunFile.readText().toLong()) + val postScriptExecution = Instant.ofEpochMilli(postRunFile.readText().toLong()) + DriverManager.getConnection(jdbc, username, password).use { connection -> + val resultSet = connection.createStatement().executeQuery("SELECT * FROM TIMESTAMPS") + resultSet.next() + val preDbScriptExecution = resultSet.getTimestamp(2).toInstant() + resultSet.getString(3) shouldBeEqualTo "TEST_PRE.SQL" + resultSet.next() + resultSet.getString(3) shouldBeEqualTo "TEST_POST.SQL" + val postDbScriptExecution = resultSet.getTimestamp(2).toInstant() + preDbScriptExecution shouldBeBefore postDbScriptExecution + preScriptExecution shouldBeBefore postScriptExecution + preScriptExecution shouldBeAfter preDbScriptExecution + postScriptExecution shouldBeBefore postDbScriptExecution + } + } + + @Test + fun `should only execute pre db script and post script`() { + server.enqueue(MockResponse().setBody("")) + + val arguments = listOf( + "squitRunRequests", "-Psquit.endpointPlaceholder=${server.url("/")}", + "-Psquit.rootDir=$project", "-Ptags=only_pre_db_script" + ) + + val result = gradleRunner(project, arguments).build() + + result.task(":squitRunRequests")?.outcome shouldBe TaskOutcome.SUCCESS + + DriverManager.getConnection(jdbc, username, password).use { connection -> + val resultSet = connection.createStatement().executeQuery("SELECT * FROM TIMESTAMPS") + resultSet.next() + resultSet.getString(3) shouldBeEqualTo "TEST_PRE.SQL" + resultSet.next().shouldBeFalse() + } + preRunFile.shouldNotExist() + postRunFile.shouldExist() + } +} diff --git a/src/test/resources/test-project-task-config/build.gradle b/src/test/resources/test-project-task-config/build.gradle new file mode 100644 index 00000000..a54f85dd --- /dev/null +++ b/src/test/resources/test-project-task-config/build.gradle @@ -0,0 +1,8 @@ +plugins { + id 'base' + id 'de.smartsquare.squit' +} + +squit { + jdbcDrivers = ["org.h2.Driver"] +} diff --git a/src/test/resources/test-project-task-config/settings.gradle b/src/test/resources/test-project-task-config/settings.gradle new file mode 100644 index 00000000..12dc58f9 --- /dev/null +++ b/src/test/resources/test-project-task-config/settings.gradle @@ -0,0 +1 @@ +rootProject.name = "test-project-task-config" diff --git a/src/test/resources/test-project-task-config/src/squit/project/configured_order/request.xml b/src/test/resources/test-project-task-config/src/squit/project/configured_order/request.xml new file mode 100644 index 00000000..8aa90df0 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/configured_order/request.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/configured_order/response.xml b/src/test/resources/test-project-task-config/src/squit/project/configured_order/response.xml new file mode 100644 index 00000000..56c6bb24 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/configured_order/response.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/configured_order/test.conf b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test.conf new file mode 100644 index 00000000..ddc6022d --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test.conf @@ -0,0 +1,2 @@ +preTestTasks = [DATABASE_SCRIPTS, PRE_RUNNER_SCRIPTS] +postTestTasks = [POST_RUNNER_SCRIPTS, DATABASE_SCRIPTS] diff --git a/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_post.sql b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_post.sql new file mode 100644 index 00000000..fdeca71d --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_post.sql @@ -0,0 +1 @@ +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_POST.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_pre.sql b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_pre.sql new file mode 100644 index 00000000..379e5d34 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/configured_order/test_pre.sql @@ -0,0 +1,8 @@ +CREATE TABLE TIMESTAMPS +( + ID INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + CREATED_DATE TIMESTAMP, + SCRIPT VARCHAR2(255) NOT NULL +); + +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_PRE.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/default/request.xml b/src/test/resources/test-project-task-config/src/squit/project/default/request.xml new file mode 100644 index 00000000..8aa90df0 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/default/request.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/default/response.xml b/src/test/resources/test-project-task-config/src/squit/project/default/response.xml new file mode 100644 index 00000000..56c6bb24 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/default/response.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/default/test_post.sql b/src/test/resources/test-project-task-config/src/squit/project/default/test_post.sql new file mode 100644 index 00000000..fdeca71d --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/default/test_post.sql @@ -0,0 +1 @@ +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_POST.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/default/test_pre.sql b/src/test/resources/test-project-task-config/src/squit/project/default/test_pre.sql new file mode 100644 index 00000000..379e5d34 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/default/test_pre.sql @@ -0,0 +1,8 @@ +CREATE TABLE TIMESTAMPS +( + ID INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + CREATED_DATE TIMESTAMP, + SCRIPT VARCHAR2(255) NOT NULL +); + +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_PRE.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/request.xml b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/request.xml new file mode 100644 index 00000000..8aa90df0 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/request.xml @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/response.xml b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/response.xml new file mode 100644 index 00000000..56c6bb24 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/response.xml @@ -0,0 +1,3 @@ + + + diff --git a/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test.conf b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test.conf new file mode 100644 index 00000000..47fe8f3f --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test.conf @@ -0,0 +1,2 @@ +preTestTasks = [DATABASE_SCRIPTS] +postTestTasks = [POST_RUNNER_SCRIPTS] diff --git a/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_post.sql b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_post.sql new file mode 100644 index 00000000..fdeca71d --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_post.sql @@ -0,0 +1 @@ +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_POST.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_pre.sql b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_pre.sql new file mode 100644 index 00000000..379e5d34 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/only_pre_db_script/test_pre.sql @@ -0,0 +1,8 @@ +CREATE TABLE TIMESTAMPS +( + ID INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + CREATED_DATE TIMESTAMP, + SCRIPT VARCHAR2(255) NOT NULL +); + +INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_PRE.SQL'); diff --git a/src/test/resources/test-project-task-config/src/squit/project/post_run.groovy b/src/test/resources/test-project-task-config/src/squit/project/post_run.groovy new file mode 100644 index 00000000..10174a95 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/post_run.groovy @@ -0,0 +1,5 @@ +import java.time.Instant +Thread.sleep(1) +def file = new File(config.getString("rootDir") + "/build/post_run.txt") +file.text = Instant.now().toEpochMilli().toString() +Thread.sleep(1) diff --git a/src/test/resources/test-project-task-config/src/squit/project/pre_run.groovy b/src/test/resources/test-project-task-config/src/squit/project/pre_run.groovy new file mode 100644 index 00000000..6b653239 --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/pre_run.groovy @@ -0,0 +1,5 @@ +import java.time.Instant +Thread.sleep(1) +def file = new File(config.getString("rootDir") + "/build/pre_run.txt") +file.text = Instant.now().toEpochMilli().toString() +Thread.sleep(1) diff --git a/src/test/resources/test-project-task-config/src/squit/project/test.conf b/src/test/resources/test-project-task-config/src/squit/project/test.conf new file mode 100644 index 00000000..0483ccef --- /dev/null +++ b/src/test/resources/test-project-task-config/src/squit/project/test.conf @@ -0,0 +1,9 @@ +endpoint = ${endpointPlaceholder} +mediaType = "application/xml" + +preRunnerScripts = [${rootDir}"/src/squit/project/pre_run.groovy"] +postRunnerScripts = [${rootDir}"/src/squit/project/post_run.groovy"] + +databaseConfigurations = [ + {name = "test", jdbc = "jdbc:h2:"${rootDir}"/testDb", username = "test", password = "test"} +]