use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class RequestFilterAcceptanceTest method filterCanBeAppliedToAdmin.
@Test
public void filterCanBeAppliedToAdmin() {
initialise(new AdminAuthenticatingFilter());
wm.stubFor(get(url).willReturn(ok()));
String adminUrl = "/__admin/mappings";
WireMockResponse good = client.get(adminUrl, withHeader("Authorization", "Token 123"));
assertThat(good.statusCode(), is(200));
WireMockResponse bad = client.get(adminUrl);
assertThat(bad.statusCode(), is(401));
// Stubs are unaffected
WireMockResponse stub = client.get(url);
assertThat(stub.statusCode(), is(200));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ResponseDefinitionTransformerAcceptanceTest method supportsSpecifiyingExtensionsByInstance.
@Test
public void supportsSpecifiyingExtensionsByInstance() {
wm = new WireMockServer(wireMockConfig().dynamicPort().extensions(new ExampleTransformer(), new MultiTransformer2()));
wm.start();
client = new WireMockTestClient(wm.port());
createStub("/to-instance-transform");
WireMockResponse response = client.get("/to-instance-transform");
assertThat(response.statusCode(), is(200));
assertThat(response.content(), is("Expect this"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ResponseDefinitionTransformerAcceptanceTest method supportsAccessingTheFilesFileSource.
@Test
public void supportsAccessingTheFilesFileSource() {
startWithExtensions("com.github.tomakehurst.wiremock.ResponseDefinitionTransformerAcceptanceTest$FileAccessTransformer");
createStub("/files-access-transform");
WireMockResponse response = client.get("/files-access-transform");
assertThat(response.content(), is("Some example test from a file"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ResponseDefinitionTransformerAcceptanceTest method supportsSpecifiyingExtensionsByClass.
@Test
public void supportsSpecifiyingExtensionsByClass() {
wm = new WireMockServer(wireMockConfig().dynamicPort().extensions(ExampleTransformer.class, MultiTransformer1.class));
wm.start();
client = new WireMockTestClient(wm.port());
createStub("/to-class-transform");
WireMockResponse response = client.get("/to-class-transform");
assertThat(response.statusCode(), is(201));
assertThat(response.content(), is("Transformed body"));
}
use of com.github.tomakehurst.wiremock.testsupport.WireMockResponse in project wiremock by wiremock.
the class ResponseDelayAcceptanceTest method responseWithByteDribbleAndFixedDelay.
@Test
public void responseWithByteDribbleAndFixedDelay() {
byte[] body = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int numberOfChunks = body.length / 2;
int fixedDelay = 1000;
int chunkedDuration = 1000;
int totalDuration = fixedDelay + chunkedDuration;
stubFor(get(urlEqualTo("/dribbleWithFixedDelay")).willReturn(aResponse().withStatus(200).withBody(body).withChunkedDribbleDelay(numberOfChunks, chunkedDuration).withFixedDelay(fixedDelay)));
long start = System.currentTimeMillis();
WireMockResponse response = testClient.get("/dribbleWithFixedDelay");
long timeTaken = System.currentTimeMillis() - start;
assertThat(response.statusCode(), is(200));
assertThat(timeTaken, greaterThanOrEqualTo((long) totalDuration));
assertThat(body, is(response.binaryContent()));
}
Aggregations