-
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 Docker-based integration tests and run them via Gradle.
- Loading branch information
Showing
7 changed files
with
126 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
* | ||
!checklister-web/build/libs/app.jar | ||
!subprojects/web/build/libs/app.jar |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
plugins { | ||
`java-library` | ||
kotlin("jvm") version "1.3.21" | ||
// https://github.com/avast/gradle-docker-compose-plugin | ||
id("com.avast.gradle.docker-compose") version "0.9.2" | ||
} | ||
|
||
repositories { | ||
mavenCentral() | ||
|
||
// jitpack required by Fuel | ||
maven(url = "https://jitpack.io") { | ||
name = "jitpack" | ||
} | ||
} | ||
|
||
val bootJar = tasks.getByPath(":web:bootJar") | ||
|
||
val test by tasks.getting(Test::class) { | ||
useJUnitPlatform { } | ||
} | ||
|
||
val composeUp = tasks.getByName("composeUp") | ||
composeUp.dependsOn(bootJar) | ||
dockerCompose.isRequiredBy(test) | ||
|
||
dependencies { | ||
// Kotlin | ||
implementation(kotlin("stdlib-jdk8")) | ||
|
||
// KotlinTest: https://github.com/kotlintest/kotlintest | ||
testImplementation("io.kotlintest:kotlintest-runner-junit5:3.3.2") | ||
|
||
// Fuel HTTP library: https://github.com/kittinunf/fuel | ||
testImplementation("com.github.kittinunf.fuel:fuel:2.0.1") | ||
|
||
// Fuel Jackson (de)serializer: https://github.com/kittinunf/fuel/blob/master/fuel-jackson/README.md | ||
testImplementation("com.github.kittinunf.fuel:fuel-jackson:2.0.1") | ||
|
||
// Jackson support for Java time classes: https://github.com/FasterXML/jackson-modules-java8 | ||
testImplementation("com.fasterxml.jackson.module:jackson-module-parameter-names:2.9.0") | ||
testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.9.0") | ||
testImplementation("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.9.0") | ||
|
||
implementation(project(":dto")) | ||
} |
72 changes: 72 additions & 0 deletions
72
subprojects/integrationTest/src/test/kotlin/cloud/cosmin/checklister/it/TimestampSpec.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,72 @@ | ||
package cloud.cosmin.checklister.it | ||
|
||
import cloud.cosmin.checklister.lib.dto.ItemGetDto | ||
import cloud.cosmin.checklister.lib.dto.ListGetDto | ||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module | ||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule | ||
import com.fasterxml.jackson.module.kotlin.registerKotlinModule | ||
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule | ||
import com.github.kittinunf.fuel.Fuel | ||
import com.github.kittinunf.fuel.jackson.responseObject | ||
import io.kotlintest.matchers.boolean.shouldBeTrue | ||
import io.kotlintest.matchers.string.shouldMatch | ||
import io.kotlintest.shouldBe | ||
import io.kotlintest.specs.WordSpec | ||
|
||
class TimestampSpec : WordSpec({ | ||
val baseUrl = "http://localhost:8180/api/v1" | ||
val contentType = "Content-Type" to "application/json" | ||
|
||
val mapper = ObjectMapper() | ||
.registerKotlinModule() | ||
.registerModule(ParameterNamesModule()) | ||
.registerModule(Jdk8Module()) | ||
.registerModule(JavaTimeModule()) | ||
|
||
val timestampRegex = Regex("[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{6}Z") | ||
|
||
"Checklister" When { | ||
"creating an item" should { | ||
"return the lastModified field" { | ||
val (_, _, listResult) = Fuel.post("$baseUrl/list") | ||
.header(contentType) | ||
.body("{\"title\":\"test list\"}") | ||
.responseObject<ListGetDto>(mapper) | ||
|
||
val list = listResult.get() | ||
list.title.shouldBe("test list") | ||
|
||
val (_, _, createItemResult) = Fuel.post("$baseUrl/item") | ||
.header(contentType) | ||
.body(""" | ||
{ | ||
"list": "${list.id}", | ||
"content": "content", | ||
"contentType": "contentType" | ||
} | ||
""".trimIndent()) | ||
.responseObject<ItemGetDto>(mapper) | ||
|
||
val item = createItemResult.get() | ||
item.createdAt.toString().shouldMatch(timestampRegex) | ||
item.lastModified.toString().shouldMatch(timestampRegex) | ||
|
||
val (_, _, updateItemResult) = Fuel.put("$baseUrl/item/${item.id}") | ||
.header(contentType) | ||
.body(""" | ||
{ | ||
"list": "${list.id}", | ||
"content": "content1", | ||
"contentType": "contentType1" | ||
} | ||
""".trimIndent()) | ||
.responseObject<ItemGetDto>(mapper) | ||
|
||
val updatedItem = updateItemResult.get() | ||
updatedItem.createdAt.shouldBe(item.createdAt) | ||
updatedItem.lastModified.isAfter(item.lastModified).shouldBeTrue() | ||
} | ||
} | ||
} | ||
}) |
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