-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add option to configure pre- and post-testtasks per test
- Loading branch information
Thomas Sievert
committed
Jun 21, 2024
1 parent
471c6ae
commit 28d3388
Showing
25 changed files
with
337 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/de/smartsquare/squit/task/SquitPostTestTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.smartsquare.squit.task | ||
|
||
enum class SquitPostTestTask { | ||
DATABASE_SCRIPTS, POST_RUNNERS, POST_RUNNER_SCRIPTS | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/kotlin/de/smartsquare/squit/task/SquitPreTestTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package de.smartsquare.squit.task | ||
|
||
enum class SquitPreTestTask { | ||
DATABASE_SCRIPTS, PRE_RUNNERS, PRE_RUNNER_SCRIPTS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
src/test/kotlin/de/smartsquare/squit/task/SquitRequestTaskConfigurableTasksTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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("<cool/>")) | ||
|
||
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("<cool/>")) | ||
|
||
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("<cool/>")) | ||
|
||
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
plugins { | ||
id 'base' | ||
id 'de.smartsquare.squit' | ||
} | ||
|
||
squit { | ||
jdbcDrivers = ["org.h2.Driver"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
rootProject.name = "test-project-task-config" |
6 changes: 6 additions & 0 deletions
6
src/test/resources/test-project-task-config/src/squit/project/configured_order/request.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<animals> | ||
<animal name="dog"/> | ||
<animal name="cat"/> | ||
</animals> |
3 changes: 3 additions & 0 deletions
3
src/test/resources/test-project-task-config/src/squit/project/configured_order/response.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?xml version="1.0" encoding="utf-8" ?> | ||
|
||
<cool/> |
2 changes: 2 additions & 0 deletions
2
src/test/resources/test-project-task-config/src/squit/project/configured_order/test.conf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
preTestTasks = [DATABASE_SCRIPTS, PRE_RUNNER_SCRIPTS] | ||
postTestTasks = [POST_RUNNER_SCRIPTS, DATABASE_SCRIPTS] |
1 change: 1 addition & 0 deletions
1
src/test/resources/test-project-task-config/src/squit/project/configured_order/test_post.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
INSERT INTO TIMESTAMPS (CREATED_DATE, SCRIPT) VALUES (CURRENT_TIMESTAMP, 'TEST_POST.SQL'); |
Oops, something went wrong.