use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class NotMatchedPageAcceptanceTest method returns404AndDiffReportWhenPlusSymbolInQuery.
@Test
public void returns404AndDiffReportWhenPlusSymbolInQuery() {
configure();
WireMockResponse response = testClient.get("/some/api/records?sort=updated+asc&filter_updated_gt=2019-01-02");
System.err.println(response.content());
assertThat(response.statusCode(), is(404));
assertThat(response.content(), containsString("No response could be served"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class PortNumberTest method canRunOnAnotherPortThan8080.
@Test
public void canRunOnAnotherPortThan8080() {
int port = Network.findFreePort();
WireMockServer wireMockServer = createServer(wireMockConfig().port(port));
wireMockServer.start();
WireMockTestClient wireMockClient = new WireMockTestClient(port);
wireMockClient.addResponse(MappingJsonSamples.BASIC_MAPPING_REQUEST_WITH_RESPONSE_HEADER);
WireMockResponse response = wireMockClient.get("/a/registered/resource");
assertThat(response.statusCode(), is(401));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class PostServeActionExtensionTest method canBeSpecifiedAsAJsonObject.
@Test
public void canBeSpecifiedAsAJsonObject() {
initWithOptions(options().dynamicPort().notifier(new ConsoleNotifier(true)).extensions(new NamedCounterAction()));
WireMockResponse response = client.postJson("/__admin/mappings", "{\n" + " \"request\" : {\n" + " \"urlPath\" : \"/count-me\",\n" + " \"method\" : \"GET\"\n" + " },\n" + " \"response\" : {\n" + " \"status\" : 200\n" + " },\n" + " \"postServeActions\": {\n" + " \"count-request\": {\n" + " \"counterName\": \"things\"\n" + " } \n" + " }\n" + "}");
assertThat(response.content(), response.statusCode(), is(201));
client.get("/count-me");
client.get("/count-me");
await().atMost(5, SECONDS).until(getContent("/__admin/named-counter/things"), is("2"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ProxyAcceptanceTest method addsSpecifiedHeadersToResponse.
@Test
public void addsSpecifiedHeadersToResponse() {
initWithDefaultConfig();
target.register(get(urlEqualTo("/extra/headers")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/plain").withBody("Proxied content")));
proxy.register(any(urlEqualTo("/extra/headers")).willReturn(aResponse().withHeader("X-Additional-Header", "Yep").proxiedFrom(targetServiceBaseUrl)));
WireMockResponse response = testClient.get("/extra/headers");
assertThat(response.firstHeader("Content-Type"), is("text/plain"));
assertThat(response.firstHeader("X-Additional-Header"), is("Yep"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ProxyAcceptanceTest method removesPrefixFromProxyRequestWhenMatching.
@Test
public void removesPrefixFromProxyRequestWhenMatching() {
initWithDefaultConfig();
proxy.register(get("/other/service/doc/123").willReturn(aResponse().proxiedFrom(targetServiceBaseUrl + "/approot").withProxyUrlPrefixToRemove("/other/service")));
target.register(get("/approot/doc/123").willReturn(ok()));
WireMockResponse response = testClient.get("/other/service/doc/123");
assertThat(response.statusCode(), is(200));
}
Aggregations