use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method doesnt_log_request_or_response_when_test_fails_when_using_non_static_request_spec_declared_before_enable_logging_since_config_is_immutable_and_spec_config_has_precedence_over_global_config.
@Test
public void doesnt_log_request_or_response_when_test_fails_when_using_non_static_request_spec_declared_before_enable_logging_since_config_is_immutable_and_spec_config_has_precedence_over_global_config() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RequestSpecification specification = new RequestSpecBuilder().setConfig(RestAssured.config().logConfig(RestAssured.config().getLogConfig().defaultStream(captor).and().enablePrettyPrinting(true))).addHeader("Api-Key", "1234").build();
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
try {
RestAssured.given().spec(specification).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("firstName", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), isEmptyString());
}
}
use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class LogIfValidationFailsITest method logging_of_both_request_and_response_validation_works_when_test_fails_when_using_non_static_request_spec_declared_after_enable_logging.
@Test
public void logging_of_both_request_and_response_validation_works_when_test_fails_when_using_non_static_request_spec_declared_after_enable_logging() {
final StringWriter writer = new StringWriter();
final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true);
RestAssured.enableLoggingOfRequestAndResponseIfValidationFails(LogDetail.HEADERS);
RequestSpecification specification = new RequestSpecBuilder().setConfig(RestAssured.config().logConfig(RestAssured.config().getLogConfig().defaultStream(captor).and().enablePrettyPrinting(true))).addHeader("Api-Key", "1234").build();
try {
RestAssured.given().spec(specification).param("firstName", "John").param("lastName", "Doe").header("Content-type", "application/json").when().get("/greet").then().body("firstName", equalTo("Hello, Johan2!"));
fail("Should throw AssertionError");
} catch (AssertionError e) {
assertThat(writer.toString(), equalTo("Headers:\t\tApi-Key=1234\n\t\t\t\tAccept=*/*\n\t\t\t\tContent-Type=application/json; charset=" + RestAssured.config().getEncoderConfig().defaultCharsetForContentType(ContentType.JSON) + "\n\nContent-Type: application/json;charset=utf-8\nContent-Length: 33\nServer: Jetty(9.3.2.v20150730)\n"));
}
}
use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class ProxyITest method using_proxy_with_specification.
@Test
public void using_proxy_with_specification() {
RequestSpecification specification = new RequestSpecBuilder().setProxy("localhost").build();
given().specification(specification).param("firstName", "John").param("lastName", "Doe").when().get("/greetJSON").then().header("Via", not(isEmptyOrNullString()));
}
use of io.restassured.builder.RequestSpecBuilder in project rest-assured by rest-assured.
the class RequestSpecMergingITest method setupRA.
@BeforeClass
public static void setupRA() {
RestAssured.baseURI = "http://example.com";
RestAssured.port = 80;
RestAssured.requestSpecification = new RequestSpecBuilder().addHeader("authorization", "abracadabra").build();
}
use of io.restassured.builder.RequestSpecBuilder 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();
}
}
Aggregations