use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class CookieMatchingAcceptanceTest method doesNotMatchWhenRequiredAbsentCookieIsPresent.
@Test
public void doesNotMatchWhenRequiredAbsentCookieIsPresent() {
stubFor(get(urlEqualTo("/absent/cookie")).withCookie("my_cookie", absent()).willReturn(aResponse().withStatus(200)));
WireMockResponse response = testClient.get("/absent/cookie", withHeader(COOKIE, "my_cookie=xxx-mycookievalue-xxx; my_other_cookie=exact-other-value; irrelevant_cookie=whatever"));
assertThat(response.statusCode(), is(404));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AdminApiTest method resetScenariosViaPOST.
@Test
public void resetScenariosViaPOST() {
dsl.stubFor(get(urlEqualTo("/stateful")).inScenario("changing-states").whenScenarioStateIs(STARTED).willSetStateTo("final").willReturn(aResponse().withBody("Initial")));
dsl.stubFor(get(urlEqualTo("/stateful")).inScenario("changing-states").whenScenarioStateIs("final").willReturn(aResponse().withBody("Final")));
assertThat(testClient.get("/stateful").content(), is("Initial"));
assertThat(testClient.get("/stateful").content(), is("Final"));
WireMockResponse response = testClient.post("/__admin/scenarios/reset", new StringEntity("", TEXT_PLAIN));
assertThat(response.content(), is("{}"));
assertThat(response.firstHeader("Content-Type"), is("application/json"));
assertThat(testClient.get("/stateful").content(), is("Initial"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class AlternativeServletContainerTest method supportsAlternativeHttpServerForFaultInjection.
@Test
public void supportsAlternativeHttpServerForFaultInjection() {
stubFor(get(urlEqualTo("/alt-server")).willReturn(aResponse().withFault(Fault.EMPTY_RESPONSE)));
WireMockResponse response = client.get("/alt-server");
assertThat(response.statusCode(), is(418));
assertThat(response.content(), is("No fault injector is configured!"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class Examples method toDoListScenario.
@Test
public void toDoListScenario() {
stubFor(get(urlEqualTo("/todo/items")).inScenario("To do list").whenScenarioStateIs(STARTED).willReturn(aResponse().withBody("<items>" + " <item>Buy milk</item>" + "</items>")));
stubFor(post(urlEqualTo("/todo/items")).inScenario("To do list").whenScenarioStateIs(STARTED).withRequestBody(containing("Cancel newspaper subscription")).willReturn(aResponse().withStatus(201)).willSetStateTo("Cancel newspaper item added"));
stubFor(get(urlEqualTo("/todo/items")).inScenario("To do list").whenScenarioStateIs("Cancel newspaper item added").willReturn(aResponse().withBody("<items>" + " <item>Buy milk</item>" + " <item>Cancel newspaper subscription</item>" + "</items>")));
WireMockResponse response = testClient.get("/todo/items");
assertThat(response.content(), containsString("Buy milk"));
assertThat(response.content(), not(containsString("Cancel newspaper subscription")));
response = testClient.postWithBody("/todo/items", "Cancel newspaper subscription", "text/plain", "UTF-8");
assertThat(response.statusCode(), is(201));
response = testClient.get("/todo/items");
assertThat(response.content(), containsString("Buy milk"));
assertThat(response.content(), containsString("Cancel newspaper subscription"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class SavingMappingsAcceptanceTest method doesNotDuplicateMappingsAlreadyPersistedToFileSystem.
@Test
public void doesNotDuplicateMappingsAlreadyPersistedToFileSystem() {
// Check the mapping we're about to add isn't already there
WireMockResponse response = testClient.get("/some/url");
assertThat(response.statusCode(), is(404));
// Add a mapping and save it
stubFor(get(urlEqualTo("/some/url")).willReturn(aResponse().withBody("Response to /some/url")));
saveAllMappings();
// Save a second time
saveAllMappings();
// Check only one file has been written
assertThat(MAPPINGS_DIRECTORY.listFiles().length, is(1));
}
Aggregations