Skip to content
Permalink
Browse files

Kotlin samples (#401)

  • Loading branch information...
tsiq-karold committed Aug 13, 2019
1 parent ef06354 commit c6bbd8cf65aad06905959d8f8fc3cf9b4e279c26
@@ -26,6 +26,10 @@

<artifactId>webtau-junit5-examples</artifactId>

<properties>
<kotlin.version>1.3.41</kotlin.version>
</properties>

<dependencies>
<dependency>
<groupId>com.twosigma.webtau</groupId>
@@ -76,6 +80,11 @@
<artifactId>webtau-junit5-groovy</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<build>
@@ -151,6 +160,61 @@
</executions>
</plugin>

<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals> <goal>compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals> <goal>test-compile</goal> </goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<executions>
<!-- Replacing default-compile as it is treated specially by maven -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- Replacing default-testCompile as it is treated specially by maven -->
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
<execution>
<id>java-compile</id>
<phase>compile</phase>
<goals> <goal>compile</goal> </goals>
</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
@@ -175,4 +239,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
@@ -0,0 +1,63 @@
package com.example.tests.junit5

import com.twosigma.webtau.WebTauDsl.*
import com.twosigma.webtau.http.validation.HttpResponseValidatorWithReturn
import com.twosigma.webtau.junit5.WebTau

import org.junit.jupiter.api.*

@WebTau
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
@DisplayName("customer")
class CustomerCrudSeparatedKotlinTest {
@Test
@Order(1)
fun `read customer record`() {
http.get("/customers/$id") { _, body ->
body.should(equal(customerPayload))
}
}

@Test
@Order(2)
fun `update customer record`() {
http.put("/customers/$id", changedCustomerPayload) { _, body ->
body.should(equal(changedCustomerPayload))
}

http.get("/customers/$id") { _, body ->
body.should(equal(changedCustomerPayload))
}
}

@Test
@Order(3)
fun `delete customer`() {
http.delete("/customers/$id") { header, _ ->
header.statusCode().should(equal(204))
}

http.get("/customers/$id") { header, _ ->
header.statusCode().should(equal(404))
}
}

companion object {
private val customerPayload = mapOf(
"firstName" to "FN",
"lastName" to "LN"
)
private val changedCustomerPayload = mapOf(
"lastName" to "NLN"
)
private val id by lazy {
val id: Int = http.post("/customers", customerPayload, HttpResponseValidatorWithReturn { _, body ->
body.get("id")
})

actual(id).shouldNot(equal(0))

id
}
}
}

0 comments on commit c6bbd8c

Please sign in to comment.
You can’t perform that action at this time.