Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kotlin samples #401

Merged
merged 5 commits into from
Aug 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 65 additions & 1 deletion webtau-junit5-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird formatting...

</execution>
<execution>
<id>java-test-compile</id>
<phase>test-compile</phase>
<goals> <goal>testCompile</goal> </goals>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird formatting...

</execution>
</executions>
</plugin>

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
Expand All @@ -175,4 +239,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
Original file line number Diff line number Diff line change
@@ -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
}
}
}