-
Notifications
You must be signed in to change notification settings - Fork 6
/
JUnit4ExampleTest.kt
51 lines (43 loc) · 1.15 KB
/
JUnit4ExampleTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package com.marcinziolo.kotlin.wiremock
import com.github.tomakehurst.wiremock.junit.WireMockRule
import io.restassured.module.kotlin.extensions.Then
import io.restassured.module.kotlin.extensions.When
import org.hamcrest.Matchers.equalTo
import org.junit.Rule
import org.junit.Test
import java.net.ServerSocket
class JUnit4ExampleTest {
val port = findRandomPort()
val url = "http://localhost:$port"
@Rule
@JvmField
var wiremock: WireMockRule = WireMockRule(port)
@Test
fun `url matching`() {
wiremock.get {
url like "/users/.*"
} returns {
header = "Content-Type" to "application/json"
statusCode = 200
body = """
{
"id": 1,
"name": "Bob"
}
"""
}
assertBobSuccess()
}
private fun assertBobSuccess() {
When {
get("$url/users/1")
} Then {
statusCode(200)
body("id", equalTo(1))
body("name", equalTo("Bob"))
}
}
fun findRandomPort(): Int {
ServerSocket(0).use { socket -> return socket.localPort }
}
}