forked from karatelabs/karate
/
HelloWorldTest.java
executable file
·99 lines (92 loc) · 4.57 KB
/
HelloWorldTest.java
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package com.intuit.karate.junit4.wiremock;
import com.intuit.karate.junit4.Karate;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
import static com.github.tomakehurst.wiremock.client.WireMock.*;
import com.github.tomakehurst.wiremock.junit.WireMockClassRule;
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
import java.util.UUID;
import org.junit.ClassRule;
import org.junit.Rule;
/**
*
* @author pthomas3
*/
@RunWith(Karate.class)
public class HelloWorldTest {
@ClassRule
public static WireMockClassRule WIREMOCK_RULE = new WireMockClassRule(wireMockConfig().dynamicPort());
@Rule
public WireMockClassRule instanceRule = WIREMOCK_RULE;
public static final byte[] testBytes = new byte[]{15, 98, -45, 0, 0, 7, -124, 75, 12, 26, 0, 9};
@BeforeClass
public static void before() {
System.setProperty("wiremock.port", WIREMOCK_RULE.port() + "");
String uuid = UUID.randomUUID().toString();
stubFor(post(urlEqualTo("/v1/cats"))
.withHeader("Content-Type", equalTo("application/json"))
.willReturn(aResponse()
.withStatus(201)
.withHeader("Content-Type", "application/json")
.withBody("{ \"id\": \"" + uuid + "\", name: \"Billie\" }")));
stubFor(get(urlEqualTo("/v1/cats/" + uuid))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"id\": \"" + uuid + "\", name: \"Billie\" }")));
stubFor(post(urlEqualTo("/v1/dogs"))
.withHeader("Content-Type", equalTo("application/json"))
.willReturn(aResponse()
.withStatus(201)
.withHeader("Content-Type", "application/json")
.withBody("{ \"id\": \"" + uuid + "\", name: \"Dummy\" }")));
stubFor(get(urlEqualTo("/v1/dogs/" + uuid))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"id\": \"" + uuid + "\", name: \"Dummy\" }")));
stubFor(get(urlEqualTo("/v1/binary/"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/octet-stream")
.withBody(testBytes)));
stubFor(patch(urlEqualTo("/v1/patch"))
.willReturn((aResponse().withStatus(422)
.withHeader("Content-Type", "application/json")
.withBody("{ \"success\": true }"))));
stubFor(delete(urlEqualTo("/v1/delete"))
.willReturn((aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"success\": true }"))));
stubFor(delete(urlEqualTo("/v1/deleteEmptyResponse"))
.willReturn(null));
stubFor(get(urlEqualTo("/v1/commas?foo=bar%2Cbaz"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"success\": true }")));
stubFor(get(urlEqualTo("/v1/multiparams?foo=bar&foo=baz"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"success\": true }")));
stubFor(get(urlEqualTo("/v1/german"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/xml")
.withBody("<name>Müller</name>")));
stubFor(get(urlMatching("/v1/encoding/.*"))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("{ \"success\": true }")));
stubFor(get(urlEqualTo("/v1/linefeed"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "application/json")
.withBody("\n{ \"success\": true }")));
stubFor(get(urlEqualTo("/v1/spaces"))
.willReturn(aResponse().withStatus(200)
.withHeader("Content-Type", "text/plain")
.withBody("\n \n")));
}
}