use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class LoggingITest method logsFullyQualifiedUrlsAreLoggedCorrectly.
@Test
public void logsFullyQualifiedUrlsAreLoggedCorrectly() throws Exception {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(config().logConfig(new LogConfig(captor, true))).log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("http://www.beijingchina.net.cn/transportation/train/train-to-shanghai.html");
assertThat(writer.toString(), startsWith("Request method:\tGET\nRequest URI:\thttp://www.beijingchina.net.cn/transportation/train/train-to-shanghai.html"));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class OAuthITest method oauth2_works_with_preemptive_header_signing.
@Test
public void oauth2_works_with_preemptive_header_signing() {
final String accessToken = "accessToken";
given().auth().preemptive().oauth2(accessToken).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
assertThat(requestSpec.getHeaders().getValue("Authorization"), equalTo("Bearer " + accessToken));
return new ResponseBuilder().setBody("ok").setStatusCode(200).build();
}
}).when().get("/somewhere").then().statusCode(200);
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class HttpClientConfigITest method httpClientIsConfigurableFromANonStaticHttpClientConfig.
@Test
public void httpClientIsConfigurableFromANonStaticHttpClientConfig() {
// Given
final MutableObject<HttpClient> client = new MutableObject<>();
// When
given().config(RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().httpClientFactory(SystemDefaultHttpClient::new))).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client.setValue(requestSpec.getHttpClient());
return new ResponseBuilder().setStatusCode(200).setContentType("application/json").setBody("{ \"message\" : \"hello\"}").build();
}
}).expect().body("message", equalTo("hello")).when().get("/something");
// Then
assertThat(client.getValue(), instanceOf(SystemDefaultHttpClient.class));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class PathParamITest method namedPathParametersWorksWhenThereAreMultipleTemplatesBetweenEachSlash.
@Test
public void namedPathParametersWorksWhenThereAreMultipleTemplatesBetweenEachSlash() throws Exception {
String param1Value = "Hello";
String param2Value = "Hello2";
given().filter((requestSpec, responseSpec, ctx) -> new ResponseBuilder().setStatusCode(200).setStatusLine("HTTP/1.1 200 OK").setBody(requestSpec.getURI()).build()).pathParam("param1Value", param1Value).pathParam("param2Value", param2Value).when().get("param1={param1Value}¶m2={param2Value}").then().body(equalTo("http://localhost:8080/param1%3DHello%26param2%3DHello2"));
}
use of io.restassured.builder.ResponseBuilder in project rest-assured by rest-assured.
the class PathParamITest method urlEncodesNamedPathParametersThatContainsCurlyBracesAndEquals.
@Test
public void urlEncodesNamedPathParametersThatContainsCurlyBracesAndEquals() throws Exception {
// When
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
given().config(RestAssuredConfig.config().logConfig(new LogConfig(captor, true))).pathParam("trackingName", "{trackingName='trackingname1'}").pathParam("platform", "platform").log().all().filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
return new ResponseBuilder().setStatusCode(200).setBody("changed").build();
}
}).get("/feed?canonicalName={trackingName}&{platform}=ed4");
// Then
assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/feed?canonicalName=%7BtrackingName%3D%27trackingname1%27%7D&platform=ed4"));
}
Aggregations