use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class HttpClientConfigITest method local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse.
@Test
public void local_http_client_config_doesnt_reuse_static_http_client_instance_when_local_config_specifies_reuse() {
final MutableObject<HttpClient> client1 = new MutableObject<HttpClient>();
final MutableObject<HttpClient> client2 = new MutableObject<HttpClient>();
RestAssured.config = RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance());
// When
try {
given().param("url", "/hello").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client1.setValue(requestSpec.getHttpClient());
return ctx.next(requestSpec, responseSpec);
}
}).expect().body("hello", equalTo("Hello Scalatra")).when().get("/redirect");
given().config(RestAssuredConfig.newConfig().httpClient(HttpClientConfig.httpClientConfig().reuseHttpClientInstance())).header("name", "value").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
client2.setValue(requestSpec.getHttpClient());
return ctx.next(requestSpec, responseSpec);
}
}).when().post("/reflect");
} finally {
RestAssured.reset();
}
assertThat(client1.getValue(), not(sameInstance(client2.getValue())));
}
use of io.restassured.specification.FilterableRequestSpecification 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"));
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class PathParamITest method urlEncodesUnnamedPathParametersThatContainsCurlyBracesAndEquals.
@Test
public void urlEncodesUnnamedPathParametersThatContainsCurlyBracesAndEquals() 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))).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", "{trackingName='trackingname1'}");
// Then
assertThat(RequestPathFromLogExtractor.loggedRequestPathIn(writer), equalTo("http://localhost:8080/feed?canonicalName=%7BtrackingName%3D%27trackingname1%27%7D&platform=ed4"));
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class RequestSpecificationITest method filterable_request_specification_returns_correct_port.
@Test
public void filterable_request_specification_returns_correct_port() {
try {
RestAssured.baseURI = "http://localhost:8089";
RequestSpecification spec = new RequestSpecBuilder().addHeader("authorization", "abracadabra").build();
given().spec(spec).filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
assertThat(requestSpec.getPort(), is(8089));
return new ResponseBuilder().setStatusCode(200).build();
}
}).when().get("/test");
} finally {
RestAssured.reset();
}
}
use of io.restassured.specification.FilterableRequestSpecification in project rest-assured by rest-assured.
the class AcceptHeaderITest method accept_headers_are_overwritten_from_request_spec_by_default.
@Test
public void accept_headers_are_overwritten_from_request_spec_by_default() {
RequestSpecification spec = new RequestSpecBuilder().setAccept(ContentType.JSON).build();
final MutableObject<List<String>> headers = new MutableObject<List<String>>();
RestAssured.given().accept("text/jux").spec(spec).body("{ \"message\" : \"hello world\"}").filter(new Filter() {
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
headers.setValue(requestSpec.getHeaders().getValues("Accept"));
return ctx.next(requestSpec, responseSpec);
}
}).when().post("/jsonBodyAcceptHeader").then().body(equalTo("hello world"));
assertThat(headers.getValue(), contains("application/json, application/javascript, text/javascript, text/json"));
}
Aggregations